本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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()));
}
示例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);
}
示例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());
}
示例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());
}
示例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"));
}
}