antlr-ng
Version:
Next generation ANTLR Tool
52 lines (51 loc) • 2.4 kB
TypeScript
import type { IAlternative } from "../types.js";
import type { IAttribute } from "./IAttribute.js";
import { IAttributeResolver } from "./IAttributeResolver.js";
import { LabelElementPair } from "./LabelElementPair.js";
import { Rule } from "./Rule.js";
import { ActionAST } from "./ast/ActionAST.js";
import { AltAST } from "./ast/AltAST.js";
import { GrammarAST } from "./ast/GrammarAST.js";
import { TerminalAST } from "./ast/TerminalAST.js";
/** An outermost alternative for a rule. We don't track inner alternatives. */
export declare class Alternative implements IAttributeResolver, IAlternative {
ast: AltAST;
/** Token IDs, string literals in this alt. */
readonly tokenRefs: Map<string, TerminalAST[]>;
/** Does not include labels. */
readonly tokenRefsInActions: Map<string, GrammarAST[]>;
/** All rule refs in this alt. */
readonly ruleRefs: Map<string, GrammarAST[]>;
readonly ruleRefsInActions: Map<string, GrammarAST[]>;
/** A list of all LabelElementPair attached to tokens like id=ID, ids+=ID */
readonly labelDefs: Map<string, LabelElementPair[]>;
/**
* Track all executable actions other than named actions like @init
* and catch/finally (not in an alt). Also tracks predicates, rewrite actions.
* We need to examine these actions before code generation so
* that we can detect refs to $rule.attr etc...
*
* This tracks per alt
*/
actions: ActionAST[];
/** What alternative number is this outermost alt? Used in templates. */
altNum: number;
private rule;
constructor(r: Rule, altNum: number);
resolvesToToken(x: string, node: ActionAST): boolean;
resolvesToAttributeDict(x: string, node: ActionAST): boolean;
/**
$x Attribute: rule arguments, return values, predefined rule prop.
*/
resolveToAttribute(x: string, node: ActionAST): IAttribute | null;
/**
* $x.y, x can be surrounding rule, token/rule/label ref. y is visible
* attr in that dictionary. Can't see args on rule refs.
*/
resolveToAttribute(x: string, y: string, node: ActionAST): IAttribute | null;
resolvesToLabel(x: string, node: ActionAST): boolean;
resolvesToListLabel(x: string, node: ActionAST): boolean;
getAnyLabelDef(x: string): LabelElementPair | null;
/** x can be rule ref or rule label. */
resolveToRule(x: string): Rule | null;
}