Options
All
  • Public
  • Public/Protected
  • All
Menu

@chevrotain/types

Index

Type aliases

CstChildrenDictionary: {}

Type declaration

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

Type declaration

CustomPatternMatcherReturn: [string] & { payload?: any }
GenerateDtsOptions: { includeVisitorInterface?: boolean; visitorInterfaceName?: string }

Type declaration

  • Optional includeVisitorInterface?: boolean

    true by default. Disable this to prevent the generation of the CSTVisitor interface. For example, if a different traversal method on the CST has been implemented by the end-user and the Chevrotain CST Visitor apis are not used.

  • Optional visitorInterfaceName?: string

    The generated visitor interface will be called ICstNodeVisitor by default This parameter enables giving it a more specific name, for example: MyCstVisitor or JohnDoe

GrammarAction<OUT>: () => OUT

Type parameters

  • OUT

Type declaration

    • (): OUT
    • Returns OUT

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

Type parameters

  • OUT

Type declaration

  • separators: IToken[]
  • values: OUT[]
MultiModesDefinition: {}

Type declaration

ParserMethod<ARGS, R>: (...args: ARGS) => R

Type parameters

  • ARGS: unknown[]

  • R

Type declaration

    • (...args: ARGS): R
    • Parameters

      • Rest ...args: ARGS

      Returns R

TokenPattern: RegExp | string | CustomPatternMatcherFunc | ICustomPattern
TokenTypeDictionary: {}

Type declaration

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

Variables

Type of End Of File Token.

VERSION: string
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: 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(): () => undefined
  • 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")},
      ])

    Returns () => undefined

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

  • Type parameters

    • T

    Parameters

    • value: T

    Returns () => T

      • (): T
      • Returns T

  • clearCache(): void
  • deprecated

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

    Returns void

  • 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(error: Error): boolean
  • A utility to detect if an Error is a Chevrotain Parser's runtime exception.

    Parameters

    • error: Error

    Returns boolean

  • 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[]

  • 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

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

Generated using TypeDoc