antlr-ng
Version:
Next generation ANTLR Tool
56 lines (55 loc) • 2.56 kB
TypeScript
import { type TokenStream } from "antlr4ng";
import { type STGroup } from "stringtemplate4ts";
import { Tool } from "../Tool.js";
import { type SupportedLanguage } from "../codegen/CodeGenerator.js";
import { AltAST } from "../tool/ast/AltAST.js";
import { GrammarAST } from "../tool/ast/GrammarAST.js";
import { LeftRecursiveRuleWalker } from "../tree/walkers/LeftRecursiveRuleWalker.js";
import { ILeftRecursiveRuleAltInfo } from "./ILeftRecursiveRuleAltInfo.js";
declare enum Associativity {
Left = "left",
Right = "right"
}
/**
* Using a tree walker on the rules, determine if a rule is directly left-recursive and if it follows
* our pattern.
*/
export declare class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker {
private static readonly templateGroupFile;
private static readonly recRuleTemplates;
tool: Tool;
binaryAlts: Map<number, ILeftRecursiveRuleAltInfo>;
ternaryAlts: Map<number, ILeftRecursiveRuleAltInfo>;
suffixAlts: Map<number, ILeftRecursiveRuleAltInfo>;
prefixAndOtherAlts: ILeftRecursiveRuleAltInfo[];
/** Pointer to ID node of ^(= ID element) */
leftRecursiveRuleRefLabels: [GrammarAST, string | undefined][];
/** Tokens from which rule AST comes from */
readonly tokenStream: TokenStream;
retvals: GrammarAST;
readonly codegenTemplates: STGroup;
readonly language: string;
altAssociativity: Map<number, Associativity>;
constructor(ruleAST: GrammarAST, tool: Tool, ruleName: string, language: SupportedLanguage);
/**
* Match (RULE RULE_REF (BLOCK (ALT .*) (ALT RULE_REF[self] .*) (ALT .*)))
* Match (RULE RULE_REF (BLOCK (ALT .*) (ALT (ASSIGN ID RULE_REF[self]) .*) (ALT .*)))
*/
static hasImmediateRecursiveRuleRefs(t: GrammarAST, ruleName: string): boolean;
setReturnValues(t: GrammarAST): void;
setAltAssoc(t: AltAST, alt: number): void;
binaryAlt(originalAltTree: AltAST, altNum: number): void;
prefixAlt(originalAltTree: AltAST, altNum: number): void;
suffixAlt(originalAltTree: AltAST, altNum: number): void;
otherAlt(originalAltTree: AltAST, altNum: number): void;
getArtificialOpPrecRule(): string;
addPrecedenceArgToRules(t: AltAST, prec: number): AltAST;
stripLeftRecursion(altAST: GrammarAST): GrammarAST | undefined;
/** Strip last 2 tokens if → label; alter indexes in altAST */
stripAltLabel(altAST: GrammarAST): void;
text(t: GrammarAST): string;
precedence(alt: number): number;
nextPrecedence(alt: number): number;
toString(): string;
}
export {};