use of org.snt.inmemantlr.comp.StringCodeGenPipeline in project inmemantlr by julianthome.
the class InmemantlrTool method createPipeline.
/**
* create code generation pipeline from grammar ast
*
* @param ast grammar ast
* @return string code generation pipeline
*/
public StringCodeGenPipeline createPipeline(GrammarRootAST ast) {
if (pip.containsKey(ast.getGrammarName()))
pip.get(ast.getGrammarName());
LOGGER.debug("create grammar {}", ast.getGrammarName());
final Grammar g = createGrammar(ast);
g.fileName = g.name;
g.loadImportedGrammars();
StringCodeGenPipeline spip = new StringCodeGenPipeline(g);
LOGGER.debug("put grammar {}", g.name);
pip.put(g.name, spip);
return spip;
}
use of org.snt.inmemantlr.comp.StringCodeGenPipeline in project inmemantlr by julianthome.
the class InmemantlrTool method process.
/**
* process all code generation pipeline and return the 'main'
* grammar and lexer names which are used to load the right classes
* afterwards
*
* @return tuple of lexer and parser names
*/
public Tuple<String, String> process() {
LOGGER.debug("process grammars");
StringCodeGenPipeline last = null;
// order is important here
Set<StringCodeGenPipeline> pip = getPipelines();
if (pip.isEmpty())
throw new IllegalArgumentException("pip must not be empty");
for (StringCodeGenPipeline p : pip) {
Grammar g = p.getG();
LOGGER.debug("process {}", g.name);
String s = getDepTokVocName(g);
if (s != null && !s.isEmpty() && tokvok.containsKey(s) && tokvok.get(s) != null) {
LOGGER.debug("get {}", s);
String tokvoc = tokvok.get(s);
if (g instanceof InmemantlrGrammar) {
LOGGER.debug("import from {}", tokvoc);
((InmemantlrGrammar) g).setTokenVocab(tokvoc);
} else if (g instanceof InmemantlrLexerGrammar) {
LOGGER.debug("2");
((InmemantlrLexerGrammar) g).setTokenVocab(tokvoc);
}
}
if (!isImported(g.name)) {
process(p.getG());
p.process();
setParserLexer(p.getG());
if (p.hasTokenVocab()) {
LOGGER.debug("put tokvok {}", g.name);
tokvok.put(g.name, p.getTokenVocabString());
}
}
}
if (lexerName.isEmpty())
throw new IllegalArgumentException("lexerName must not be empty");
if (parserName.isEmpty())
throw new IllegalArgumentException("parserName must not be empty");
return new Tuple<>(parserName, lexerName);
}
Aggregations