antlr-ng
Version:
Next generation ANTLR Tool
60 lines (59 loc) • 1.58 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
import { isToken } from "antlr4ng";
import { CharSupport } from "../../misc/CharSupport.js";
import { GrammarAST } from "./GrammarAST.js";
class GrammarASTWithOptions extends GrammarAST {
static {
__name(this, "GrammarASTWithOptions");
}
astType = "GrammarASTWithOptions";
options = /* @__PURE__ */ new Map();
constructor(...args) {
if (isToken(args[0])) {
super(args[0]);
} else if (args[0] instanceof GrammarASTWithOptions) {
super(args[0]);
this.options = args[0].options;
} else {
super(args[0], args[1], args[2]);
}
}
setOption(key, node) {
this.options.set(key, node);
}
getOptionString(key) {
const value = this.getOptionAST(key);
if (value === void 0) {
return value;
}
if (value.astType === "ActionAST") {
return value.getText();
} else {
let v = value.getText();
if (v && (v.startsWith("'") || v.startsWith('"'))) {
v = CharSupport.getStringFromGrammarStringLiteral(v, this.g, { line: 1, column: 0 });
if (v === null) {
v = "";
}
}
return v;
}
}
/**
* Gets AST node holding value for option key; ignores default options
* and command-line forced options.
*/
getOptionAST(key) {
return this.options.get(key) ?? void 0;
}
getNumberOfOptions() {
return this.options.size;
}
getOptions() {
return this.options;
}
}
export {
GrammarASTWithOptions
};