Options
All
  • Public
  • Public/Protected
  • All
Menu

@chevrotain/types

Index

Type aliases

CstChildrenDictionary

CstChildrenDictionary: {}

Type declaration

CstElement

CstElement: IToken | CstNode

CustomPatternMatcherFunc

CustomPatternMatcherFunc: (text: string, offset: number, tokens: IToken[], groups: {}) => CustomPatternMatcherReturn | RegExpExecArray | null

Type declaration

CustomPatternMatcherReturn

CustomPatternMatcherReturn: [string] & { payload?: any }

GrammarAction

GrammarAction<OUT>: () => OUT

Type parameters

  • OUT

Type declaration

    • (): OUT
    • Returns OUT

ISeparatedIterationResult

ISeparatedIterationResult<OUT>: { separators: IToken[]; values: OUT[] }

Type parameters

  • OUT

Type declaration

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

MultiModesDefinition

MultiModesDefinition: {}

Type declaration

TokenPattern

TokenPattern: RegExp | string | CustomPatternMatcherFunc | ICustomPattern

TokenTypeDictionary

TokenTypeDictionary: {}

Type declaration

TokenVocabulary

nodeLocationTrackingOptions

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

Variables

EOF

Type of End Of File Token.

VERSION

VERSION: string

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.

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): () => T
  • 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 () => T

      • (): T
      • 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")},
          ])

        Returns T

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

isRecognitionException

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

    Parameters

    • error: Error

    Returns boolean

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

Generated using TypeDoc