[[cygwin]]

Class Parser
deprecated
Soft deprecated, CstParser or EmbeddedActionsParser instead.

CstParser
EmbeddedActionsParser
Hierarchy
BaseParser
Parser
Index
Constructors
constructor
Properties
errors
input
Methods
AT_LEAST_ONE
AT_LEAST_ONE_SEP
BACKTRACK
CONSUME
LA
MANY
MANY_SEP
OPTION
OR
OVERRIDE_RULE
RULE
SKIP_TOKEN
SUBRULE
canTokenTypeBeInsertedInRecovery
computeContentAssist
getBaseCstVisitorConstructor
getBaseCstVisitorConstructorWithDefaults
getGAstProductions
getNextPossibleTokenTypes
getSerializedGastProductions
getTokenToInsert
performSelfAnalysis
reset
performSelfAnalysis
Constructors
constructor
new Parser(tokenVocabulary: TokenVocabulary, config?: IParserConfig): Parser
Inherited from BaseParser.constructor

Defined in api.d.ts:15
It is recommended to reuse the same Parser instance by passing an empty array to the input argument and only later setting the input by using the input property. See: http://sap.github.io/chevrotain/docs/FAQ.html#major-performance-benefits

Parameters
tokenVocabulary: TokenVocabulary
A data structure containing all the Tokens used by the Parser.

Optional config: IParserConfig
The Parser's configuration.

Returns Parser
Properties
errors
errors: IRecognitionException[]
Inherited from BaseParser.errors

Defined in api.d.ts:28
input
input: IToken[]
Inherited from BaseParser.input

Defined in api.d.ts:806
Methods
AT_LEAST_ONE
AT_LEAST_ONE(actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>): void
Inherited from BaseParser.AT_LEAST_ONE

Defined in api.d.ts:616
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
AT_LEAST_ONE_SEP
AT_LEAST_ONE_SEP(options: AtLeastOneSepMethodOpts<any>): void
Inherited from BaseParser.AT_LEAST_ONE_SEP

Defined in api.d.ts:705
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
BACKTRACK
BACKTRACK<T>(grammarRule: function, args?: any[]): function
Inherited from BaseParser.BACKTRACK

Defined in api.d.ts:63
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
CONSUME
CONSUME(tokType: TokenType, options?: ConsumeMethodOpts): IToken
Inherited from BaseParser.CONSUME

Defined in api.d.ts:99
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 . 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);
    });
  })
See more details on the unique suffixes requirement.
Parameters
tokType: TokenType
The Type of the token to be consumed.

Optional options: ConsumeMethodOpts
optional properties to modify the behavior of CONSUME.

Returns IToken
LA
LA(howMuch: number): IToken
Inherited from BaseParser.LA

Defined in api.d.ts:810
Parameters
howMuch: number
Returns IToken
MANY
MANY(actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>): void
Inherited from BaseParser.MANY

Defined in api.d.ts:442
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
MANY_SEP
MANY_SEP(options: ManySepMethodOpts<any>): void
Inherited from BaseParser.MANY_SEP

Defined in api.d.ts:549
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.

Parameters
options: ManySepMethodOpts<any>
An object defining the grammar of each iteration and the separator between iterations

Returns void
OPTION
OPTION<OUT>(actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>): OUT
Inherited from BaseParser.OPTION

Defined in api.d.ts:216
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 OUT
OR
OR(altsOrOpts: IAnyOrAlt[] | OrMethodOpts): any
Inherited from BaseParser.OR

Defined in api.d.ts:352
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.

Parameters
altsOrOpts: IAnyOrAlt[] | OrMethodOpts
A set of alternatives or an "OPTIONS" object describing the alternatives and optional properties.

Returns any
The result of invoking the chosen alternative.

OVERRIDE_RULE
OVERRIDE_RULE<T>(name: string, impl: function, config?: IRuleConfig<T>): function
Defined in api.d.ts:844
Same as Parser.RULE, but should only be used in "extending" grammars to override rules/productions from the super grammar. See Parser Inheritance Example.

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 | any
Parameters
Optional idxInCallingRule: number
Rest ...args: any[]
Returns T | any
RULE
RULE<T>(name: string, implementation: function, config?: IRuleConfig<T>): function
Defined in api.d.ts:833
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
SKIP_TOKEN
SKIP_TOKEN(): IToken
Inherited from BaseParser.SKIP_TOKEN

Defined in api.d.ts:808
Returns IToken
SUBRULE
SUBRULE<T>(ruleToCall: function, options?: SubruleMethodOpts): T
Defined in api.d.ts:870
The Parsing DSL Method is used by one rule to call another. It is equivalent to a non-Terminal in EBNF notation.

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 Parser's self analysis phase, which will lead to errors in error recovery/automatic lookahead calculation and any other functionality relying on the Parser'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 options: SubruleMethodOpts
optional properties to modify the behavior of SUBRULE.

Returns T
The result of invoking ruleToCall.

canTokenTypeBeInsertedInRecovery
canTokenTypeBeInsertedInRecovery(tokType: TokenType): boolean
Inherited from BaseParser.canTokenTypeBeInsertedInRecovery

Defined in api.d.ts:795
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
tokType: TokenType
Returns boolean
computeContentAssist
computeContentAssist(startRuleName: string, precedingInput: IToken[]): ISyntacticContentAssistPath[]
Inherited from BaseParser.computeContentAssist

Defined in api.d.ts:52
Parameters
startRuleName: string
precedingInput: IToken[]
The token vector up to (not including) the content assist point

Returns ISyntacticContentAssistPath[]
getBaseCstVisitorConstructor
getBaseCstVisitorConstructor(): object
Inherited from BaseParser.getBaseCstVisitorConstructor

Defined in api.d.ts:36
Returns object
constructor: function
new __type(...args: any[]): ICstVisitor<any, any>
Defined in api.d.ts:36
Parameters
Rest ...args: any[]
Returns ICstVisitor<any, any>
getBaseCstVisitorConstructorWithDefaults
getBaseCstVisitorConstructorWithDefaults(): object
Inherited from BaseParser.getBaseCstVisitorConstructorWithDefaults

Defined in api.d.ts:40
Returns object
constructor: function
new __type(...args: any[]): ICstVisitor<any, any>
Defined in api.d.ts:40
Parameters
Rest ...args: any[]
Returns ICstVisitor<any, any>
getGAstProductions
getGAstProductions(): HashTable<Rule>
Inherited from BaseParser.getGAstProductions

Defined in api.d.ts:44
Returns HashTable<Rule>
getNextPossibleTokenTypes
getNextPossibleTokenTypes(grammarPath: ITokenGrammarPath): TokenType[]
Inherited from BaseParser.getNextPossibleTokenTypes

Defined in api.d.ts:802
deprecated
will be removed in the future
Parameters
grammarPath: ITokenGrammarPath
Returns TokenType[]
getSerializedGastProductions
getSerializedGastProductions(): ISerializedGast[]
Inherited from BaseParser.getSerializedGastProductions

Defined in api.d.ts:46
Returns ISerializedGast[]
getTokenToInsert
getTokenToInsert(tokType: TokenType): IToken
Inherited from BaseParser.getTokenToInsert

Defined in api.d.ts:786
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
tokType: TokenType
Returns IToken
performSelfAnalysis
performSelfAnalysis(): void
Inherited from BaseParser.performSelfAnalysis

Defined in api.d.ts:15
This must be called at the end of a Parser constructor. See: http://sap.github.io/chevrotain/docs/tutorial/step2_parsing.html#under-the-hood

Returns void
reset
reset(): void
Inherited from BaseParser.reset

Defined in api.d.ts:34
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
Static performSelfAnalysis
performSelfAnalysis(parserInstance: Parser): void
Defined in api.d.ts:822
deprecated
use Parser.performSelfAnalysis instance method instead.

Parameters
parserInstance: Parser
Returns void
トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS