Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Parser

A Recognizer capable of self analysis to determine it's grammar structure This is used for more advanced features requiring such information. For example: Error Recovery, Automatic lookahead calculation.

Hierarchy

  • Parser

Index

Constructors

Properties

Methods

Constructors

constructor

  • Only used internally for storing productions as they are built for the first time. The final productions should be accessed from the static cache.

    Parameters

    Returns Parser

Properties

Protected CST_STACK

CST_STACK: CstNode[]

Protected RULE_OCCURRENCE_STACK

RULE_OCCURRENCE_STACK: number[]

Protected RULE_STACK

RULE_STACK: string[]

Protected _errors

Protected className

className: string

Protected dynamicTokensEnabled

dynamicTokensEnabled: boolean

Protected errorMessageProvider

errorMessageProvider: IParserErrorMessageProvider

errors

Protected ignoredIssues

ignoredIssues: IgnoredParserIssues

input

input: IToken[]

Protected isBackTrackingStack

isBackTrackingStack: any[]

Protected maxLookahead

maxLookahead: number

Protected outputCst

outputCst: boolean

Protected recoveryEnabled

recoveryEnabled: boolean

This flag enables or disables error recovery (fault tolerance) of the parser. If this flag is disabled the parser will halt on the first error.

Protected tokensMap

tokensMap: object

Type declaration

Static DEFER_DEFINITION_ERRORS_HANDLING

DEFER_DEFINITION_ERRORS_HANDLING: boolean

Static NO_RESYNC

NO_RESYNC: boolean

Methods

Protected AT_LEAST_ONE

  • Convenience method equivalent to AT_LEAST_ONE1.

    see

    AT_LEAST_ONE1

    Type parameters

    • OUT

    Parameters

    Returns OUT[]

Protected AT_LEAST_ONE1

  • 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

    MANY1

    Type parameters

    • OUT

    Parameters

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

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

    Returns OUT[]

Protected AT_LEAST_ONE2

Protected AT_LEAST_ONE3

Protected AT_LEAST_ONE4

Protected AT_LEAST_ONE5

Protected AT_LEAST_ONE6

Protected AT_LEAST_ONE7

Protected AT_LEAST_ONE8

Protected AT_LEAST_ONE9

Protected AT_LEAST_ONE_SEP

Protected AT_LEAST_ONE_SEP1

  • 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_SEP1

    Type parameters

    • OUT

    Parameters

    • options: AtLeastOneSepMethodOpts<OUT>

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

    Returns ISeparatedIterationResult<OUT>

Protected AT_LEAST_ONE_SEP2

Protected AT_LEAST_ONE_SEP3

Protected AT_LEAST_ONE_SEP4

Protected AT_LEAST_ONE_SEP5

Protected AT_LEAST_ONE_SEP6

Protected AT_LEAST_ONE_SEP7

Protected AT_LEAST_ONE_SEP8

Protected AT_LEAST_ONE_SEP9

Protected BACKTRACK

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

    • T

    Parameters

    • grammarRule: function

      The rule to try and parse in backtracking mode.

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

          • Rest ...args: any[]

          Returns T

    • Optional args: any[]

      argumens to be passed to the grammar rule execution

    Returns function

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

      • (): boolean
      • Returns boolean

Protected CONSUME

  • Convenience method equivalent to CONSUME1.

    see

    CONSUME1

    Parameters

    Returns IToken

Protected CONSUME1

  • A Parsing DSL method use to consume a single terminal Token. a Token will be consumed, IFF the next token in the token vector matches . otherwise the parser will attempt to perform error recovery.

    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 difference index.

    for example:

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

    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 CONSUME2

Protected CONSUME3

Protected CONSUME4

Protected CONSUME5

Protected CONSUME6

Protected CONSUME7

Protected CONSUME8

Protected CONSUME9

Protected LA

  • Parameters

    • howMuch: number

    Returns IToken

Protected MANY

  • Convenience method equivalent to MANY1.

    see

    MANY1

    Type parameters

    • OUT

    Parameters

    Returns OUT[]

Protected MANY1

  • 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.

    Type parameters

    • OUT

    Parameters

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

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

    Returns OUT[]

Protected MANY2

  • see

    MANY1

    Type parameters

    • OUT

    Parameters

    Returns OUT[]

Protected MANY3

  • see

    MANY1

    Type parameters

    • OUT

    Parameters

    Returns OUT[]

Protected MANY4

  • see

    MANY1

    Type parameters

    • OUT

    Parameters

    Returns OUT[]

Protected MANY5

  • see

    MANY1

    Type parameters

    • OUT

    Parameters

    Returns OUT[]

Protected MANY6

  • see

    MANY1

    Type parameters

    • OUT

    Parameters

    Returns OUT[]

Protected MANY7

  • see

    MANY1

    Type parameters

    • OUT

    Parameters

    Returns OUT[]

Protected MANY8

  • see

    MANY1

    Type parameters

    • OUT

    Parameters

    Returns OUT[]

Protected MANY9

  • see

    MANY1

    Type parameters

    • OUT

    Parameters

    Returns OUT[]

Protected MANY_SEP

Protected MANY_SEP1

  • 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.

    Note that due to current limitations in the implementation the "SEP" property must appear BEFORE the "DEF" property.

    Type parameters

    • OUT

    Parameters

    • options: ManySepMethodOpts<OUT>

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

    Returns ISeparatedIterationResult<OUT>

Protected MANY_SEP2

Protected MANY_SEP3

Protected MANY_SEP4

Protected MANY_SEP5

Protected MANY_SEP6

Protected MANY_SEP7

Protected MANY_SEP8

Protected MANY_SEP9

Protected OPTION

  • Convenience method equivalent to OPTION1.

    see

    OPTION1

    Type parameters

    • OUT

    Parameters

    Returns OUT

Protected OPTION1

  • Parsing DSL Method that Indicates an Optional production in EBNF notation: [...].

    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 OUT

Protected OPTION2

  • see

    OPTION1

    Type parameters

    • OUT

    Parameters

    Returns OUT

Protected OPTION3

  • see

    OPTION1

    Type parameters

    • OUT

    Parameters

    Returns OUT

Protected OPTION4

  • see

    OPTION1

    Type parameters

    • OUT

    Parameters

    Returns OUT

Protected OPTION5

  • see

    OPTION1

    Type parameters

    • OUT

    Parameters

    Returns OUT

Protected OPTION6

  • see

    OPTION1

    Type parameters

    • OUT

    Parameters

    Returns OUT

Protected OPTION7

  • see

    OPTION1

    Type parameters

    • OUT

    Parameters

    Returns OUT

Protected OPTION8

  • see

    OPTION1

    Type parameters

    • OUT

    Parameters

    Returns OUT

Protected OPTION9

  • see

    OPTION1

    Type parameters

    • OUT

    Parameters

    Returns OUT

Protected OR

  • Convenience method equivalent to OR1.

    see

    OR1

    Type parameters

    • T

    Parameters

    Returns T

Protected OR1

  • Parsing DSL method that indicates a choice between a set of alternatives must be made. This is equivalent to EBNF alternation (A | B | C | D ...)

    There are a couple of syntax 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: IAnyOrAlt<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.

Protected OR2

  • see

    OR1

    Type parameters

    • T

    Parameters

    Returns T

Protected OR3

  • see

    OR1

    Type parameters

    • T

    Parameters

    Returns T

Protected OR4

  • see

    OR1

    Type parameters

    • T

    Parameters

    Returns T

Protected OR5

  • see

    OR1

    Type parameters

    • T

    Parameters

    Returns T

Protected OR6

  • see

    OR1

    Type parameters

    • T

    Parameters

    Returns T

Protected OR7

  • see

    OR1

    Type parameters

    • T

    Parameters

    Returns T

Protected OR8

  • see

    OR1

    Type parameters

    • T

    Parameters

    Returns T

Protected OR9

  • see

    OR1

    Type parameters

    • T

    Parameters

    Returns T

Protected OVERRIDE_RULE

  • OVERRIDE_RULE<T>(name: string, impl: function, config?: IRuleConfig<T>): function
  • see

    RULE Same as RULE, but should only be used in "extending" grammars to override rules/productions from the super grammar.

    Type parameters

    • T

    Parameters

    • name: string
    • impl: function
        • (...implArgs: any[]): T
        • Parameters

          • Rest ...implArgs: any[]

          Returns T

    • Optional config: IRuleConfig<T>

    Returns function

      • (idxInCallingRule?: number, ...args: any[]): T
      • Parameters

        • Optional idxInCallingRule: number
        • Rest ...args: any[]

        Returns T

Protected RULE

  • RULE<T>(name: string, implementation: function, config?: IRuleConfig<T>): function
  • Type parameters

    • T

    Parameters

    • name: string

      The name of the rule.

    • implementation: function

      The implementation of the rule.

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

          • Rest ...implArgs: any[]

          Returns T

    • Optional config: IRuleConfig<T>

    Returns function

    • The parsing rule which is the production implementation wrapped with the parsing logic that handles
                    Parser state / error recovery&reporting/ ...
      
      • (idxInCallingRule?: number, ...args: any[]): T | any
      • Parameters

        • Optional idxInCallingRule: number
        • Rest ...args: any[]

        Returns T | any

Protected SAVE_ERROR

Protected SKIP_TOKEN

  • Returns IToken

Protected SUBRULE

  • SUBRULE<T>(ruleToCall: function, args?: any[]): T
  • Convenience method equivalent to SUBRULE1

    see

    SUBRULE1

    Type parameters

    • T

    Parameters

    • ruleToCall: function
        • (idx: number): T
        • Parameters

          • idx: number

          Returns T

    • Optional args: any[]

    Returns T

Protected SUBRULE1

  • SUBRULE1<T>(ruleToCall: function, args?: any[]): T
  • The Parsing DSL Method is used by one rule to call another.

    This may seem redundant as it does not actually do much. However using it is mandatory for all sub rule invocations. calling another rule without wrapping in SUBRULE(...) will cause errors/mistakes in the Recognizer's self analysis, which will lead to errors in error recovery/automatic lookahead calculation and any other functionality relying on the Recognizer's self analysis output.

    As in CONSUME the index in the method name indicates the occurrence of the sub rule invocation in its rule.

    Type parameters

    • T

    Parameters

    • ruleToCall: function

      The rule to invoke.

        • (idx: number): T
        • Parameters

          • idx: number

          Returns T

    • Optional args: any[]

      The arguments to pass to the invoked subrule.

    Returns T

    • The result of invoking ruleToCall.

Protected SUBRULE2

  • SUBRULE2<T>(ruleToCall: function, args?: any[]): T
  • see

    SUBRULE1

    Type parameters

    • T

    Parameters

    • ruleToCall: function
        • (idx: number): T
        • Parameters

          • idx: number

          Returns T

    • Optional args: any[]

    Returns T

Protected SUBRULE3

  • SUBRULE3<T>(ruleToCall: function, args?: any[]): T
  • see

    SUBRULE1

    Type parameters

    • T

    Parameters

    • ruleToCall: function
        • (idx: number): T
        • Parameters

          • idx: number

          Returns T

    • Optional args: any[]

    Returns T

Protected SUBRULE4

  • SUBRULE4<T>(ruleToCall: function, args?: any[]): T
  • see

    SUBRULE1

    Type parameters

    • T

    Parameters

    • ruleToCall: function
        • (idx: number): T
        • Parameters

          • idx: number

          Returns T

    • Optional args: any[]

    Returns T

Protected SUBRULE5

  • SUBRULE5<T>(ruleToCall: function, args?: any[]): T
  • see

    SUBRULE1

    Type parameters

    • T

    Parameters

    • ruleToCall: function
        • (idx: number): T
        • Parameters

          • idx: number

          Returns T

    • Optional args: any[]

    Returns T

Protected SUBRULE6

  • SUBRULE6<T>(ruleToCall: function, args?: any[]): T
  • see

    SUBRULE1

    Type parameters

    • T

    Parameters

    • ruleToCall: function
        • (idx: number): T
        • Parameters

          • idx: number

          Returns T

    • Optional args: any[]

    Returns T

Protected SUBRULE7

  • SUBRULE7<T>(ruleToCall: function, args?: any[]): T
  • see

    SUBRULE1

    Type parameters

    • T

    Parameters

    • ruleToCall: function
        • (idx: number): T
        • Parameters

          • idx: number

          Returns T

    • Optional args: any[]

    Returns T

Protected SUBRULE8

  • SUBRULE8<T>(ruleToCall: function, args?: any[]): T
  • see

    SUBRULE1

    Type parameters

    • T

    Parameters

    • ruleToCall: function
        • (idx: number): T
        • Parameters

          • idx: number

          Returns T

    • Optional args: any[]

    Returns T

Protected SUBRULE9

  • SUBRULE9<T>(ruleToCall: function, args?: any[]): T
  • see

    SUBRULE1

    Type parameters

    • T

    Parameters

    • ruleToCall: function
        • (idx: number): T
        • Parameters

          • idx: number

          Returns T

    • Optional args: any[]

    Returns T

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

  • Parameters

    • startRuleName: string
    • precedingInput: IToken[]

      The token vector up to (not including) the content assist point

    Returns ISyntacticContentAssistPath[]

Protected consumeInternal

  • Parameters

    • tokType: TokenType

      The Type of Token we wish to consume (Reference to its constructor function).

    • idx: number

      Occurrence index of consumed token in the invoking parser rule text for example: IDENT (DOT IDENT)* the first ident will have idx 1 and the second one idx 2

          * note that for the second ident the idx is always 2 even if its invoked 30 times in the same rule
            the idx is about the position in grammar (source code) and has nothing to do with a specific invocation
            details.
      
    • options: ConsumeMethodOpts

      -

    Returns IToken

    • The consumed Token.

Protected consumeToken

  • consumeToken(): void
  • Returns void

Protected exportLexerState

  • exportLexerState(): number
  • Returns number

getBaseCstVisitorConstructor

  • getBaseCstVisitorConstructor(): object
  • Returns object

    • constructor: function
      • Parameters

        • Rest ...args: any[]

        Returns ICstVisitor<any, any>

getBaseCstVisitorConstructorWithDefaults

  • getBaseCstVisitorConstructorWithDefaults(): object
  • Returns object

    • constructor: function
      • Parameters

        • Rest ...args: any[]

        Returns ICstVisitor<any, any>

Protected getCurrRuleFullName

  • getCurrRuleFullName(): string
  • Returns string

Protected getCurrentGrammarPath

getGAstProductions

Protected getHumanReadableRuleStack

  • getHumanReadableRuleStack(): string[]
  • Returns string[]

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

isAtEndOfInput

  • isAtEndOfInput(): boolean
  • Returns boolean

Protected isBackTracking

  • isBackTracking(): boolean
  • Returns boolean

Protected lookAheadBuilderForAlternatives

  • lookAheadBuilderForAlternatives(alts: lookAheadSequence[], hasPredicates: boolean, tokenMatcher: TokenMatcher, dynamicTokensEnabled: boolean): function
  • Parameters

    Returns function

      • (orAlts?: IAnyOrAlt<any>[]): number | undefined
      • Parameters

        Returns number | undefined

Protected lookAheadBuilderForOptional

  • Parameters

    Returns function

      • (): boolean
      • Returns boolean

Protected moveToTerminatedState

  • moveToTerminatedState(): void
  • Returns void

Protected nestedRuleFinallyStateUpdate

  • nestedRuleFinallyStateUpdate(): void
  • Returns void

Protected nestedRuleInvocationStateUpdate

  • nestedRuleInvocationStateUpdate(nestedRuleName: string, shortNameKey: number): void
  • Parameters

    • nestedRuleName: string
    • shortNameKey: number

    Returns 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

Protected resetLexerState

  • resetLexerState(): void
  • Returns void

Protected ruleFinallyStateUpdate

  • ruleFinallyStateUpdate(): void
  • Returns void

Protected ruleInvocationStateUpdate

  • ruleInvocationStateUpdate(shortName: string, fullName: string, idxInCallingRule: number): void
  • Parameters

    • shortName: string
    • fullName: string
    • idxInCallingRule: number

    Returns void

Protected shortRuleNameToFullName

  • shortRuleNameToFullName(shortName: string): string
  • Parameters

    • shortName: string

    Returns string

Protected subruleInternal

  • subruleInternal<T>(ruleToCall: function, idx: number, args: any[]): any
  • Type parameters

    • T

    Parameters

    • ruleToCall: function
        • (idx: number): T
        • Parameters

          • idx: number

          Returns T

    • idx: number
    • args: any[]

    Returns any

Static Protected performSelfAnalysis

  • performSelfAnalysis(parserInstance: Parser): void
  • Parameters

    Returns void

Generated using TypeDoc