Interface ILookaheadStrategyExperimental

interface ILookaheadStrategy {
    buildLookaheadForAlternation(options: {
        dynamicTokensEnabled: boolean;
        hasPredicates: boolean;
        maxLookahead: number;
        prodOccurrence: number;
        rule: Rule;
    }): ((orAlts?: IOrAlt<any>[]) => undefined | number);
    buildLookaheadForOptional(options: {
        dynamicTokensEnabled: boolean;
        maxLookahead: number;
        prodOccurrence: number;
        prodType: OptionalProductionType;
        rule: Rule;
    }): (() => boolean);
    initialize?(options: {
        rules: Rule[];
    }): void;
    validate(options: {
        grammarName: string;
        rules: Rule[];
        tokenTypes: TokenType[];
    }): ILookaheadValidationError[];
}

Methods

  • Experimental

    Builds a lookahead function for alternations/OR parser methods.

    Parameters

    • options: {
          dynamicTokensEnabled: boolean;
          hasPredicates: boolean;
          maxLookahead: number;
          prodOccurrence: number;
          rule: Rule;
      }
      • dynamicTokensEnabled: boolean

        Whether dynamic tokens are enabled for this parser.

      • hasPredicates: boolean

        Whether any of the alternatives contain a predicate.

      • maxLookahead: number

        The maximum amount of lookahead for this OR.

      • prodOccurrence: number

        The occurrence number of this OR within its rule.

      • rule: Rule

        The rule that contains this OR.

    Returns ((orAlts?: IOrAlt<any>[]) => undefined | number)

    A function that is able to compute which of the alternatives to choose while parsing.

      • (orAlts?): undefined | number
      • Parameters

        Returns undefined | number

  • Experimental

    Builds a lookahead function for optional productions.

    Parameters

    • options: {
          dynamicTokensEnabled: boolean;
          maxLookahead: number;
          prodOccurrence: number;
          prodType: OptionalProductionType;
          rule: Rule;
      }
      • dynamicTokensEnabled: boolean

        Whether dynamic tokens are enabled for this parser.

      • maxLookahead: number

        The maximum amount of lookahead for this production.

      • prodOccurrence: number

        The occurrence number of this production within its rule.

      • prodType: OptionalProductionType

        The type of this production.

      • rule: Rule

        The rule that contains this production.

    Returns (() => boolean)

    A function is able to compute whether to parse the production or to continue with the rest of the parser rule.

      • (): boolean
      • Returns boolean

  • Experimental

    Initializes the lookahead for a grammar.

    Note that this method does not build the lookahead functions. It only initializes the internal state of the strategy based on all grammar rules.

    Parameters

    • options: {
          rules: Rule[];
      }
      • rules: Rule[]

        All parser rules of the grammar.

    Returns void

  • Experimental

    Performs validations on the grammar specific to this lookahead strategy. This method is not called if parser validations are disabled.

    Parameters

    • options: {
          grammarName: string;
          rules: Rule[];
          tokenTypes: TokenType[];
      }
      • grammarName: string

        The name of the grammar.

      • rules: Rule[]

        All parser rules of the grammar.

      • tokenTypes: TokenType[]

        All token types of the grammar.

    Returns ILookaheadValidationError[]