antlr-ng
Version:
Next generation ANTLR Tool
97 lines (96 loc) • 3.55 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
class CodeGenPipeline {
constructor(g, gen, generateListener, generateVisitor) {
this.generateListener = generateListener;
this.generateVisitor = generateVisitor;
this.g = g;
this.gen = gen;
}
static {
__name(this, "CodeGenPipeline");
}
g;
gen;
process(toolParameters) {
const errorCount = this.g.tool.errorManager.errors;
if (this.g.isLexer()) {
if (this.gen.target.needsHeader()) {
const lexer2 = this.gen.generateLexer(toolParameters, true);
if (this.g.tool.errorManager.errors === errorCount) {
this.writeRecognizer(lexer2, this.gen, true);
}
}
const lexer = this.gen.generateLexer(toolParameters, false);
if (this.g.tool.errorManager.errors === errorCount) {
this.writeRecognizer(lexer, this.gen, false);
}
} else {
if (this.gen.target.needsHeader()) {
const parser2 = this.gen.generateParser(toolParameters, true);
if (this.g.tool.errorManager.errors === errorCount) {
this.writeRecognizer(parser2, this.gen, true);
}
}
const parser = this.gen.generateParser(toolParameters, false);
if (this.g.tool.errorManager.errors === errorCount) {
this.writeRecognizer(parser, this.gen, false);
}
if (this.generateListener) {
if (this.gen.target.needsHeader()) {
const listener2 = this.gen.generateListener(true);
if (this.g.tool.errorManager.errors === errorCount) {
this.gen.writeListener(listener2, true);
}
}
const listener = this.gen.generateListener(false);
if (this.g.tool.errorManager.errors === errorCount) {
this.gen.writeListener(listener, false);
}
if (this.gen.target.needsHeader()) {
const baseListener = this.gen.generateBaseListener(true);
if (this.g.tool.errorManager.errors === errorCount) {
this.gen.writeBaseListener(baseListener, true);
}
}
if (this.gen.target.wantsBaseListener()) {
const baseListener = this.gen.generateBaseListener(false);
if (this.g.tool.errorManager.errors === errorCount) {
this.gen.writeBaseListener(baseListener, false);
}
}
}
if (this.generateVisitor) {
if (this.gen.target.needsHeader()) {
const visitor2 = this.gen.generateVisitor(true);
if (this.g.tool.errorManager.errors === errorCount) {
this.gen.writeVisitor(visitor2, true);
}
}
const visitor = this.gen.generateVisitor(false);
if (this.g.tool.errorManager.errors === errorCount) {
this.gen.writeVisitor(visitor, false);
}
if (this.gen.target.needsHeader()) {
const baseVisitor = this.gen.generateBaseVisitor(true);
if (this.g.tool.errorManager.errors === errorCount) {
this.gen.writeBaseVisitor(baseVisitor, true);
}
}
if (this.gen.target.wantsBaseVisitor()) {
const baseVisitor = this.gen.generateBaseVisitor(false);
if (this.g.tool.errorManager.errors === errorCount) {
this.gen.writeBaseVisitor(baseVisitor, false);
}
}
}
}
this.gen.writeVocabFile();
}
writeRecognizer(template, gen, header) {
gen.writeRecognizer(template, header);
}
}
export {
CodeGenPipeline
};