antlr-ng
Version:
Next generation ANTLR Tool
55 lines (54 loc) • 2.12 kB
TypeScript
import { GrammarAST } from "../../tool/ast/GrammarAST.js";
import type { ErrorManager } from "../../tool/ErrorManager.js";
import { Grammar } from "../../tool/Grammar.js";
import type { CommonTreeNodeStream } from "../CommonTreeNodeStream.js";
import { TreeRewriter } from "../TreeRewriter.js";
export declare class BlockSetTransformer extends TreeRewriter {
private currentRuleName?;
private g;
constructor(errorManager: ErrorManager, input: CommonTreeNodeStream, grammar: Grammar);
/**
* Transforms ^(nil x) to x and nil to null.
*
* @param root The root node to process.
*
* @returns The processed root node.
*/
private static rulePostProcessing;
/**
* If oldRoot is a nil root, just copy or move the children to newRoot. If not a nil root, make oldRoot a child
* of newRoot.
* ```
* old=^(nil a b c), new=r yields ^(r a b c)
* old=^(a b c), new=r yields ^(r ^(a b c))
* ```
* If newRoot is a nil-rooted single child tree, use the single child as the new root node.
* ```
* old=^(nil a b c), new=^(nil r) yields ^(r a b c)
* old=^(a b c), new=^(nil r) yields ^(r ^(a b c))
* ```
* If oldRoot was null, it's ok, just return newRoot (even if isNil).
* ```
* old=null, new=r yields r
* old=null, new=^(nil r) yields ^(nil r)
* ```
*
* @param newRoot The new root node.
* @param oldRoot The old root node.
*
* @returns newRoot. Throw an error if newRoot is not a simple node or nil root with a single child node. It must
* be a root node. If newRoot is ^(nil x) return x as newRoot.
*
* Be advised that it's ok for newRoot to point at oldRoot's children, i.e. you don't have to copy the list. We are
* constructing these nodes so we should have this control for efficiency.
*/
private static becomeRoot;
topdown: () => GrammarAST | undefined;
private setAlt;
private ebnfBlockSet;
private ebnfSuffix;
private blockSet;
private setElement;
private elementOptions;
private elementOption;
}