UNPKG

antlr-ng

Version:

Next generation ANTLR Tool

73 lines (72 loc) 1.79 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); import { CharStream } from "antlr4ng"; import { ActionSplitter } from "../generated/ActionSplitter.js"; class ActionSniffer { static { __name(this, "ActionSniffer"); } g; r; alt; node; /** Token within action. */ actionToken; constructor(g, r, alt, node, actionToken) { this.g = g; this.r = r; this.alt = alt; this.node = node; this.actionToken = actionToken; } examineAction() { const input = CharStream.fromString(this.actionToken.text); const splitter = new ActionSplitter(input); this.node.chunks = splitter.getActionTokens(this, this.actionToken); } processNested(actionToken) { const input = CharStream.fromString(actionToken); const splitter = new ActionSplitter(input); splitter.getActionTokens(this, this.actionToken); } attr(expr, x) { this.trackRef(x.text); } qualifiedAttr(expr, x, y) { this.trackRef(x.text); } setAttr(expr, x, rhs) { this.trackRef(x.text); this.processNested(rhs.text); } setNonLocalAttr(expr, x, y, rhs) { this.processNested(rhs); } nonLocalAttr() { } text() { } trackRef(x) { const xRefs = this.alt.tokenRefs.get(x); if (xRefs) { const list = this.alt.tokenRefsInActions.get(x); if (!list) { this.alt.tokenRefsInActions.set(x, [this.node]); } else { list.push(this.node); } } const rRefs = this.alt.ruleRefs.get(x); if (rRefs) { const list = this.alt.ruleRefsInActions.get(x); if (!list) { this.alt.ruleRefsInActions.set(x, [this.node]); } else { list.push(this.node); } } } } export { ActionSniffer };