CstElement
export declare type CstElement = IToken | CstNode
IToken
/** * Things to note: * - The offset range is inclusive to exclusive. * * - A lineTerminator as the last character does not effect the Token's line numbering. * In other words a new line only starts **after** a line terminator. * * - A Token's image is it's **literal** text. * e.g unicode escaping is untouched. */ export interface IToken { /** The textual representation of the Token as it appeared in the text. */ image: string /** Offset of the first character of the Token. 0-indexed. */ startOffset: number /** Line of the first character of the Token. 1-indexed. */ startLine?: number /** * Column of the first character of the Token. 1-indexed. * * For token foo in the following line, startColumn will be 3 and endColumn will be 5. * ``` * a foo * 123456 * ``` */ startColumn?: number /** * Offset of the last character of the Token. 0-indexed. * Note that this points at the last character, not the end of the token, so the original image would be * `input.substring(token.startOffset, token.endOffset + 1)`. */ endOffset?: number /** Line of the last character of the Token. 1-indexed. Will be the same as startLine for single-line tokens.*/ endLine?: number /** Column of the last character of the Token. 1-indexed. See also startColumn. */ endColumn?: number /** this marks if a Token does not really exist and has been inserted "artificially" during parsing in rule error recovery. */ isInsertedInRecovery?: boolean /** An number index representing the type of the Token use <getTokenConstructor> to get the Token Type from a token "instance" */ tokenTypeIdx: number /** * The actual Token Type of this Token "instance" * This is the same Object returned by the "createToken" API. * This property is very useful for debugging the Lexing and Parsing phases. */ tokenType: TokenType /** * Custom Payload value, this is an optional feature of Custom Token Patterns * For additional details see the docs: * https://chevrotain.io/docs/guide/custom_token_patterns.html#custom-payloads */ payload?: any }
CstNode
/** * A [Concrete Syntax Tree](http://chevrotain.io/docs/guide/concrete_syntax_tree.html) Node. * This structure represents the whole parse tree of the grammar * This means that information on each and every Token is present. * This is unlike an AST (Abstract Syntax Tree) where some of the syntactic information is missing. * * For example given an ECMAScript grammar, an AST would normally not contain information on the location * of Commas, Semi colons, redundant parenthesis ect, however a CST would have that information. */ export interface CstNode { readonly name: string readonly children: CstChildrenDictionary /** * A flag indicating the whole CSTNode has been recovered during **re-sync** error recovery. * This means that some of the node's children may be missing. * - Note that single token insertion/deletion recovery would not activate this flag. * This flag would only be activated in **re-sync** recovery when the rule's * grammar cannot be fully parsed. * - See: https://chevrotain.io/docs/tutorial/step4_fault_tolerance.html * for more info on error recovery and fault tolerance. */ readonly recoveredNode?: boolean /** * Will only be present if the {@link IParserConfig.nodeLocationTracking} is * **not** set to "none". * See: http://chevrotain.io/docs/guide/concrete_syntax_tree.html#cstnode-location * For more details. */ readonly location?: CstNodeLocation }