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.
The generated visitor interface will be called ICstNodeVisitor
by default
This parameter enables giving it a more specific name, for example: MyCstVisitor
or JohnDoe
Type of End Of File Token.
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.
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.
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:
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"
}},
])
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")},
])
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:
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"
}},
])
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")},
])
Will generate an html source code (text). This html text will render syntax diagrams for the provided grammar.
Creates a new TokenType which can then be used to define a Lexer and Parser
Utility to create Chevrotain IToken "instances" Note that Chevrotain tokens are not real TokenTypes instances and thus the instanceOf cannot be used with them.
Will generate TypeScript definitions source code (text). For a set of Rule.
This set of Rules can be obtained from a Parser instance via the BaseParser.getGAstProductions method.
Note that this function produces a string the output. It is the responsibility of the end-user to create the signatures files.
fs.writeFileSync()
See: https://chevrotain.io/docs/guide/concrete_syntax_tree.html##cst-typescript-signatures
A utility to detect if an Error is a Chevrotain Parser's runtime exception.
Serialize a Grammar to a JSON Object.
This can be useful for scenarios requiring exporting the grammar structure for example drawing syntax diagrams.
Like serializeGrammar but for a single GAST Production instead of a set of Rules.
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.
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) { /* ... *\/ }
true iff the token matches the TokenType.
Generated using TypeDoc
API #1 Custom Token Patterns.