type Map = (result: Input, index: number, source: string) => Output; /** The result of a parsing action */ export type ParserState = { /** The intial source value being parsed */ source: string; /** Offset (in chars - not glyphs) where the last result was found */ index: number; /** The result of the last succedeed parsing action */ result: Result; /** Wether the parser produced an error */ isError: false; /** The error produced by the parser */ error: null; }; /** The error reporting state of a parsing action */ export type ParserError = { /** The intial source value being parsed */ source: string; /** Offset (in chars - not glyphs) where the last result was found */ index: number; /** The result of the last succedeed parsing action */ result: Result; /** Wether the parser produced an error */ isError: true; /** The error produced by the parser */ error: Error; }; export type ParserOutput = ParserState | ParserError; export type ParserStateHandler = (state: ParserState) => ParserOutput; export type ParserErrorHandler = (state: ParserError) => ParserError; export type ParserHandler = (state: ParserOutput) => ParserOutput; export type SourceParser = (source: string) => ParserOutput; export type Parser = ParserHandler & SourceParser & { /** Wether the parse operates at binary level */ readonly isBinary: false; /** * Map the result of the parser into another result * @param callback a callback that produces a new result from the precedent * @return a new parser function which produces a new typed action */ map(callback: Map): Parser; /** * Map the error of the parser into another error. This method is the * equivalent of map but it will be performed only for error states * @param callback a callback that produces a new error from the precedent * @return a new parser function which produces a new typed error */ error(callback: Map): Parser; /** * Chain this parser to another parser. The callback function will * choose each time which parser will be chained depending on the * current parser state. This method is similar to a flatMap operation, * where the returned parser is used to produce a new updated state. * @param callback the function which decide which parser to employ * after the current one * @return a new chained parser */ chain(callback: Map>): Parser; }; type BinMap = (result: Input, index: number, source: DataView) => Output; /** The result of a binary parsing action */ export type BinaryParserState = { /** The intial source value being parsed */ source: DataView; /** Offset (in bits - not bytes) where the last result was found */ index: number; /** The result of the last succedeed parsing action */ result: Result; /** Wether the parser produced an error */ isError: false; /** The error produced by the parser */ error: null; }; /** The error reporting state of a binary parsing action */ export type BinaryParserError = { /** The intial source value being parsed */ source: DataView; /** Offset (in bits - not bytes) where the last result was found */ index: number; /** The result of the last succedeed parsing action */ result: Result; /** Wether the parser produced an error */ isError: true; /** The error produced by the parser */ error: Error; }; export type BinaryParserOutput = BinaryParserState | BinaryParserError; export type BinaryParserStateHandler = (state: BinaryParserState) => BinaryParserOutput; export type BinaryParserErrorHandler = (state: BinaryParserError) => BinaryParserError; export type BinaryParserHandler = (state: BinaryParserOutput) => BinaryParserOutput; export type BinarySourceParser = (source: string) => BinaryParserOutput; export type BinaryParser = BinaryParserHandler & BinarySourceParser & { /** Wether the parse operates at binary level */ readonly isBinary: true; /** * Map the result of the binary parser into another result * @param callback a callback that produces a new result from the precedent * @return a new binary parser function which produces a new typed action */ map(callback: BinMap): BinaryParser; /** * Map the error of the binaryparser into another error. This method is the * equivalent of map but it will be performed only for error states * @param callback a callback that produces a new error from the precedent * @return a new binaryparser function which produces a new typed error */ error(callback: BinMap): BinaryParser; /** * Chain this binary parser to another parser. The callback function will * choose each time which binary parser will be chained depending on the * current binary parser state. This method is similar to a flatMap operation, * where the returned binary parser is used to produce a new updated state. * @param callback the function which decide which binary parser to employ * after the current one * @return a new chained binary parser */ chain(callback: BinMap>): BinaryParser; }; export declare namespace state { function ok(state: ParserState, result: Output, index?: number): ParserState; function ok(state: BinaryParserState, result: Output, index?: number): BinaryParserState; function error(state: ParserOutput, error: Output): ParserError; function error(state: BinaryParserOutput, error: Output): BinaryParserError; } /** * Create a parser out of a production function * @param handler the production function which can return a state or an error * @param error the function which will catch and elaborates errors produced by precedent operations * @returns a compiled perser */ export declare function parser(handler: ParserStateHandler, error?: ParserErrorHandler): Parser; type Binariable = string | number[] | DataView | ArrayBuffer | ArrayBufferLike; /** * Create a binary parser out of a production function * @param handler the production function which can return a binary state or an error * @param error the function which will catch and elaborates errors produced by precedent operations * @returns a compiled perser */ export declare function binary(handler: BinaryParserStateHandler, error?: BinaryParserErrorHandler): BinaryParser; /** * Create a parser which check if the current state * matches the given regular expression. The expression * will be matched just at the start of the current state * @param expression the regular expression to match * @return a parser which check if the current state starts with the * given regular expression */ export declare function match(expression: RegExp): Parser; /** * Create a parser which check if the current state * matches the given regular expression. The expression * will be matched just at the start of the current state. * The `matcher` function will be responsible to extract * the parser state out of the regex match result * @param expression the regular expression to match * @param matcher the function which extracts the parser state * @return a parser which check if the current state starts with the * given regular expression */ export declare function match(expression: RegExp, matcher: (match: RegExpMatchArray) => T): Parser; /** * Create a parser which check if the current state * starts with the given string expression. It is possible * to ignore case during the comparison. * @param expression the string expression to match * @param ignoreCase wheter to ignore case during the comparison (default: `false`) * @return a parser which check if the current state starts with the * given string */ export declare function match(expression: T, ignoreCase?: false | undefined): Parser; /** * Create a parser which check if the current state * starts with the given string expression. It is possible * to ignore case during the comparison. * @param expression the string expression to match * @param ignoreCase wheter to ignore case during the comparison (default: `false`) * @return a parser which check if the current state starts with the * given string */ export declare function match(expression: string, ignoreCase?: boolean): Parser; /** A parser which check for any letter in the range a-z (case insnsitive) */ export declare const letters: Parser; /** A parser which check for any digit in the range 0-9 */ export declare const digits: Parser; /** A parser which check for any white space */ export declare const spaces: Parser; /** A parser which check the end of the input */ export declare const eof: Parser; /** A parser which check the end of the input */ export declare const eoi: Parser; /** A parser which check the end of the input */ export declare const end: Parser; type SequenceOfParsersResult = Parsers extends [] ? [] : Parsers extends [Parser] ? [OR] : Parsers extends [Parser, ...infer Rest1] ? Rest1 extends [Parser, ...infer Rest2] ? Rest2 extends Parser[] ? [OR1, OR2, ...SequenceOfParsersResult] : never : never : Parser extends Parser[] ? OR[] : never; type SequenceOfParsersError = Parsers extends [] ? never : Parsers extends [Parser] ? OE : Parsers extends [Parser, ...infer Rest1] ? Rest1 extends [Parser, ...infer Rest2] ? Rest2 extends Parser[] ? OE1 | OE2 | SequenceOfParsersError : never : never : Parser extends Parser[] ? OE : never; type SequenceOfParsers = SequenceOfParsersResult extends never ? never : SequenceOfParsersError extends never ? never : Parser, SequenceOfParsersError, any, any>; /** * Create a parser which check the concatenation in * sequence of the given parsers * @param parsers an array of parsers to concatenate * @return a parser that is the concatenation in a sequence * of the given parsers */ export declare function sequence(parsers: Parsers): SequenceOfParsers; /** * Create a parser which check the concatenation in * sequence of the given parsers * @param parsers parsers to concatenate * @return a parser that is the concatenation in a sequence * of the given parsers */ export declare function sequence(...parsers: Parsers): SequenceOfParsers; type OneOf = Args extends [] ? never : Args extends [infer X] ? X : Args extends [infer X, ...infer Rest] ? X | OneOf : Args extends (infer X)[] ? X : never; type ParserOneOf = SequenceOfParsersResult extends never ? never : SequenceOfParsersError extends never ? never : Parser>, SequenceOfParsersError, any, any>; /** * Create a parser which returns the first success state * from any given parsers. * @param parsers an array of parsers to test * @return a parser which test the given parsers */ export declare function oneOf(parsers: Parsers): ParserOneOf; /** * Create a parser which returns the first success state * from any given parsers. * @param parsers parsers to test * @return a parser which test the given parsers */ export declare function oneOf(...parsers: Parsers): ParserOneOf; type ManyOf

= P extends Parser ? Parser : never; /** * Create a parser which tries to match the given parser * as many times as possible * @param parser the parser to test * @returns a parser which tries to match the given parser * as many times as possible */ export declare function many

(parser: P): ManyOf

; /** * Create a parser which match at least one time, * then as many times as possible, the given parser * @param parser the parser to test * @returns a parser which match at least one time, * then as many times as possible, the given parser */ export declare function oneOrMore

(parser: P): ManyOf

; /** * Create a parser which match the given parser * the given number of times * @param parser the parser to test * @param times how many exact times the parser must match * @returns a parser which match the given parser * the given number of times */ export declare function times

(parser: P, times: number): ManyOf

; /** * Create a parser which check the following syntax: * `wrapper content wrapper` from the given parsers. * The resultant parser will consider only the output of the * content parser.\ * For example, to parse a string you can use `between(match('"'), contentParser)` * @param wrapper the wrapper parser to match before and after the content * @param content the parser responsible to match the content * @return a parser which consider only the wrapped content */ export declare function between(wrapper: Parser, content: Parser): Parser; /** * Create a parser which check the following syntax: * `left content rigth` from the given parsers. * The resultant parser will consider only the output of the * content parser.\ * For example, to parse an array you can use `between(match('['), valueParser, match(']'))` * @param left the parser to match before the content * @param content the parser responsible to match the content * @param right the parser to match after the content * @return a parser which consider only the wrapped content */ export declare function between(left: Parser, content: Parser, right: Parser): Parser; /** * Generate an high-order function which creates a * between expression for a parser. This function * returns another function which takes the content * parser as argument and generate a parser which will * match the following syntax: `wrapper content wrapper`. * The resultant parser will consider only the output of the * content parser.\ * For example, to parse a string you can use * ```js * const contentParser = letters; // or whatever * const betweenQuotes = parsebetween(match('"')); * const stringParser = betweenQuotes(contentParser); * ``` * @param wrapper the wrapper parser to match before and after the content * @return an high-order function which generate a between parser expression */ export declare function parseBetween(wrapper: Parser): (content: Parser) => Parser; /** * Generate an high-order function which creates a * between expression for a parser. This function * returns another function which takes the content * parser as argument and generate a parser which will * match the following syntax: `left content right`. * The resultant parser will consider only the output of the * content parser.\ * For example, to parse a simple numeric array you can use: * ```js * const contentParser = sequence(digits, match(',')); // or whatever * const betweenBrackets = parsebetween(match('[')); * const arrayParser = betweenBrackets(contentParser); * ``` * @param left the parser to match before the content * @param right the parser to match after the content * @return an high-order function which generate a between parser expression */ export declare function parseBetween(left: Parser, right: Parser): (content: Parser) => Parser; /** * Generate a parser which tries to match one or more * times the following syntax: `(content separator)* content`. * The resultant parser will consider only the output of * the content parser.\ * For example, to parse a comma-separated list you can use: * `separated(match(','), contentPasrer)`. * @param separator the parser that matches separator * @param content the parser that match the content * @returns a parser which generate a separated expression */ export declare function separated(separator: Parser, content: Parser): Parser; /** * Generate an high-order function which creates a * separated expression for a parser. This function * returns another function which takes the content * parser as argument and generate a parser which will * match the following syntax: `(content separator)* content`. * The resultant parser will consider only the output of the * content parser.\ * For example, to parse a comma-separated list you can use: * ```js * const contentParser = letters; // or whatever * const commaSeparated = parseSeparated(match(',')); * const commaSeparatedParser = commaSeparated(contentParser); * ``` * @param separator the parser that matches separator * @return an high-order function which generate a between parser expression */ export declare function parseSeparated(separator: Parser): (content: Parser) => Parser; /** * Generate a parser which will use the given thunk lazily. * This is helpful if you need to use parsers which depends one * on the other: * ```js * const parserA = lazy(() => sequence([ parserB, digits, parserB ])); * const parserB = lazy(() => oneOf([ parserA, digits, letters ])); * ``` * @param thunk the lazy evaluated function which produce a parser * @param notCached wether to cache or not the output of the thunk (default: `false --> cached`) * @returns a parser which evaluates lazily the given thunk */ export declare function lazy

(thunk: () => P, notCached?: boolean): P; /** * Create a parser which always produces an error state * @param message the message of the error state * @returns a failure parser */ export declare function fail(message: E): Parser; /** * Create a parser which always produces a success parser state * @param value the result value of the success state * @returns a success parser */ export declare function success(value: T): Parser; type ContextualOneOf

= P extends Parser ? R : P extends Parser | infer Rest ? Rest extends Parser ? ContextualOneOf extends never ? never : R | ContextualOneOf : never : never; type ContextualCB

= () => Generator | R, ContextualOneOf

| R>; /** * Create a parser which automatically chain the parsers produced * by a generator function, yielding their parserd results states.\ * For example: * ```js * const declTypeParser = combo.oneOf( * combo.match('VAR '), * combo.match('GLOBAL_VAR ') * ); * const typeParser = combo.oneOf( * combo.match(' INT '), * combo.match(' STRING '), * combo.match(' BOOL ') * ).map(v => v.trim().toLowerCase()); * const stringParser = combo.between(combo.match('"'), combo.letters); * const numParser = combo.digits.map(Number); * const boolParser = combo.oneOf(combo.match('true'), combo.match('false')).map(v => v === 'true'); * const parser = combo.contextual(function*() { // Note that we use a generator function here * const declarationType = yield declTypeParser; // yielding parser => returning 'var' | 'global_var' * const varName = yield combo.letters; // returning string * const type = yield typeParser; // returning 'int' | 'string' | 'bool' * let data; * switch (type) { * case 'int': data = yield numParser; break; * case 'string': data = yield stringParser; break; * case 'bool': data = yield boolParser; break; * } * return { varName: varName, data, type: type.trim().toLowerCase(), declarationType: declarationType.trim().toLowerCase() }; * }); * parser('VAR theAnswer INT 42'); // { varName: 'theAnswer', data: 42, type: 'int', declarationType: 'var' } * parser('GLOBAL_VAR greeting STRING "Hello"'); // { varName: 'greetubg', data: 'Hello', type: 'string', declarationType: 'global_var' } * parser('VAR skyIsBlue BOOL true'); // { varName: 'skyIsBlue', data: true, type: 'bool', declarationType: 'var' } * ``` * @param generator the function that generates the parsers to chain * @returns a automatically chained parser */ export declare function contextual

(generator: ContextualCB): Parser; export declare namespace binary { /** * Create a binary parser which check if the current state * starts with the given binary expression * @param expression the string expression to match * @param expressionOffset the offset where the considered expression starts * @param expressionLength the length of considered expression * @return a binary parser which check if the current state starts with the given bianry expression */ export function match(expression: Binariable, expressionOffset?: number, expressionLength?: number): BinaryParser; /** A binary parser which consumes a buffer bit by bit */ export const bit: BinaryParser<0 | 1, string>; /** A binary parser which consume a buffer bit by bit, expecting an unsetted bit (0) */ export const zero: BinaryParser<0, string>; /** A binary parser which consume a buffer bit by bit, expecting a setted bit (1) */ export const one: BinaryParser<1, string>; /** * Create a binary parser which read an unsigned integer from * a fixed number of bits into a {@link Number}. The number of bits must not exceed * 32. For integers longer than 32 bits use {@link biguint} * @param bits the number of bits to read (1 <= bits <= 32) * @param bigEndian wether to read the number in Big Endian or Little Endian mode * @returns a binary parser which read an unsigned integer with the given specs */ export function uint(bits: number, bigEndian?: boolean): BinaryParser; /** A binary parser which reads an unsigned 8-bit (1 byte) integer as {@link Number} */ export const uint8: BinaryParser; /** A binary parser which reads an unsigned 8-bit (1 byte) integer as {@link Number}, Big Endian mode */ export const uint8BE: BinaryParser; /** A binary parser which reads an unsigned 16-bit (2 byte) integer as {@link Number} */ export const uint16: BinaryParser; /** A binary parser which reads an unsigned 16-bit (2 byte) integer as {@link Number}, Big Endian mode */ export const uint16BE: BinaryParser; /** A binary parser which reads an unsigned 24-bit (3 byte) integer as {@link Number} */ export const uint24: BinaryParser; /** A binary parser which reads an unsigned 24-bit (3 byte) integer as {@link Number}, Big Endian mode */ export const uint24BE: BinaryParser; /** A binary parser which reads an unsigned 32-bit (4 byte) integer as {@link Number} */ export const uint32: BinaryParser; /** A binary parser which reads an unsigned 32-bit (4 byte) integer as {@link Number}, BigEndian mode */ export const uint32BE: BinaryParser; /** * Create a binary parser which read an unsigned integer from * a fixed number of bits into a {@link BigInt}. The number of * readable bits is limited by JS environment implementation. * @param bits the number of bits to read (bits >= 1) * @param bigEndian wether to read the number in Big Endian or Little Endian mode * @returns a binary parser which read an unsigned integer with the given specs */ export function biguint(bits: number, bigEndian?: boolean): BinaryParser; /** A binary parser which reads an unsigned 64-bit (8 byte) integer as {@link BigInt} */ export const uint64: BinaryParser; /** A binary parser which reads an unsigned 64-bit (8 byte) integer as {@link BigInt}, Big Endian mode */ export const uint64BE: BinaryParser; /** A binary parser which reads an unsigned 128-bit (16 byte) integer as {@link BigInt} */ export const uint128: BinaryParser; /** A binary parser which reads an unsigned 128-bit (16 byte) integer as {@link BigInt}, Big Endian mode */ export const uint128BE: BinaryParser; /** A binary parser which reads an unsigned 256-bit (32 byte) integer as {@link BigInt} */ export const uint256: BinaryParser; /** A binary parser which reads an unsigned 256-bit (32 byte) integer as {@link BigInt}, Big Endian mode */ export const uint256BE: BinaryParser; /** * Create a binary parser which read a signed integer from * a fixed number of bits into a {@link Number}. The number of bits must not exceed * 32. For integers longer than 32 bits use {@link bigint} * @param bits the number of bits to read (1 <= bits <= 32) * @param bigEndian wether to read the number in Big Endian or Little Endian mode * @returns a binary parser which read a signed integer with the given specs */ export function int(bits: number, bigEndian?: boolean): BinaryParser; /** A binary parser which reads a signed 8-bit (1 byte) integer as {@link Number} */ export const int8: BinaryParser; /** A binary parser which reads a signed 8-bit (1 byte) integer as {@link Number}, Big Endian mode */ export const int8BE: BinaryParser; /** A binary parser which reads a signed 16-bit (2 byte) integer as {@link Number} */ export const int16: BinaryParser; /** A binary parser which reads a signed 16-bit (2 byte) integer as {@link Number}, Big Endian mode */ export const int16BE: BinaryParser; /** A binary parser which reads a signed 24-bit (3 byte) integer as {@link Number} */ export const int24: BinaryParser; /** A binary parser which reads a signed 24-bit (3 byte) integer as {@link Number}, Big Endian mode */ export const int24BE: BinaryParser; /** A binary parser which reads a signed 32-bit (4 byte) integer as {@link Number} */ export const int32: BinaryParser; /** A binary parser which reads a signed 32-bit (4 byte) integer as {@link Number}, Big Endian mode */ export const int32BE: BinaryParser; /** * Create a binary parser which read a signed integer from * a fixed number of bits into a {@link BigInt}. The number of * readable bits is limited by JS environment implementation. * @param bits the number of bits to read (bits >= 1) * @param bigEndian wether to read the number in Big Endian or Little Endian mode * @returns a binary parser which read a signed integer with the given specs */ export function bigint(bits: number, bigEndian?: boolean): BinaryParser; /** A binary parser which reads an unsigned 64-bit (8 byte) integer as {@link BigInt} */ export const int64: BinaryParser; /** A binary parser which reads an unsigned 64-bit (8 byte) integer as {@link BigInt}, Big Endian mode */ export const int64BE: BinaryParser; /** A binary parser which reads an unsigned 128-bit (16 byte) integer as {@link BigInt} */ export const int128: BinaryParser; /** A binary parser which reads an unsigned 128-bit (16 byte) integer as {@link BigInt}, Big Endian mode */ export const int128BE: BinaryParser; /** A binary parser which reads an unsigned 256-bit (32 byte) integer as {@link BigInt} */ export const int256: BinaryParser; /** A binary parser which reads an unsigned 256-bit (32 byte) integer as {@link BigInt}, Big Endian mode */ export const int256BE: BinaryParser; type SequenceOfParsersResult = Parsers extends [] ? [] : Parsers extends [BinaryParser] ? [OR] : Parsers extends [BinaryParser, ...infer Rest1] ? Rest1 extends [BinaryParser, ...infer Rest2] ? Rest2 extends BinaryParser[] ? [OR1, OR2, ...SequenceOfParsersResult] : never : never : Parsers extends BinaryParser[] ? OR[] : never; type SequenceOfParsersError = Parsers extends [] ? never : Parsers extends [BinaryParser] ? OE : Parsers extends [BinaryParser, ...infer Rest1] ? Rest1 extends [BinaryParser, ...infer Rest2] ? Rest2 extends BinaryParser[] ? OE1 | OE2 | SequenceOfParsersError : never : never : Parsers extends BinaryParser[] ? OE : never; type SequenceOfParsers = SequenceOfParsersResult extends never ? never : SequenceOfParsersError extends never ? never : BinaryParser, SequenceOfParsersError, any, any>; /** * Create a binary parser which check the concatenation in * sequence of the given binary parsers * @param parsers an array of binary parsers to concatenate * @return a binary parser that is the concatenation in a sequence * of the given binary parsers */ export function sequence(parsers: Parsers): SequenceOfParsers; /** * Create a binary parser which check the concatenation in * sequence of the given binary parsers * @param parsers binary parsers to concatenate * @return a binary parser that is the concatenation in a sequence * of the given binary parsers */ export function sequence(...parsers: Parsers): SequenceOfParsers; type ParserOneOf = SequenceOfParsersResult extends never ? never : SequenceOfParsersError extends never ? never : Parser>, SequenceOfParsersError, any, any>; /** * Create a binary parser which returns the first success state * from any given binary parsers. * @param parsers an array of binary parsers to test * @return a binary parser which test the given binary parsers */ export function oneOf(parsers: Parsers): ParserOneOf; /** * Create a binary parser which returns the first success state * from any given binary parsers. * @param parsers binary parsers to test * @return a binary parser which test the given binary parsers */ export function oneOf(...parsers: Parsers): ParserOneOf; type ManyOf

= P extends BinaryParser ? BinaryParser : never; /** * Create a binary parser which tries to match the given binary parser * as many times as possible * @param parser the binary parser to test * @returns a binary parser which tries to match the given binary parser * as many times as possible */ export function many

(parser: P): ManyOf

; /** * Create a binary parser which match at least one time, * then as many times as possible, the given binary parser * @param parser the binary parser to test * @returns a binary parser which match at least one time, * then as many times as possible, the given binary parser */ export function oneOrMore

(parser: P): ManyOf

; /** * Create a binary parser which match the given binary parser * the given number of times * @param parser the binary parser to test * @param times how many exact times the binary parser must match * @returns a binary parser which match the given binary parser * the given number of times */ export function times

(parser: P, times: number): ManyOf

; /** * Create a binary parser which check the following syntax: * `wrapper content wrapper` from the given binary parsers. * The resultant binary parser will consider only the output of the * content binary parser.\ * For example, to parse a binary string enclosed by the sequence `0110` you can use * `between(sequence(zero, one, one, zero), contentParser)` * @param wrapper the wrapper binary parser to match before and after the content * @param content the binary parser responsible to match the content * @return a binary parser which consider only the wrapped content */ export function between(wrapper: BinaryParser, content: BinaryParser): BinaryParser; /** * Create a binary parser which check the following syntax: * `left content rigth` from the given binary parsers. * The resultant binary parser will consider only the output of the * content binary parser.\ * For example, to parse a binary string enclosed by the sequence `0110` and `1001` you can use * `between(sequence(zero, one, one, zero), contentParser, sequence(one, zero, zero, one))` * @param left the binary parser to match before the content * @param content the binary parser responsible to match the content * @param right the binary parser to match after the content * @return a binary parser which consider only the wrapped content */ export function between(left: BinaryParser, content: BinaryParser, right: BinaryParser): BinaryParser; /** * Generate an high-order function which creates a * between expression for a binary parser. This function * returns another function which takes the content * binary parser as argument and generate a binary parser which will * match the following syntax: `wrapper content wrapper`. * The resultant binary parser will consider only the output of the * content binary parser.\ * For example, to parse content between the sequence `0110` you can use * ```js * const contentParser = uint8; // or whatever * const betweenSequence = parsebetween(sequence(zero, one, one, zero)); * const myParser = betweenSequence(contentParser); * ``` * @param wrapper the wrapper binary parser to match before and after the content * @return an high-order function which generate a binary between parser expression */ export function parseBetween(wrapper: BinaryParser): (content: BinaryParser) => BinaryParser; /** * Generate an high-order function which creates a * between expression for a binary parser. This function * returns another function which takes the content * binary parser as argument and generate a binary parser which will * match the following syntax: `left content right`. * The resultant binary parser will consider only the output of the * content binary parser.\ * For example, to parse content between the sequence `0110` and `1001` you can use * ```js * const contentParser = uint8; // or whatever * const betweenSequence = parsebetween(sequence(zero, one, one, zero), sequence(one, zero, zero, one)); * const myParser = betweenSequence(contentParser); * ``` * @param left the parser to match before the content * @param right the parser to match after the content * @return an high-order function which generate a between parser expression */ export function parseBetween(left: BinaryParser, right: BinaryParser): (content: BinaryParser) => BinaryParser; /** * Generate a binary parser which tries to match one or more * times the following syntax: `(content separator)* content`. * The resultant binary parser will consider only the output of * the content binary parser.\ * For example, to a list separated by the sequence `000` you can use: * `separated(sequence(zero, zero, zero), contentPasrer)`. * @param separator the binary parser that matches separator * @param content the binary parser that match the content * @returns a binary parser which generate a separated expression */ export function separated(separator: BinaryParser, content: BinaryParser): BinaryParser; /** * Generate an high-order function which creates a * separated expression for a binary parser. This function * returns another function which takes the content * binary parser as argument and generate a binary parser which will * match the following syntax: `(content separator)* content`. * The resultant binary parser will consider only the output of the * content binary parser.\ * For example, to parse a list which elements are separated by `0` you can use: * ```js * const contentParser = uint8; // or whatever * const zeroSeparated = parseSeparated(zero); * const zeroSeparatedParser = zeroSeparated(contentParser); * ``` * @param separator the binary parser that matches separator * @return an high-order function which generate a binary between parser expression */ export function parseSeparated(separator: BinaryParser): (content: BinaryParser) => BinaryParser; /** * Generate a binary parser which will use the given thunk lazily. * This is helpful if you need to use binary parsers which depends one * on the other: * ```js * const parserA = lazy(() => sequence(parserB, zero, zero, parserB)); * const parserB = lazy(() => oneOf(parserA, sequence(zero, zero, one), sequence(one, one, zero))); * ``` * @param thunk the lazy evaluated function which produce a binary parser * @param notCached wether to cache or not the output of the thunk (default: `false --> cached`) * @returns a binary parser which evaluates lazily the given thunk */ export function lazy

(thunk: () => P, notCached?: boolean): P; /** * Create a binary parser which always produces an error state * @param message the message of the error state * @returns a failure binary parser */ export function fail(message: E): BinaryParser; /** * Create a binary parser which always produces a success binary parser state * @param value the result value of the success state * @returns a success binary parser */ export function success(value: T): BinaryParser; type ContextualOneOf

= P extends BinaryParser ? R : P extends BinaryParser | infer Rest ? Rest extends BinaryParser ? ContextualOneOf extends never ? never : R | ContextualOneOf : never : never; type ContextualCB

= () => Generator | R, ContextualOneOf

| R>; /** * Create a binary parser which automatically chain the binary parsers produced * by a generator function, yielding their parserd binary results states.\ * See the non binary version of this function for a tip on the usage. * @param generator the function that generates the binary parsers to chain * @returns a automatically chained binary parser */ export function contextual

(generator: ContextualCB): BinaryParser; /** * Utility function to convert a string or an array * into a buffer. Note that all non-zero characters * are considered as a one bit, as well as any non * truish numeric values (eg. `0, NaN`). * @param value the value to being converted * @returns the converted buffer as a {@link DataView} */ export function asBinary(value: string | (boolean | 1 | 0 | '1' | '0')[]): DataView; /** * Converts a string to a byte array buffer * @param value the string to convert * @returns the converted buffer as a {@link DataView} */ export function toCharCode(value: string): DataView; export {}; } declare const _default: { binary: typeof binary; between: typeof between; contextual: typeof contextual; digits: Parser; end: Parser; eof: Parser; eoi: Parser; fail: typeof fail; lazy: typeof lazy; letters: Parser; many: typeof many; match: typeof match; parseBetween: typeof parseBetween; parseSeparated: typeof parseSeparated; parser: typeof parser; success: typeof success; separated: typeof separated; sequence: typeof sequence; spaces: Parser; state: typeof state; times: typeof times; oneOf: typeof oneOf; oneOrMore: typeof oneOrMore; }; export default _default;