當前位置: 首頁>>代碼示例>>Java>>正文


Java CommonTokenStream類代碼示例

本文整理匯總了Java中org.antlr.runtime.CommonTokenStream的典型用法代碼示例。如果您正苦於以下問題:Java CommonTokenStream類的具體用法?Java CommonTokenStream怎麽用?Java CommonTokenStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CommonTokenStream類屬於org.antlr.runtime包,在下文中一共展示了CommonTokenStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseAnyUnhandled

import org.antlr.runtime.CommonTokenStream; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:25,代碼來源:CQLFragmentParser.java

示例2: createParser

import org.antlr.runtime.CommonTokenStream; //導入依賴的package包/類
/** 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);
    }
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:23,代碼來源:ParseTree.java

示例3: getExpr

import org.antlr.runtime.CommonTokenStream; //導入依賴的package包/類
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;

  }
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:17,代碼來源:TestEvaluationVisitor.java

示例4: parseExpression

import org.antlr.runtime.CommonTokenStream; //導入依賴的package包/類
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;

  }
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:18,代碼來源:TreeTest.java

示例5: Test1

import org.antlr.runtime.CommonTokenStream; //導入依賴的package包/類
@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);

    }
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:22,代碼來源:QueryTestCase.java

示例6: parse

import org.antlr.runtime.CommonTokenStream; //導入依賴的package包/類
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);
    }
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:19,代碼來源:SiddhiCompiler.java

示例7: parseStreamDefinition

import org.antlr.runtime.CommonTokenStream; //導入依賴的package包/類
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);
    }
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:19,代碼來源:SiddhiCompiler.java

示例8: parseTableDefinition

import org.antlr.runtime.CommonTokenStream; //導入依賴的package包/類
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);
    }
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:19,代碼來源:SiddhiCompiler.java

示例9: parsePartitionDefinition

import org.antlr.runtime.CommonTokenStream; //導入依賴的package包/類
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);
    }
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:19,代碼來源:SiddhiCompiler.java

示例10: parseQuery

import org.antlr.runtime.CommonTokenStream; //導入依賴的package包/類
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);
    }
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:19,代碼來源:SiddhiCompiler.java

示例11: runTestFor

import org.antlr.runtime.CommonTokenStream; //導入依賴的package包/類
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()));
}
 
開發者ID:RapturePlatform,項目名稱:Rapture,代碼行數:26,代碼來源:ApiChecks.java

示例12: runSuspendTestFor

import org.antlr.runtime.CommonTokenStream; //導入依賴的package包/類
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);
}
 
開發者ID:RapturePlatform,項目名稱:Rapture,代碼行數:24,代碼來源:ResourceBasedTest.java

示例13: test1

import org.antlr.runtime.CommonTokenStream; //導入依賴的package包/類
@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());
}
 
開發者ID:RapturePlatform,項目名稱:Rapture,代碼行數:21,代碼來源:JavaWalkerTest.java

示例14: test2

import org.antlr.runtime.CommonTokenStream; //導入依賴的package包/類
@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());
}
 
開發者ID:RapturePlatform,項目名稱:Rapture,代碼行數:21,代碼來源:JavaWalkerTest.java

示例15: test3

import org.antlr.runtime.CommonTokenStream; //導入依賴的package包/類
@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"));
    }
}
 
開發者ID:RapturePlatform,項目名稱:Rapture,代碼行數:25,代碼來源:JavaWalkerTest.java


注:本文中的org.antlr.runtime.CommonTokenStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。