antlr-ng
Version:
Next generation ANTLR Tool
47 lines (46 loc) • 1.28 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
import { ANTLRv4Parser } from "../../generated/ANTLRv4Parser.js";
import { isTokenName } from "../../support/helpers.js";
import { GrammarASTWithOptions } from "./GrammarASTWithOptions.js";
class RuleAST extends GrammarASTWithOptions {
static {
__name(this, "RuleAST");
}
astType = "RuleAST";
constructor(nodeOrTokenOrType) {
if (typeof nodeOrTokenOrType === "number") {
super(nodeOrTokenOrType);
} else {
super(nodeOrTokenOrType);
}
}
isLexerRule() {
const name = this.getRuleName();
return name !== null && isTokenName(name);
}
getRuleName() {
const nameNode = this.children[0];
return nameNode?.getText() ?? null;
}
dupNode() {
return new RuleAST(this);
}
getLexerAction() {
const blk = this.getFirstChildWithType(ANTLRv4Parser.LPAREN);
if (blk?.children.length === 1) {
const onlyAlt = blk.children[0];
const lastChild = onlyAlt.children[onlyAlt.children.length - 1];
if (lastChild.getType() === ANTLRv4Parser.RBRACE) {
return lastChild;
}
}
return null;
}
visit(v) {
return v.visit(this);
}
}
export {
RuleAST
};