use of org.btrplace.btrpsl.antlr.ANTLRBtrplaceSL2Parser in project scheduler by btrplace.
the class ScriptBuilder method build.
/**
* Internal method to check a script from a stream.
*
* @param cs the stream to analyze
* @return the built script
* @throws ScriptBuilderException in an error occurred while building the script
*/
// For the UnsupportedOperationException
@SuppressWarnings("squid:S1166")
private Script build(CharStream cs) throws ScriptBuilderException {
Script v = new Script();
ANTLRBtrplaceSL2Lexer lexer = new ANTLRBtrplaceSL2Lexer(cs);
ErrorReporter errorReporter = errBuilder.build(v);
lexer.setErrorReporter(errorReporter);
CommonTokenStream tokens = new CommonTokenStream(lexer);
ANTLRBtrplaceSL2Parser parser = new ANTLRBtrplaceSL2Parser(tokens);
parser.setErrorReporter(errorReporter);
SymbolsTable t = new SymbolsTable();
parser.setTreeAdaptor(new BtrPlaceTreeAdaptor(v, model, namingServiceNodes, namingServiceVMs, tpls, errorReporter, t, includes, catalog));
try {
BtrPlaceTree tree = (BtrPlaceTree) parser.script_decl().getTree();
if (tree != null) {
if (tree.token != null) {
// Single instruction
tree.go(tree);
} else {
for (int i = 0; i < tree.getChildCount(); i++) {
tree.getChild(i).go(tree);
}
}
}
} catch (RecognitionException e) {
throw new ScriptBuilderException(e.getMessage(), e);
} catch (UnsupportedOperationException e) {
// We only keep the error message
errorReporter.append(0, 0, e.getMessage());
}
if (!errorReporter.getErrors().isEmpty()) {
throw new ScriptBuilderException(errorReporter);
}
return v;
}
Aggregations