UNPKG

antlr-ng

Version:

Next generation ANTLR Tool

41 lines (40 loc) 1.45 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); import { ANTLRv4Parser } from "../../generated/ANTLRv4Parser.js"; import { RuleFunction } from "./RuleFunction.js"; import { RuleContextDecl } from "./decl/RuleContextDecl.js"; import { RuleContextListDecl } from "./decl/RuleContextListDecl.js"; class LeftRecursiveRuleFunction extends RuleFunction { static { __name(this, "LeftRecursiveRuleFunction"); } constructor(factory, r) { super(factory, r); const gen = factory.getGenerator(); for (const [idAST, altLabel] of r.leftRecursiveRuleRefLabels) { const label = idAST.getText(); const ruleRefAST = idAST.parent.children[1]; if (ruleRefAST.getType() === ANTLRv4Parser.RULE_REF) { const targetRule = factory.g.getRule(ruleRefAST.getText()); const ctxName = gen.target.getRuleFunctionContextStructName(targetRule); let d; if (idAST.parent.getType() === ANTLRv4Parser.ASSIGN) { d = new RuleContextDecl(factory, label, ctxName); } else { d = new RuleContextListDecl(factory, label, ctxName); } let struct = this.ruleCtx; if (this.altLabelCtxs) { const s = this.altLabelCtxs.get(altLabel); if (s) { struct = s; } } struct.addDecl(d); } } } } export { LeftRecursiveRuleFunction };