Options
All
  • Public
  • Public/Protected
  • All
Menu

This class does not actually exists nor is exposed at runtime. This is just a helper to avoid duplications in the Type Definitions Of CstParser and EmbeddedActionsParser

Hierarchy

Index

Constructors

constructor

Properties

RECORDING_PHASE

RECORDING_PHASE: boolean

Flag indicating the Parser is at the recording phase. Can be used to implement methods similar to BaseParser.ACTION Or any other logic to requires knowledge of the recording phase. See:

errors

input

input: IToken[]

Methods

Protected ACTION

  • ACTION<T>(impl: () => T): T
  • The Semantic Actions wrapper. Should be used to wrap semantic actions that either:

    • May fail when executing in "recording phase".
    • Have global side effects that should be avoided during "recording phase".

    Type parameters

    • T

    Parameters

    • impl: () => T
        • (): T
        • Returns T

    Returns T

Protected AT_LEAST_ONE

  • Convenience method, same as MANY but the repetition is of one or more. failing to match at least one repetition will result in a parsing error and cause a parsing error.

    see

    MANY

    Parameters

    • actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>

      The grammar action to optionally invoke multiple times or an "OPTIONS" object describing the grammar action and optional properties.

    Returns void

Protected AT_LEAST_ONE_SEP

  • Convenience method, same as MANY_SEP but the repetition is of one or more. failing to match at least one repetition will result in a parsing error and cause the parser to attempt error recovery.

    Note that an additional optional property ERR_MSG can be used to provide custom error messages.

    see

    MANY_SEP

    Parameters

    • options: AtLeastOneSepMethodOpts<any>

      An object defining the grammar of each iteration and the separator between iterations

    Returns void

Protected BACKTRACK

  • BACKTRACK<T>(grammarRule: (...args: any[]) => T, args?: any[]): () => boolean
  • Type parameters

    • T

    Parameters

    • grammarRule: (...args: any[]) => T

      The rule to try and parse in backtracking mode.

        • (...args: any[]): T
        • Parameters

          • Rest ...args: any[]

          Returns T

    • Optional args: any[]

      argument to be passed to the grammar rule execution

    Returns () => boolean

    a lookahead function that will try to parse the given grammarRule and will return true if succeed.

      • (): boolean
      • Returns boolean

        a lookahead function that will try to parse the given grammarRule and will return true if succeed.

Protected CONSUME

  • A Parsing DSL method use to consume a single Token. In EBNF terms this is equivalent to a Terminal.

    A Token will be consumed, IFF the next token in the token vector matches tokType. otherwise the parser may attempt to perform error recovery (if enabled).

    The index in the method name indicates the unique occurrence of a terminal consumption inside a the top level rule. What this means is that if a terminal appears more than once in a single rule, each appearance must have a different index.

    For example:

      this.RULE("qualifiedName", () => {
    this.CONSUME1(Identifier);
    this.MANY(() => {
    this.CONSUME1(Dot);
    // here we use CONSUME2 because the terminal
    // 'Identifier' has already appeared previously in the
    // the rule 'parseQualifiedName'
    this.CONSUME2(Identifier);
    });
    })

    Parameters

    • tokType: TokenType

      The Type of the token to be consumed.

    • Optional options: ConsumeMethodOpts

      optional properties to modify the behavior of CONSUME.

    Returns IToken

Protected LA

  • Look-Ahead for the Token Vector LA(1) is the next Token ahead. LA(n) is the nth Token ahead. LA(0) is the previously consumed Token.

    Looking beyond the end of the Token Vector or before its begining will return in an IToken of type EOF EOF. This behavior can be used to avoid infinite loops.

    This is often used to implement custom lookahead logic for GATES. https://chevrotain.io/docs/features/gates.html

    Parameters

    • howMuch: number

    Returns IToken

Protected MANY

  • Parsing DSL method, that indicates a repetition of zero or more. This is equivalent to EBNF repetition {...}.

    Note that there are two syntax forms:

    • Passing the grammar action directly:

        this.MANY(() => {
      this.CONSUME(Comma)
      this.CONSUME(Digit)
      })
    • using an "options" object:

        this.MANY({
      GATE: predicateFunc,
      DEF: () => {
      this.CONSUME(Comma)
      this.CONSUME(Digit)
      }
      });

    The optional 'GATE' property in "options" object form can be used to add constraints to invoking the grammar action.

    As in CONSUME the index in the method name indicates the occurrence of the repetition production in it's top rule.

    Parameters

    • actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>

      The grammar action to optionally invoke multiple times or an "OPTIONS" object describing the grammar action and optional properties.

    Returns void

Protected MANY_SEP

  • Parsing DSL method, that indicates a repetition of zero or more with a separator Token between the repetitions.

    Example:

        this.MANY_SEP({
    SEP:Comma,
    DEF: () => {
    this.CONSUME(Number};
    // ...
    })

    Note that because this DSL method always requires more than one argument the options object is always required and it is not possible to use a shorter form like in the MANY DSL method.

    Note that for the purposes of deciding on whether or not another iteration exists Only a single Token is examined (The separator). Therefore if the grammar being implemented is so "crazy" to require multiple tokens to identify an item separator please use the more basic DSL methods to implement it.

    As in CONSUME the index in the method name indicates the occurrence of the repetition production in it's top rule.

    Parameters

    • options: ManySepMethodOpts<any>

      An object defining the grammar of each iteration and the separator between iterations

    Returns void

Protected OPTION

  • Parsing DSL Method that Indicates an Optional production. in EBNF notation this is equivalent to: "[...]".

    Note that there are two syntax forms:

    • Passing the grammar action directly:

        this.OPTION(() => {
      this.CONSUME(Digit)}
      );
    • using an "options" object:

        this.OPTION({
      GATE:predicateFunc,
      DEF: () => {
      this.CONSUME(Digit)
      }});

    The optional 'GATE' property in "options" object form can be used to add constraints to invoking the grammar action.

    As in CONSUME the index in the method name indicates the occurrence of the optional production in it's top rule.

    Type parameters

    • OUT

    Parameters

    • actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>

      The grammar action to optionally invoke once or an "OPTIONS" object describing the grammar action and optional properties.

    Returns undefined | OUT

    The GrammarAction return value (OUT) if the optional syntax is encountered or undefined if not.

Protected OR

  • Parsing DSL method that indicates a choice between a set of alternatives must be made. This is equivalent to an EBNF alternation (A | B | C | D ...), except that the alternatives are ordered like in a PEG grammar. This means that the first matching alternative is always chosen.

    There are several forms for the inner alternatives array:

    • Passing alternatives array directly:

        this.OR([
      { ALT:() => { this.CONSUME(One) }},
      { ALT:() => { this.CONSUME(Two) }},
      { ALT:() => { this.CONSUME(Three) }}
      ])
    • Passing alternative array directly with predicates (GATE):

        this.OR([
      { GATE: predicateFunc1, ALT:() => { this.CONSUME(One) }},
      { GATE: predicateFuncX, ALT:() => { this.CONSUME(Two) }},
      { GATE: predicateFuncX, ALT:() => { this.CONSUME(Three) }}
      ])
    • These syntax forms can also be mixed:

        this.OR([
      {
      GATE: predicateFunc1,
      ALT:() => { this.CONSUME(One) }
      },
      { ALT:() => { this.CONSUME(Two) }},
      { ALT:() => { this.CONSUME(Three) }}
      ])
    • Additionally an "options" object may be used:

        this.OR({
      DEF:[
      { ALT:() => { this.CONSUME(One) }},
      { ALT:() => { this.CONSUME(Two) }},
      { ALT:() => { this.CONSUME(Three) }}
      ],
      // OPTIONAL property
      ERR_MSG: "A Number"
      })

    The 'predicateFuncX' in the long form can be used to add constraints to choosing the alternative.

    As in CONSUME the index in the method name indicates the occurrence of the alternation production in it's top rule.

    Type parameters

    • T

    Parameters

    • altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>

      A set of alternatives or an "OPTIONS" object describing the alternatives and optional properties.

    Returns T

    The result of invoking the chosen alternative.

  • Parameters

    Returns any

Protected OR1

Protected OR2

Protected OR3

Protected OR4

Protected OR5

Protected OR6

Protected OR7

Protected OR8

Protected OR9

Protected SKIP_TOKEN

Protected atLeastOne

  • Like AT_LEAST_ONE with the numerical suffix as a parameter, e.g: atLeastOne(0, X) === AT_LEAST_ONE(X) atLeastOne(1, X) === AT_LEAST_ONE1(X) atLeastOne(2, X) === AT_LEAST_ONE2(X) ...

    see

    AT_LEAST_ONE

    Parameters

    Returns void

Protected canTokenTypeBeInsertedInRecovery

  • canTokenTypeBeInsertedInRecovery(tokType: TokenType): boolean
  • By default all tokens type may be inserted. This behavior may be overridden in inheriting Recognizers for example: One may decide that only punctuation tokens may be inserted automatically as they have no additional semantic value. (A mandatory semicolon has no additional semantic meaning, but an Integer may have additional meaning depending on its int value and context (Inserting an integer 0 in cardinality: "[1..]" will cause semantic issues as the max of the cardinality will be greater than the min value (and this is a false error!).

    Parameters

    Returns boolean

computeContentAssist

Protected consume

  • Like CONSUME with the numerical suffix as a parameter, e.g: consume(0, X) === CONSUME(X) consume(1, X) === CONSUME1(X) consume(2, X) === CONSUME2(X) ...

    see

    CONSUME

    Parameters

    Returns IToken

getBaseCstVisitorConstructor

  • getBaseCstVisitorConstructor(): new (...args: any[]) => ICstVisitor<any, any>

getBaseCstVisitorConstructorWithDefaults

  • getBaseCstVisitorConstructorWithDefaults(): new (...args: any[]) => ICstVisitor<any, any>

getGAstProductions

  • getGAstProductions(): Record<string, Rule>

Protected getNextPossibleTokenTypes

getSerializedGastProductions

Protected getTokenToInsert

  • Returns an "imaginary" Token to insert when Single Token Insertion is done Override this if you require special behavior in your grammar. For example if an IntegerToken is required provide one with the image '0' so it would be valid syntactically.

    Parameters

    Returns IToken

Protected many

  • Like MANY with the numerical suffix as a parameter, e.g: many(0, X) === MANY(X) many(1, X) === MANY1(X) many(2, X) === MANY2(X) ...

    see

    MANY

    Parameters

    Returns void

Protected option

  • Like OPTION with the numerical suffix as a parameter, e.g: option(0, X) === OPTION(X) option(1, X) === OPTION1(X) option(2, X) === OPTION2(X) ...

    see

    OPTION

    Type parameters

    • OUT

    Parameters

    Returns undefined | OUT

Protected or

  • Like OR with the numerical suffix as a parameter, e.g: or(0, X) === OR(X) or(1, X) === OR1(X) or(2, X) === OR2(X) ...

    see

    OR

    Parameters

    Returns any

  • Type parameters

    • T

    Parameters

    Returns T

Protected performSelfAnalysis

  • performSelfAnalysis(): void

reset

  • reset(): void
  • Resets the parser state, should be overridden for custom parsers which "carry" additional state. When overriding, remember to also invoke the super implementation!

    Returns void

Generated using TypeDoc