Search in sources :

Example 1 with BtrPlaceTreeAdaptor

use of org.btrplace.btrpsl.tree.BtrPlaceTreeAdaptor 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;
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) BtrPlaceTree(org.btrplace.btrpsl.tree.BtrPlaceTree) ANTLRBtrplaceSL2Lexer(org.btrplace.btrpsl.antlr.ANTLRBtrplaceSL2Lexer) ANTLRBtrplaceSL2Parser(org.btrplace.btrpsl.antlr.ANTLRBtrplaceSL2Parser) BtrPlaceTreeAdaptor(org.btrplace.btrpsl.tree.BtrPlaceTreeAdaptor) RecognitionException(org.antlr.runtime.RecognitionException)

Aggregations

CommonTokenStream (org.antlr.runtime.CommonTokenStream)1 RecognitionException (org.antlr.runtime.RecognitionException)1 ANTLRBtrplaceSL2Lexer (org.btrplace.btrpsl.antlr.ANTLRBtrplaceSL2Lexer)1 ANTLRBtrplaceSL2Parser (org.btrplace.btrpsl.antlr.ANTLRBtrplaceSL2Parser)1 BtrPlaceTree (org.btrplace.btrpsl.tree.BtrPlaceTree)1 BtrPlaceTreeAdaptor (org.btrplace.btrpsl.tree.BtrPlaceTreeAdaptor)1