use of org.antlr.v4.codegen.CodeGenerator in project antlr4 by tunnelvisionlabs.
the class OutputModelController method buildLexerOutputModel.
public OutputModelObject buildLexerOutputModel(boolean header) {
CodeGenerator gen = delegate.getGenerator();
LexerFile file = lexerFile(gen.getRecognizerFileName(header));
setRoot(file);
file.lexer = lexer(file);
Grammar g = delegate.getGrammar();
for (Rule r : g.rules.values()) {
buildLexerRuleActions(file.lexer, r);
}
return file;
}
use of org.antlr.v4.codegen.CodeGenerator in project antlr4 by tunnelvisionlabs.
the class TestCodeGeneration method getEvalInfoForString.
public List<String> getEvalInfoForString(String grammarString, String pattern) throws RecognitionException {
ErrorQueue equeue = new ErrorQueue();
Grammar g = new Grammar(grammarString);
List<String> evals = new ArrayList<String>();
if (g.ast != null && !g.ast.hasErrors) {
SemanticPipeline sem = new SemanticPipeline(g);
sem.process();
ATNFactory factory = new ParserATNFactory(g);
if (g.isLexer())
factory = new LexerATNFactory((LexerGrammar) g);
g.atn = factory.createATN();
CodeGenerator gen = new CodeGenerator(g);
ST outputFileST = gen.generateParser();
// STViz viz = outputFileST.inspect();
// try {
// viz.waitForClose();
// }
// catch (Exception e) {
// e.printStackTrace();
// }
boolean debug = false;
DebugInterpreter interp = new DebugInterpreter(outputFileST.groupThatCreatedThisInstance, outputFileST.impl.nativeGroup.errMgr, debug);
InstanceScope scope = new InstanceScope(null, outputFileST);
StringWriter sw = new StringWriter();
AutoIndentWriter out = new AutoIndentWriter(sw);
interp.exec(out, scope);
for (String e : interp.evals) {
if (e.contains(pattern)) {
evals.add(e);
}
}
}
if (equeue.size() > 0) {
System.err.println(equeue.toString());
}
return evals;
}
use of org.antlr.v4.codegen.CodeGenerator in project antlr4 by antlr.
the class GoTarget method getVisitorFileName.
/**
* A given grammar T, return the visitor name such as
* TVisitor.java, if we're using the Java target.
*/
public String getVisitorFileName(boolean header) {
CodeGenerator gen = getCodeGenerator();
Grammar g = gen.g;
assert g.name != null;
return g.name.toLowerCase() + "_visitor.go";
}
use of org.antlr.v4.codegen.CodeGenerator in project antlr4 by antlr.
the class GoTarget method getRecognizerFileName.
public String getRecognizerFileName(boolean header) {
CodeGenerator gen = getCodeGenerator();
Grammar g = gen.g;
assert g != null;
String name;
switch(g.getType()) {
case ANTLRParser.PARSER:
name = g.name.endsWith("Parser") ? g.name.substring(0, g.name.length() - 6) : g.name;
return name.toLowerCase() + "_parser.go";
case ANTLRParser.LEXER:
// trim off "lexer"
name = g.name.endsWith("Lexer") ? g.name.substring(0, g.name.length() - 5) : g.name;
return name.toLowerCase() + "_lexer.go";
case ANTLRParser.COMBINED:
return g.name.toLowerCase() + "_parser.go";
default:
return "INVALID_FILE_NAME";
}
}
use of org.antlr.v4.codegen.CodeGenerator in project antlr4 by antlr.
the class GoTarget method getListenerFileName.
/**
* A given grammar T, return the listener name such as
* TListener.java, if we're using the Java target.
*/
public String getListenerFileName(boolean header) {
CodeGenerator gen = getCodeGenerator();
Grammar g = gen.g;
assert g.name != null;
return g.name.toLowerCase() + "_listener.go";
}
Aggregations