Variable LexerConst

Lexer: {
    anyOf: ((str: string) => Rule<string, string>);
    create: (<H, Rules>(collect: [Rule<string, H>, ...Rules[]], ignore?: Rule<string, unknown>) => Rule<string, ResultsAsUnion<[Rule<string, H>, ...Rules[]]>[]>);
    delimiters: (<Suffix>(suffix: Suffix, open: string, close: string) => [Rule<string, {
        type: `open_${Suffix}`;
    }>, Rule<string, {
        type: `close_${Suffix}`;
    }>]);
    end: Rule<string, undefined>;
    exact: ((...str: [string, ...string[]]) => Rule<string, undefined>);
    feed: ((text: string) => (<O>(rule: LexRule<O>) => Result<O>));
    keyword: (<Type>(type: Type, display?: string) => Rule<string, {
        type: Type;
    }>);
    noneOf: ((str: string) => Rule<string, string>);
    optional: (<E, R>(rule: Rule<E, R>) => Rule<E, undefined | R>);
    skipWhile: ((pred: ((el: string) => boolean)) => Rule<string, undefined>);
    slice: ((rule: Rule<string, unknown>) => Rule<string, string>);
    whitespace: Rule<string, string>;
} = ...

Type declaration

  • anyOf: ((str: string) => Rule<string, string>)
      • (str): Rule<string, string>
      • Parameters

        • str: string

        Returns Rule<string, string>

        A rule that matches any character as long as it belongs to the graphemes in str

  • create: (<H, Rules>(collect: [Rule<string, H>, ...Rules[]], ignore?: Rule<string, unknown>) => Rule<string, ResultsAsUnion<[Rule<string, H>, ...Rules[]]>[]>)
  • delimiters: (<Suffix>(suffix: Suffix, open: string, close: string) => [Rule<string, {
        type: `open_${Suffix}`;
    }>, Rule<string, {
        type: `close_${Suffix}`;
    }>])
      • <Suffix>(suffix, open, close): [Rule<string, {
            type: `open_${Suffix}`;
        }>, Rule<string, {
            type: `close_${Suffix}`;
        }>]
      • Type Parameters

        • Suffix extends string

        Parameters

        • suffix: Suffix
        • open: string
        • close: string

        Returns [Rule<string, {
            type: `open_${Suffix}`;
        }>, Rule<string, {
            type: `close_${Suffix}`;
        }>]

  • end: Rule<string, undefined>
  • exact: ((...str: [string, ...string[]]) => Rule<string, undefined>)
      • (...str): Rule<string, undefined>
      • Parameters

        • Rest...str: [string, ...string[]]

        Returns Rule<string, undefined>

        A rule that accepts the stream only if it follows exactly with str

  • feed: ((text: string) => (<O>(rule: LexRule<O>) => Result<O>))
  • keyword: (<Type>(type: Type, display?: string) => Rule<string, {
        type: Type;
    }>)
      • <Type>(type, display?): Rule<string, {
            type: Type;
        }>
      • Utility function to create tokens that are discriminated by the field type (ie. {type:'text'})

        Type Parameters

        • Type extends string

        Parameters

        • type: Type
        • display: string = type

        Returns Rule<string, {
            type: Type;
        }>

  • noneOf: ((str: string) => Rule<string, string>)
      • (str): Rule<string, string>
      • Parameters

        • str: string

        Returns Rule<string, string>

        A rule that accepts any character, unless it belongs to the graphemes in str

  • optional: (<E, R>(rule: Rule<E, R>) => Rule<E, undefined | R>)
      • <E, R>(rule): Rule<E, undefined | R>
      • Matches the given rule, or nothing if original rule doesn't match

        Type Parameters

        • E
        • R

        Parameters

        Returns Rule<E, undefined | R>

        A rule that may or may not match the original rule

  • skipWhile: ((pred: ((el: string) => boolean)) => Rule<string, undefined>)
      • (pred): Rule<string, undefined>
      • Parameters

        • pred: ((el: string) => boolean)
            • (el): boolean
            • Parameters

              • el: string

              Returns boolean

        Returns Rule<string, undefined>

        A rule that matches as many characters, as long as they pass predicated pred

  • slice: ((rule: Rule<string, unknown>) => Rule<string, string>)
      • (rule): Rule<string, string>
      • Parameters

        • rule: Rule<string, unknown>

        Returns Rule<string, string>

        A rule that returns the matched substring

  • whitespace: Rule<string, string>