You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `Parsimmon.Binary` constructors parse binary content using Node.js Buffers. These constructors can be combined with the normal parser combinators such as `Parsimmon.seq`, `Parsimmon.seqObj`, and still have all the same methods as text-based parsers (e.g. `.map`, `.node`, etc.).
430
+
431
+
## Parsimmon.byte(int)
432
+
433
+
Returns a parser that yields a byte (as a number) that matches the given input; similar to `Parsimmon.digit` and `Parsimmon.letter`.
434
+
435
+
```javascript
436
+
var parser =Parsimmon.Binary.byte(0x3f);
437
+
parser.parse(Buffer.from([0x3f]));
438
+
// => { status: true, value: 63 }
439
+
```
440
+
441
+
## Parsimmon.bitSeq(alignments)
442
+
443
+
Parse a series of bits that do not have to be byte-aligned and consume them from a Buffer. The maximum number is 48 since more than 48 bits won't fit safely into a JavaScript number without losing precision. Also, the total of all bits in the sequence must be a multiple of 8 since parsing is still done at the byte level.
444
+
445
+
```javascript
446
+
var parser =Parsimmon.Binary.bitSeq([3, 5, 5, 3]);
447
+
parser.parse(Buffer.from([0x04, 0xff]));
448
+
//=> { status: true, value: [0, 4, 31, 7] }
449
+
```
450
+
451
+
## Parsimmon.bitSeqObj(namedAlignments)
452
+
453
+
Works like `Parsimmon.bitSeq` except each item in the array is either a number of bits or pair (array with length = 2) of name and bits. The bits are parsed in order and put into an object based on the name supplied. If there's no name for the bits, it will be parsed but discarded from the returned value.
0 commit comments