antlr-ng
Version:
Next generation ANTLR Tool
46 lines (45 loc) • 1.43 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
import { IntStream } from "antlr4ng";
import { Character } from "./support/Character.js";
import { IssueCode } from "./tool/Issues.js";
import { GrammarTreeVisitor } from "./tree/walkers/GrammarTreeVisitor.js";
class UndefChecker extends GrammarTreeVisitor {
constructor(isLexer, ruleToAST, errorManager) {
super(errorManager);
this.isLexer = isLexer;
this.ruleToAST = ruleToAST;
}
static {
__name(this, "UndefChecker");
}
badRef = false;
tokenRef(ref) {
if (ref.getText() === "EOF") {
return;
}
if (this.isLexer) {
this.ruleRef(ref, null);
}
}
ruleRef(ref, arg) {
const ruleAST = this.ruleToAST.get(ref.getText());
const fileName = ref.token?.inputStream?.getSourceName() ?? IntStream.UNKNOWN_SOURCE_NAME;
if (Character.isUpperCase(this.currentRuleName.codePointAt(0)) && Character.isLowerCase(ref.getText().codePointAt(0))) {
this.badRef = true;
this.errorManager.grammarError(
IssueCode.ParserRuleRefInLexerRule,
fileName,
ref.token,
ref.getText(),
this.currentRuleName
);
} else if (!ruleAST) {
this.badRef = true;
this.errorManager.grammarError(IssueCode.UndefinedRuleRef, fileName, ref.token, ref.getText());
}
}
}
export {
UndefChecker
};