antlr-ng
Version:
Next generation ANTLR Tool
62 lines (61 loc) • 3.06 kB
TypeScript
import { type RecognitionException } from "antlr4ng";
import type { GrammarAST } from "../tool/ast/GrammarAST.js";
import type { ErrorManager } from "../tool/ErrorManager.js";
import { CommonTreeNodeStream } from "./CommonTreeNodeStream.js";
/**
* A parser for a stream of tree nodes. Tree walkers result in a subclass of this. All the error reporting
* and recovery is shared with Parser via the BaseRecognizer superclass.
*/
export declare class TreeParser {
protected input: CommonTreeNodeStream;
protected errorManager: ErrorManager;
/**
* This is true when we see an error and before having successfully matched a token. Prevents generation of more
* than one error message per error.
*/
protected errorRecovery: boolean;
/**
* In lieu of a return value, this indicates that a rule or token has failed to match. Reset to false upon valid
* token match.
*/
protected failed: boolean;
/** If 0, no backtracking is going on. Safe to exec actions etc... If > 0 then it's the level of backtracking. */
protected backtracking: number;
constructor(errorManager: ErrorManager, input?: CommonTreeNodeStream);
private static getAncestor;
/**
* Match '.' in tree parser has special meaning. Skip node or entire tree if node has children. If children,
* scan until corresponding UP node.
*/
matchAny(): void;
/**
* Check if current node in input has a context. Context means sequence of nodes towards root of tree. For
* example, you might say context is "MULT" which means my parent must be MULT. "CLASS VARDEF" says current node
* must be child of a VARDEF and whose parent is a CLASS node. You can use "..." to mean zero-or-more nodes.
* "METHOD ... VARDEF" means my parent is VARDEF and somewhere above that is a METHOD node. The first node in t
* he context is not necessarily the root. The context matcher stops matching and returns true when it runs out
* of context. There is no way to force the first node to be the root.
*/
inContext(nodes: number[]): boolean;
/**
* Match current input symbol against ttype. Attempt single token insertion or deletion error recovery. If
* that fails, throw MismatchedTokenException.
*/
match<T extends GrammarAST = GrammarAST>(input: CommonTreeNodeStream, ttype: number): T | null;
/**
* Report a recognition problem.
*
* This method sets errorRecovery to indicate the parser is recovering not parsing. Once in recovery mode,
* no errors are generated. To get out of recovery mode, the parser must successfully match
* a token (after a resync). So it will go:
*
* 1. error occurs
* 2. enter recovery mode, report error
* 3. consume until token found in resynch set
* 4. try to resume parsing
* 5. next match() will reset errorRecovery mode
*
* If you override, make sure to update syntaxErrors if you care about that.
*/
reportError(e: RecognitionException): void;
}