Java 类org.antlr.runtime.CommonTokenStream 实例源码

项目:sstable-adaptor    文件:CQLFragmentParser.java   
/**
 * Just call a parser method in {@link CqlParser} - does not do any error handling.
 */
public static <R> R parseAnyUnhandled(CQLParserFunction<R> parserFunction, String input) throws RecognitionException
{
    // Lexer and parser
    ErrorCollector errorCollector = new ErrorCollector(input);
    CharStream stream = new ANTLRStringStream(input);
    CqlLexer lexer = new CqlLexer(stream);
    lexer.addErrorListener(errorCollector);

    TokenStream tokenStream = new CommonTokenStream(lexer);
    CqlParser parser = new CqlParser(tokenStream);
    parser.addErrorListener(errorCollector);

    // Parse the query string to a statement instance
    R r = parserFunction.parse(parser);

    // The errorCollector has queue up any errors that the lexer and parser may have encountered
    // along the way, if necessary, we turn the last error into exceptions here.
    errorCollector.throwFirstSyntaxError();

    return r;
}
项目:JavaGraph    文件:ParseTree.java   
/** Creates a parser for a given term, generating trees of this kind. */
public <P extends Parser> P createParser(Class<P> parserType, I info, String term) {
    try {
        // find the lexer type
        String parserName = parserType.getName();
        String lexerName = parserName.substring(0, parserName.indexOf("Parser"))
            .concat("Lexer");
        @SuppressWarnings("unchecked") Class<? extends Lexer> lexerType =
            (Class<? extends Lexer>) Class.forName(lexerName);
        Lexer lexer = createLexer(lexerType, info, term);
        // instantiate the parser
        CommonTokenStream tokenStream = new CommonTokenStream(lexer);
        Constructor<P> parserConstructor = parserType.getConstructor(TokenStream.class);
        P result = parserConstructor.newInstance(tokenStream);
        Method adaptorSetter = parserType.getMethod("setTreeAdaptor", TreeAdaptor.class);
        adaptorSetter.invoke(result, new ParseTreeAdaptor<>(this, info, tokenStream));
        callInitialise(result, info);
        return result;
    } catch (Exception e) {
        throw toRuntime(e);
    }
}
项目:QDrill    文件:TestEvaluationVisitor.java   
private LogicalExpression getExpr(String expr) throws Exception{
    ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
    CommonTokenStream tokens = new CommonTokenStream(lexer);

//    tokens.fill();
//    for(Token t : (List<Token>) tokens.getTokens()){
//      System.out.println(t + "" + t.getType());
//    }
//    tokens.rewind();

    ExprParser parser = new ExprParser(tokens);
    parse_return ret = parser.parse();

    return ret.e;

  }
项目:QDrill    文件:TreeTest.java   
private LogicalExpression parseExpression(String expr) throws RecognitionException, IOException{

    ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
    CommonTokenStream tokens = new CommonTokenStream(lexer);

//    tokens.fill();
//    for(Token t : (List<Token>) tokens.getTokens()){
//      System.out.println(t + "" + t.getType());
//    }
//    tokens.rewind();

    ExprParser parser = new ExprParser(tokens);
    parse_return ret = parser.parse();

    return ret.e;

  }
项目:dremio-oss    文件:TreeTest.java   
private LogicalExpression parseExpression(String expr) throws RecognitionException, IOException{

    ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
    CommonTokenStream tokens = new CommonTokenStream(lexer);

//    tokens.fill();
//    for(Token t : (List<Token>) tokens.getTokens()){
//      System.out.println(t + "" + t.getType());
//    }
//    tokens.rewind();

    ExprParser parser = new ExprParser(tokens);
    parse_return ret = parser.parse();

    return ret.e;

  }
项目:rb-bi    文件:QueryTestCase.java   
@Test
    public void Test1() throws RecognitionException {
        SiddhiQLGrammarLexer lexer = new SiddhiQLGrammarLexer();

        lexer.setCharStream(new ANTLRStringStream(
                "define stream `define` ( `string` string, price int, volume float );"));
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        SiddhiQLGrammarParser parser = new SiddhiQLGrammarParser(tokens);

        parser.executionPlan();
//        System.out.println("OK");
//        double float1 = 2d;
//        System.out.println(float1);
        // CommonTree t = (CommonTree) r.getTree();
        //
        // CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
        // nodes.setTokenStream(tokens);
        // SiddhiGrammarWalker walker = new SiddhiGrammarWalker(nodes);
        // return walker.siddhiGrammar(existingStreams);

    }
项目:rb-bi    文件:SiddhiCompiler.java   
public static List<ExecutionPlan> parse(String source) throws SiddhiParserException {
    try {
        SiddhiQLGrammarLexer lexer = new SiddhiQLGrammarLexer();
        lexer.setCharStream(new ANTLRStringStream(source));
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        SiddhiQLGrammarParser parser = new SiddhiQLGrammarParser(tokens);

        SiddhiQLGrammarParser.executionPlan_return r = parser.executionPlan();
        CommonTree t = (CommonTree) r.getTree();

        CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
        nodes.setTokenStream(tokens);
        SiddhiQLGrammarWalker walker = new SiddhiQLGrammarWalker(nodes);
        return walker.executionPlan();
    } catch (Throwable e) {
        throw new SiddhiParserException(e.getMessage(), e);
    }
}
项目:rb-bi    文件:SiddhiCompiler.java   
public static StreamDefinition parseStreamDefinition(String source) throws SiddhiParserException {
    try {
        SiddhiQLGrammarLexer lexer = new SiddhiQLGrammarLexer();
        lexer.setCharStream(new ANTLRStringStream(source));
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        SiddhiQLGrammarParser parser = new SiddhiQLGrammarParser(tokens);

        SiddhiQLGrammarParser.definitionStreamFinal_return r = parser.definitionStreamFinal();
        CommonTree t = (CommonTree) r.getTree();

        CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
        nodes.setTokenStream(tokens);
        SiddhiQLGrammarWalker walker = new SiddhiQLGrammarWalker(nodes);
        return walker.definitionStreamFinal();
    } catch (Throwable e) {
        throw new SiddhiParserException(e.getMessage(), e);
    }
}
项目:rb-bi    文件:SiddhiCompiler.java   
public static TableDefinition parseTableDefinition(String source) throws SiddhiParserException {
    try {
        SiddhiQLGrammarLexer lexer = new SiddhiQLGrammarLexer();
        lexer.setCharStream(new ANTLRStringStream(source));
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        SiddhiQLGrammarParser parser = new SiddhiQLGrammarParser(tokens);

        SiddhiQLGrammarParser.definitionTableFinal_return r = parser.definitionTableFinal();
        CommonTree t = (CommonTree) r.getTree();

        CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
        nodes.setTokenStream(tokens);
        SiddhiQLGrammarWalker walker = new SiddhiQLGrammarWalker(nodes);
        return walker.definitionTableFinal();
    } catch (Throwable e) {
        throw new SiddhiParserException(e.getMessage(), e);
    }
}
项目:rb-bi    文件:SiddhiCompiler.java   
public static PartitionDefinition parsePartitionDefinition(String source) throws SiddhiParserException {
    try {
        SiddhiQLGrammarLexer lexer = new SiddhiQLGrammarLexer();
        lexer.setCharStream(new ANTLRStringStream(source));
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        SiddhiQLGrammarParser parser = new SiddhiQLGrammarParser(tokens);

        SiddhiQLGrammarParser.definitionPartitionFinal_return r = parser.definitionPartitionFinal();
        CommonTree t = (CommonTree) r.getTree();

        CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
        nodes.setTokenStream(tokens);
        SiddhiQLGrammarWalker walker = new SiddhiQLGrammarWalker(nodes);
        return walker.definitionPartitionFinal();
    } catch (Throwable e) {
        throw new SiddhiParserException(e.getMessage(), e);
    }
}
项目:rb-bi    文件:SiddhiCompiler.java   
public static Query parseQuery(String source) throws SiddhiParserException {
    try {
        SiddhiQLGrammarLexer lexer = new SiddhiQLGrammarLexer();
        lexer.setCharStream(new ANTLRStringStream(source));
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        SiddhiQLGrammarParser parser = new SiddhiQLGrammarParser(tokens);

        SiddhiQLGrammarParser.queryFinal_return r = parser.queryFinal();
        CommonTree t = (CommonTree) r.getTree();

        CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
        nodes.setTokenStream(tokens);
        SiddhiQLGrammarWalker walker = new SiddhiQLGrammarWalker(nodes);
        return walker.queryFinal();
    } catch (Throwable e) {
        throw new SiddhiParserException(e.getMessage(), e);
    }
}
项目:rb-bi    文件:QueryTestCase.java   
@Test
    public void Test1() throws RecognitionException {
        SiddhiQLGrammarLexer lexer = new SiddhiQLGrammarLexer();

        lexer.setCharStream(new ANTLRStringStream(
                "define stream `define` ( `string` string, price int, volume float );"));
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        SiddhiQLGrammarParser parser = new SiddhiQLGrammarParser(tokens);

        parser.executionPlan();
//        System.out.println("OK");
//        double float1 = 2d;
//        System.out.println(float1);
        // CommonTree t = (CommonTree) r.getTree();
        //
        // CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
        // nodes.setTokenStream(tokens);
        // SiddhiGrammarWalker walker = new SiddhiGrammarWalker(nodes);
        // return walker.siddhiGrammar(existingStreams);

    }
项目:Rapture    文件:ApiChecks.java   
private void runTestFor(String script) throws RecognitionException {
    ReflexLexer lexer = new ReflexLexer();
    lexer.setCharStream(new ANTLRStringStream(script));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ReflexParser parser = new ReflexParser(tokens);
    CommonTree tree = (CommonTree) parser.parse().getTree();

    /*
     * DOTTreeGenerator gen = new DOTTreeGenerator(); StringTemplate st =
     * gen.toDOT(tree); System.out.println(st);
     */

    CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
    ReflexTreeWalker walker = new ReflexTreeWalker(nodes, parser.languageRegistry);
    HttpLoginApi loginApi = new HttpLoginApi("http://localhost:8665/rapture", new SimpleCredentialsProvider("rapture", "rapture"));
    loginApi.login();
    HttpUserApi userApi = new HttpUserApi(loginApi);
    ApiVersion version = userApi.getServerApiVersion();
    System.out.println("version is " + version.getMajor() + ":" + version.getMinor());

    walker.getReflexHandler().setApi(new ScriptClient(loginApi));

    ReflexNode returned = walker.walk();
    System.out.println(returned == null ? "null" : returned.evaluateWithoutScope(new ReflexPrintingDebugger()));
}
项目:Rapture    文件:ResourceBasedTest.java   
protected void runSuspendTestFor(String fileName) throws RecognitionException {
    ReflexLexer lexer = new ReflexLexer();
    lexer.setCharStream(new ANTLRStringStream(getResourceAsString(this, fileName)));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ReflexParser parser = new ReflexParser(tokens);
    CommonTree tree = (CommonTree) parser.parse().getTree();

    /*
     * DOTTreeGenerator gen = new DOTTreeGenerator(); StringTemplate st =
     * gen.toDOT(tree); System.out.println(st);
     */

    CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
    ReflexTreeWalker walker = new ReflexTreeWalker(nodes, parser.languageRegistry);
    ReflexNode returned = walker.walk();
    ReflexValue value = returned.evaluateWithoutScope(new NullDebugger());
    while (value.getValue() == ReflexValue.Internal.SUSPEND) {
        System.out.println("Oooh it suspended...");
        System.out.println("Resuming script");
        value = returned.evaluateWithResume(new NullDebugger(), returned.getScope());
    }
    System.out.println(value);
}
项目:Rapture    文件:JavaWalkerTest.java   
@Test
public void test1() throws RecognitionException {
    CharStream input = new ANTLRStringStream("version(1.1.0)\n" + "minVer(1.1.0)\n"
            + "[ The Admin API is used to manipulate and access the low level entities in Rapture. Typically the methods in this API\n"
            + "are only used during significant setup events in a Rapture environment.]\n" + "api(Admin) {\n"
            + "    [This method restores a user that has been deleted]\n" + "    @entitle=/admin/main\n"
            + "    @public Boolean restoreUser(String userName);\n" + "}\n" + "[A return value from a native query]\n"
            + "type RaptureQueryResult(@package=rapture.common) {\n" + "    List(JsonContent) rows;\n" + "}\n");
    TLexer lexer = new TLexer(input);
    TokenStream tokenInputStream = new CommonTokenStream(lexer);
    TParser parser = new TParser(tokenInputStream);
    hmxdef_return returnVal = parser.hmxdef();
    System.out.println("Done " + returnVal.getTree().toStringTree());

    TreeNodeStream treeInput = new CommonTreeNodeStream(returnVal.getTree());
    TTree walker = new TTree(treeInput);
    walker.setTemplateLib(TemplateRepo.getApiTemplates("Java"));
    com.incapture.rapgen.TTree.hmxdef_return walkerResult = walker.hmxdef();
    System.out.println("Done, result=" + walkerResult.toString());
}
项目:Rapture    文件:JavaWalkerTest.java   
@Test
public void test2() throws RecognitionException {
    CharStream input = new ANTLRStringStream("version(1.1.0)\n" + "minVer(1.1.0)\n"
            + "[ The Admin API is used to manipulate and access the low level entities in Rapture. Typically the methods in this API\n"
            + "are only used during significant setup events in a Rapture environment.]\n" + "api(Admin) {\n"
            + "    [This method restores a user that has been deleted]\n" + "    @entitle=/admin/main\n"
            + "    @public Boolean restoreUser(String userName);\n" + "}\n" + "[A return value from a native query]\n"
            + "type RaptureQueryResult(@package=rapture.common) {\n" + "    List(JsonContent) rows;\n" + "}\n");
    TLexer lexer = new TLexer(input);
    TokenStream tokenInputStream = new CommonTokenStream(lexer);
    TParser parser = new TParser(tokenInputStream);
    hmxdef_return returnVal = parser.hmxdef();
    System.out.println("Done " + returnVal.getTree().toStringTree());

    TreeNodeStream treeInput = new CommonTreeNodeStream(returnVal.getTree());
    TTree walker = new TTree(treeInput);
    walker.setTemplateLib(TemplateRepo.getApiTemplates("Java"));
    apiGen_return walkerResult = walker.apiGen();
    System.out.println("Done, result=" + walkerResult.toString());
}
项目:Rapture    文件:JavaWalkerTest.java   
@Test
public void test3() throws RecognitionException {
    CharStream input = new ANTLRStringStream("version(1.1.0)\n" + "minVer(1.1.0)\n"
            + "[ The Admin API is used to manipulate and access the low level entities in Rapture. Typically the methods in this API\n"
            + "are only used during significant setup events in a Rapture environment.]\n" + "api(Admin) {\n"
            + "    [This method restores a user that has been deleted]\n" + "    @entitle=/admin/main\n"
            + "    @public Boolean restoreUser(String userName);\n" + "}\n" + "[A return value from a native query]\n"
            + "type RaptureQueryResult(@package=rapture.common) {\n" + "    List(JsonContent) rows;\n" + "}\n");
    TLexer lexer = new TLexer(input);
    TokenStream tokenInputStream = new CommonTokenStream(lexer);
    TParser parser = new TParser(tokenInputStream);
    hmxdef_return returnVal = parser.hmxdef();
    System.out.println("Done " + returnVal.getTree().toStringTree());

    TreeNodeStream treeInput = new CommonTreeNodeStream(returnVal.getTree());
    TTree walker = new TTree(treeInput);
    walker.setTemplateLib(TemplateRepo.getSdkTemplates("Java"));
    try {
        walker.sdkGen();
        fail("This should have failed, sdk name is required but not present in code");
    } catch (IllegalArgumentException e) {
        assertTrue(e.getMessage().contains("SDK Name"));
    }
}
项目:Rapture    文件:JavaWalkerTest.java   
@Test
public void test4() throws RecognitionException {
    CharStream input = new ANTLRStringStream("sdk(alan)\n" + "version(0.0.1)\n" + "minVer(0.0.1)\n"
            + "[ The Admin API is used to manipulate and access the low level entities in Rapture. Typically the methods in this API\n"
            + "are only used during significant setup events in a Rapture environment.]\n" + "api(Admin) {\n"
            + "    [This method restores a user that has been deleted]\n" + "    @entitle=/admin/main\n"
            + "    @public Boolean restoreUser(String userName);\n" + "}\n" + "[A return value from a native query]\n"
            + "type RaptureQueryResult(@package=rapture.common) {\n" + "    List(JsonContent) rows;\n" + "}\n");
    TLexer lexer = new TLexer(input);
    TokenStream tokenInputStream = new CommonTokenStream(lexer);
    TParser parser = new TParser(tokenInputStream);
    hmxdef_return returnVal = parser.hmxdef();
    System.out.println("Done " + returnVal.getTree().toStringTree());

    TreeNodeStream treeInput = new CommonTreeNodeStream(returnVal.getTree());
    TTree walker = new TTree(treeInput);
    walker.setTemplateLib(TemplateRepo.getSdkTemplates("Java"));
    walker.sdkGen();
}
项目:Rapture    文件:JavaWalkerTest.java   
@Test
public void test5() throws RecognitionException {
    CharStream input = new ANTLRStringStream("sdk(alan)\n" + "version(0.0.1)\n" + "minVer(0.0.1)\n"
            + "[ The Admin API is used to manipulate and access the low level entities in Rapture. Typically the methods in this API\n"
            + "are only used during significant setup events in a Rapture environment.]\n" + "api(Admin) {\n"
            + "    [This method restores a user that has been deleted]\n" + "    @entitle=/admin/main\n"
            + "    @public Boolean restoreUser(String userName);\n" + "}\n" + "[A return value from a native query]\n"
            + "type RaptureQueryResult(@package=rapture.common) {\n" + "    List(JsonContent) rows;\n" + "}\n");
    TLexer lexer = new TLexer(input);
    TokenStream tokenInputStream = new CommonTokenStream(lexer);
    TParser parser = new TParser(tokenInputStream);
    hmxdef_return returnVal = parser.hmxdef();
    System.out.println("Done " + returnVal.getTree().toStringTree());

    TreeNodeStream treeInput = new CommonTreeNodeStream(returnVal.getTree());
    TTree walker = new TTree(treeInput);
    walker.setTemplateLib(TemplateRepo.getApiTemplates("Java"));
    try {
        walker.apiGen();
        fail("This should have failed, sdk name is not expected but found");
    } catch (IllegalArgumentException e) {
        assertTrue(e.getMessage().contains("SDK Name"));
    }
}
项目:Rapture    文件:JavaWalkerTest.java   
@Test
public void test7() throws RecognitionException {
    CharStream input = new ANTLRStringStream("version(1.1.0)\n" + "minVer(1.1.0)\n"
            + "[ The Admin API is used to manipulate and access the low level entities in Rapture. Typically the methods in this API\n"
            + "are only used during significant setup events in a Rapture environment.]\n" + "api(Admin) {\n"
            + "    [This method restores a user that has been deleted]\n" + "    @entitle=/admin/main\n"
            + "    @public Boolean restoreUser(String userName);\n" + "}\n" + "[A return value from a native query]\n"
            + "@Storable(storagePath : {\"sys\", name}, separator=\".\")\n" +
            "type RepoConfig (@package=rapture.common.model) {\n" +
            "   String name = \"test\";\n" +
            "   String config;\n" +
            "}\n" +
            "");
    TLexer lexer = new TLexer(input);
    TokenStream tokenInputStream = new CommonTokenStream(lexer);
    TParser parser = new TParser(tokenInputStream);
    hmxdef_return returnVal = parser.hmxdef();
    System.out.println("Done " + returnVal.getTree().toStringTree());

    TreeNodeStream treeInput = new CommonTreeNodeStream(returnVal.getTree());
    TTree walker = new TTree(treeInput);
    walker.setTemplateLib(TemplateRepo.getApiTemplates("Java"));
    apiGen_return walkerResult = walker.apiGen();
    System.out.println("Done, result=" + walkerResult.toString());
}
项目:coj-web    文件:Utils.java   
public static List<Token> getTokens(String sourceCode, String language)
        throws Exception {
    Lexer lexer = null;
    if (language.compareTo("C++") == 0) {
        lexer = new PlagiCOJCppLexer(new ANTLRStringStream(sourceCode));
    } else if (language.compareTo("Java") == 0) {
        lexer = new PlagiCOJJavaLexer(new ANTLRStringStream(sourceCode));
    } else if (language.compareTo("C#") == 0) {
        lexer = new PlagiCOJCSharpLexer(new ANTLRStringStream(sourceCode));
    } else if (language.compareTo("C") == 0) {
        lexer = new PlagiCOJCLexer(new ANTLRStringStream(sourceCode));
    } else if (language.compareTo("Python") == 0) {
        lexer = new PlagiCOJPythonLexer(new ANTLRStringStream(sourceCode));
    } else if (language.compareTo("Pascal") == 0) {
        lexer = new PlagiCOJPascalLexer(new ANTLRStringStream(sourceCode));
    } else {
        throw new PlagiCOJUnsupportedLanguageException();
    }
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    return tokens.getTokens();
}
项目:Rapture    文件:AnnotationsTest.java   
@Test
public void test6() throws RecognitionException {
    System.out.println("6");
    CharStream input = new ANTLRStringStream("[ This is a mailbox message, usually posted by an external user]\n" + "@Addressable(scheme = MAILBOX)\n"
            + "@Storable(storagePath : {authority , documentPath , id} )\n" + "type RaptureMailMessage(@package=rapture.common.model) {\n"
            + "   String id;\n" + "   String authority;\n" + "   String category;\n" + "   String content;\n" + "   Date when;\n" + "   String who;\n"
            + "}\n" + "");
    TLexer lexer = new TLexer(input);
    TokenStream tokenInputStream = new CommonTokenStream(lexer);
    TParser parser = new TParser(tokenInputStream);
    typeExpr_return returnVal = parser.typeExpr();
    System.out.println("Done " + returnVal.getTree().toStringTree());

    TreeNodeStream treeInput = new CommonTreeNodeStream(returnVal.getTree());
    TTree walker = new TTree(treeInput);
    walker.setTemplateLib(TemplateRepo.getApiTemplates("Java"));
    com.incapture.rapgen.TTree.typeExpr_return walkerResult = walker.typeExpr();
    System.out.println("Done, result=" + walkerResult.toString());
}
项目:Rapture    文件:JSWalkerTest.java   
@Test
public void test1() throws RecognitionException, IOException {
    CharStream input = new ANTLRStringStream("version(1.1.0)\n" + "minVer(1.1.0)\n"
            + "[ The Admin API is used to manipulate and access the low level entities in Rapture. Typically the methods in this API\n"
            + "are only used during significant setup events in a Rapture environment.]\n" + "api(Admin) {\n"
            + "    [This method restores a user that has been deleted]\n" + "    @entitle=/admin/main\n"
            + "    @public Boolean restoreUser(String userName);\n" + "}\n" + "[A return value from a native query]\n"
            + "type RaptureQueryResult(@package=rapture.common) {\n" + "    List(JsonContent) rows;\n" + "}\n");
    TLexer lexer = new TLexer(input);
    TokenStream tokenInputStream = new CommonTokenStream(lexer);
    TParser parser = new TParser(tokenInputStream);
    hmxdef_return returnVal = parser.hmxdef();
    System.out.println("Done " + returnVal.getTree().toStringTree());

    TreeNodeStream treeInput = new CommonTreeNodeStream(returnVal.getTree());
    TTreeJS walker = new TTreeJS(treeInput);
    walker.setTemplateLib(getJsTemplate());
}
项目:Rapture    文件:StatStoreFactory.java   
public static IRaptureStatApi getStatImpl(String config) {
    // Given a config that is formatted in the idgen command
    // string, create a RaptureIdGen
    // and assign the appropriate features and implementation to it.
    //
    try {
        SGenLexer lexer = new SGenLexer();
        log.info("Creating store from config - " + config);
        lexer.setCharStream(new ANTLRStringStream(config));
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        SGenParser parser = new SGenParser(tokens);
        parser.sinfo();

        StandardStatImpl ret = new StandardStatImpl();
        ret.setStatStore(createStatStore(parser.getStore().getType(), parser.getConfig().getConfig()));
        return ret;
    } catch (RecognitionException e) {
        log.error("Error parsing config - " + e.getMessage());
    }
    return null;
}
项目:Rapture    文件:ReflexRaptureScript.java   
private ReflexTreeWalker getStandardWalker(CallingContext ctx, String script) throws RecognitionException {
    ReflexLexer lexer = new ReflexLexer();
    lexer.dataHandler = new ReflexIncludeHelper(ctx);
    lexer.setCharStream(new ANTLRStringStream(script));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ReflexParser parser = new ReflexParser(tokens);
    CommonTree tree;
    tree = (CommonTree) parser.parse().getTree();
    CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
    ReflexTreeWalker walker = new ReflexTreeWalker(nodes, parser.languageRegistry);
    walker.setReflexHandler(new AddingOutputReflexHandler());
    walker.getReflexHandler().setOutputHandler(new SimpleCollectingOutputHandler());
    walker.getReflexHandler().setOutputHandler(new DummyReflexOutputHandler());
    walker.getReflexHandler().setDataHandler(new ReflexDataHelper(ctx));
    walker.getReflexHandler().setIOHandler(new BlobOnlyIOHandler());
    walker.setScriptInfo(parser.scriptInfo);
    return walker;
}
项目:Rapture    文件:ResourceBasedTest.java   
protected void runSuspendTestFor(String fileName) throws RecognitionException {
    ReflexLexer lexer = new ReflexLexer();
    lexer.setCharStream(new ANTLRStringStream(getResourceAsString(this, fileName)));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ReflexParser parser = new ReflexParser(tokens);
    CommonTree tree = (CommonTree) parser.parse().getTree();

    /*
     * DOTTreeGenerator gen = new DOTTreeGenerator(); StringTemplate st =
     * gen.toDOT(tree); System.out.println(st);
     */

    CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
    ReflexTreeWalker walker = new ReflexTreeWalker(nodes, parser.languageRegistry);
    ReflexNode returned = walker.walk();
    ReflexValue value = returned.evaluateWithoutScope(new NullDebugger());
    while (value.getValue() == ReflexValue.Internal.SUSPEND) {
        System.out.println("Oooh it suspended...");
        System.out.println("Resuming script");
        value = returned.evaluateWithResume(new NullDebugger(), returned.getScope());
    }
    System.out.println(value);
}
项目:Rapture    文件:ResourceBasedTest.java   
protected void runTestForWithApi(String fileName, ScriptingApi api, IReflexDataHandler dataHandler) throws RecognitionException {
    ReflexLexer lexer = new ReflexLexer();
    lexer.setCharStream(new ANTLRStringStream(getResourceAsString(this, fileName)));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ReflexParser parser = new ReflexParser(tokens);
    CommonTree tree = (CommonTree) parser.parse().getTree();

    CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
    ReflexTreeWalker walker = new ReflexTreeWalker(nodes, parser.languageRegistry);

    walker.getReflexHandler().setApi(api);
    walker.getReflexHandler().setDataHandler(dataHandler);

    ReflexNode returned = walker.walk();
    System.out.println(returned == null ? "null" : returned.evaluateWithoutScope(new ReflexPrintingDebugger()));
}
项目:moql    文件:OperandFactoryImpl.java   
@Override
public Operand createOperand(String operand) throws MoqlException {
    // TODO Auto-generated method stub
    Validate.notEmpty(operand, "Parameter 'operand' is empty!");
    Operand pseudoOperand = createPseudoOperand(operand);
    if (pseudoOperand != null)
      return pseudoOperand;
    try {
        ANTLRInputStream is = new ANTLRInputStream(new ByteArrayInputStream(operand.getBytes()));
        OperandLexer lexer = new OperandLexer(is);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        OperandParser parser = new OperandParser(tokens);
        parser.setFunctionFactory(functionFactory);
        return parser.operand();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        throw new MoqlException(StringFormater.format("Create operand '{}' failed!", operand), e);
    }
}
项目:moql    文件:MoqlParser.java   
/**
 *
 * @param moql
 * @return SelectorMetadata or SetlectorMetadata
 * @throws MoqlException
 */
public static SelectorDefinition parseMoql(String moql) throws MoqlException {
  Validate.notEmpty(moql, "Parameter 'moql' is empty!");
  try {
    ANTLRInputStream is = new ANTLRInputStream(new ByteArrayInputStream(
        moql.getBytes()));
    SelectorLexer lexer = new SelectorLexer(is);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    SelectorParser parser = new SelectorParser(tokens);
    return parser.selector();
  } catch (Exception e) {
    // TODO Auto-generated catch block
    throw new MoqlException(StringFormater.format("Parse moql '{}' failed!",
        moql), e);
  }
}
项目:moql    文件:MoqlParser.java   
public static ConditionMetadata parseCondition(String condition)
    throws MoqlException {
  Validate.notEmpty(condition, "Parameter 'condition' is empty!");
  try {
    ANTLRInputStream is = new ANTLRInputStream(new ByteArrayInputStream(
        condition.getBytes()));
    FilterLexer lexer = new FilterLexer(is);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    FilterParser parser = new FilterParser(tokens);
    return new ConditionMetadata(parser.searchCondition());
  } catch (Exception e) {
    // TODO Auto-generated catch block
    throw new MoqlException(StringFormater.format(
        "Parse condition '{}' failed!", condition), e);
  }
}
项目:codebuff    文件:STGroup.java   
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix!=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
项目:codebuff    文件:STGroup.java   
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix!=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
项目:codebuff    文件:STGroup.java   
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix!=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
项目:codebuff    文件:STGroup.java   
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix!=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
项目:codebuff    文件:STGroup.java   
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix!=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
项目:codebuff    文件:STGroup.java   
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix!=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
项目:codebuff    文件:STGroup.java   
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix!=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
项目:codebuff    文件:STGroup.java   
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix !=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
项目:codebuff    文件:STGroup.java   
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix !=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
项目:codebuff    文件:STGroup.java   
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix!=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}