UNPKG

antlr-ng

Version:

Next generation ANTLR Tool

34 lines (33 loc) 1.69 kB
import { CommonTree } from "./CommonTree.js"; /** * Build and navigate trees with this object. Must know about the names of tokens so you have to pass in a map or * array of token names (from which this class can build the map). I.e., Token DECL means nothing unless the * class can translate it to a token type. * * This class can build a token type -> node index for repeated use or for iterating over the various nodes with * a particular type. */ export declare class TreeWizard { private tokenNameToTypeMap?; constructor(tokenNames: Array<string | null>); /** * Given a pattern like (ASSIGN %lhs:ID %rhs:.) with optional labels on the various nodes and '.' (dot) as * the node/subtree wildcard, returns true if the pattern matches and fill the labels Map with the labels pointing * at the appropriate nodes. Returns false if the pattern is malformed or the tree does not match. * * If a node specifies a text arg in pattern, then that must match for that node in t. */ parse<T extends CommonTree>(t: T, pattern: string, labels?: Map<string, T>): boolean; /** Using the map of token names to token types, returns the type. */ getTokenType(tokenName: string): number; /** * Computes a map that is an inverted index of tokenNames (which maps int token types to names). */ private computeTokenTypes; /** * Does the work for parse. Check to see if the t2 pattern fits the structure and token types in t1. Check text * if the pattern has text arguments on nodes. Fill labels map with pointers to nodes in tree matched against * nodes in pattern with labels. */ private doParse; }