antlr-ng
Version:
Next generation ANTLR Tool
87 lines (86 loc) • 2.17 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
import { Utils } from "../../misc/Utils.js";
import { GrammarASTWithOptions } from "./GrammarASTWithOptions.js";
class GrammarRootAST extends GrammarASTWithOptions {
static {
__name(this, "GrammarRootAST");
}
grammarType;
hasErrors = false;
// TODO: This is not set anywhere.
/** Track stream used to create this tree */
tokenStream;
fileName;
toolParameters;
constructor(...args) {
switch (args.length) {
case 1: {
const [node] = args;
super(node);
this.grammarType = node.grammarType;
this.hasErrors = node.hasErrors;
this.tokenStream = node.tokenStream;
break;
}
case 2: {
const [t, tokenStream] = args;
super(t);
if (!tokenStream) {
throw new Error("tokenStream");
}
this.tokenStream = tokenStream;
break;
}
case 3: {
const [type, t, tokenStream] = args;
super(type, t);
if (!tokenStream) {
throw new Error("tokenStream");
}
this.tokenStream = tokenStream;
break;
}
case 4: {
const [type, t, text, tokenStream] = args;
super(type, t, text);
if (!tokenStream) {
throw new Error("tokenStream");
}
this.tokenStream = tokenStream;
break;
}
default: {
throw new Error("Invalid number of arguments");
}
}
}
getGrammarName() {
const t = this.children[0];
return t.getText();
}
getOptionString(key) {
if (this.toolParameters) {
if (Utils.hasKey(this.toolParameters, key)) {
const value = this.toolParameters[key];
if (typeof value === "string") {
return value;
}
}
const define = this.toolParameters.define?.[key];
if (define !== void 0) {
return define;
}
}
return super.getOptionString(key);
}
visit(v) {
return v.visit(this);
}
dupNode() {
return new GrammarRootAST(this);
}
}
export {
GrammarRootAST
};