Options
All
  • Public
  • Public/Protected
  • All
Menu

chevrotain

Index

Enumerations

Classes

Interfaces

Type aliases

Variables

Functions

Type aliases

CstChildrenDictionary

CstChildrenDictionary: object

Type declaration

CstElement

CstElement: IToken | CstNode

CustomPatternMatcherFunc

CustomPatternMatcherFunc: function

Type declaration

CustomPatternMatcherReturn

CustomPatternMatcherReturn: [string] & object

GrammarAction

GrammarAction: function

Type declaration

    • (): OUT
    • Returns OUT

IAnyOrAlt

IAnyOrAlt: any

TODO: remove this in next major version this IOrAlt is enough

deprecated

ISeparatedIterationResult

ISeparatedIterationResult: object

Type declaration

  • separators: IToken[]
  • values: OUT[]

IgnoredParserIssues

IgnoredParserIssues: object

Type declaration

IgnoredRuleIssues

IgnoredRuleIssues: object

Type declaration

  • [dslNameAndOccurrence: string]: boolean

MultiModesDefinition

MultiModesDefinition: object

Type declaration

TokenPattern

TokenPattern: RegExp | string | CustomPatternMatcherFunc | ICustomPattern

TokenTypeDictionary

TokenTypeDictionary: object

Type declaration

TokenVocabulary

nodeLocationTrackingOptions

nodeLocationTrackingOptions: "full" | "onlyOffset" | "none"

Variables

Const EOF

Type of End Of File Token.

Const VERSION

VERSION: string

Const defaultGrammarResolverErrorProvider

defaultGrammarResolverErrorProvider: IGrammarResolverErrorMessageProvider

The default grammar resolver errror message provider used by Chevrotain. this can be used as the basis for custom error providers when using Chevrotain's custom APIs.

Const defaultGrammarValidatorErrorProvider

defaultGrammarValidatorErrorProvider: IGrammarValidatorErrorMessageProvider

The default grammar validations errror message provider used by Chevrotain. this can be used as the basis for custom error providers when using Chevrotain's custom APIs.

Const defaultLexerErrorProvider

defaultLexerErrorProvider: ILexerErrorMessageProvider

This is the default logic Chevrotain uses to construct lexing error messages. It can be used as a reference or as a starting point customize a lexer's error messages.

Const defaultParserErrorProvider

defaultParserErrorProvider: IParserErrorMessageProvider

This is the default logic Chevrotain uses to construct error messages. It can be used as a reference or as a starting point customize a parser's error messages.

Functions

EMPTY_ALT

  • EMPTY_ALT<T>(value?: T): function
  • Convenience used to express an empty alternative in an OR (alternation). can be used to more clearly describe the intent in a case of empty alternation.

    For example:

    1. without using EMPTY_ALT:

      this.OR([
        {ALT: () => {
          this.CONSUME1(OneTok)
          return "1"
        }},
        {ALT: () => {
          this.CONSUME1(TwoTok)
          return "2"
        }},
        // implicitly empty because there are no invoked grammar
        // rules (OR/MANY/CONSUME...) inside this alternative.
        {ALT: () => {
          return "666"
        }},
      ])
    2. using EMPTY_ALT:

      this.OR([
        {ALT: () => {
          this.CONSUME1(OneTok)
          return "1"
        }},
        {ALT: () => {
          this.CONSUME1(TwoTok)
          return "2"
        }},
        // explicitly empty, clearer intent
        {ALT: EMPTY_ALT("666")},
      ])

    Type parameters

    • T

    Parameters

    • Optional value: T

    Returns function

      • (): T
      • Returns T

assignOccurrenceIndices

  • assignOccurrenceIndices(options: object): void

clearCache

  • clearCache(): void
  • deprecated

    This function no longer does anything, Avoid using this function As it will be removed in future versions.

    Returns void

createSyntaxDiagramsCode

createToken

createTokenInstance

  • createTokenInstance(tokType: TokenType, image: string, startOffset: number, endOffset: number, startLine: number, endLine: number, startColumn: number, endColumn: number): IToken
  • Utility to create Chevrotain IToken "instances" Note that Chevrotain tokens are not real TokenTypes instances and thus the instanceOf cannot be used with them.

    Parameters

    • tokType: TokenType
    • image: string
    • startOffset: number
    • endOffset: number
    • startLine: number
    • endLine: number
    • startColumn: number
    • endColumn: number

    Returns IToken

generateParserFactory

  • generateParserFactory(options: object): function
  • Generate A Parser factory from a set of Rules.

    This variant will Create a factory function that once invoked with a IParserConfig will return a Parser Object.

    • Note that this happens using the Function constructor (a type of "eval") so it will not work in environments where content security policy is enabled, such as certain websites, Chrome extensions ect...

      This means this function is best used for development flows to reduce the feedback loops or for productive flows targeting node.js only.

      For productive flows targeting a browser runtime see generateParserModule.

    • See detailed docs for Custom APIs.

    Parameters

    Returns function

generateParserModule

  • generateParserModule(options: object): string
  • Generate A Parser's text from a set of Rules.

    This variant will generate the string literal for a UMD module https://github.com/umdjs/umd That exports a Parser Constructor.

    • Note that the constructor exposed by the generated module must receive the TokenVocabulary as the first argument, the IParser config can be passed as the second argument.

    • See detailed docs for Custom APIs.

    Parameters

    • options: object
      • name: string
      • rules: Rule[]

    Returns string

isRecognitionException

  • isRecognitionException(error: Error): boolean
  • A utility to detect if an Error is a Chevrotain Parser's runtime exception.

    Parameters

    • error: Error

    Returns boolean

resolveGrammar

serializeGrammar

  • Serialize a Grammar to a JSON Object.

    This can be useful for scenarios requiring exporting the grammar structure for example drawing syntax diagrams.

    Parameters

    Returns ISerializedGast[]

serializeProduction

tokenLabel

  • Returns a human readable label for a TokenType if such exists, otherwise will return the TokenType's name.

    Labels are useful in improving the readability of error messages and syntax diagrams. To define labels provide the label property in the createToken config parameter.

    Parameters

    Returns string

tokenMatcher

  • A Utility method to check if a token is of the type of the argument Token class. This utility is needed because Chevrotain tokens support "categories" which means A TokenType may have multiple categories.

    This means a simple comparison using the IToken.tokenType property may not suffice. For example:

      import { createToken, tokenMatcher, Lexer } from "chevrotain"
    
      // An "abstract" Token used only for categorization purposes.
      const NumberTokType = createToken({ name: "NumberTokType", pattern: Lexer.NA })
    
      const IntegerTokType = createToken({
        name: "IntegerTokType",
        pattern: /\d+/,
        // Integer "Is A" Number
        categories: [NumberTokType]
      })
    
      const DecimalTokType = createToken({
        name: "DecimalTokType",
        pattern: /\d+\.\d+/,
        // Double "Is A" Number
        categories: [NumberTokType]
      })
    
      // Will always be false as the tokenType property can only
      // be Integer or Double Token Types as the Number TokenType is "abstract".
      if (myToken.tokenType === NumberTokType) { /* ... *\/ }
    
      // Will be true when myToken is of Type Integer or Double.
      // Because the hierarchy defined by the categories is taken into account.
      if (tokenMatcher(myToken, NumberTokType) { /* ... *\/ }

    Parameters

    Returns boolean

    true iff the token matches the TokenType.

tokenName

validateGrammar

Generated using TypeDoc