本文整理匯總了Java中org.antlr.runtime.tree.CommonTreeNodeStream.setTokenStream方法的典型用法代碼示例。如果您正苦於以下問題:Java CommonTreeNodeStream.setTokenStream方法的具體用法?Java CommonTreeNodeStream.setTokenStream怎麽用?Java CommonTreeNodeStream.setTokenStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.antlr.runtime.tree.CommonTreeNodeStream
的用法示例。
在下文中一共展示了CommonTreeNodeStream.setTokenStream方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parse
import org.antlr.runtime.tree.CommonTreeNodeStream; //導入方法依賴的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);
}
}
示例2: parseStreamDefinition
import org.antlr.runtime.tree.CommonTreeNodeStream; //導入方法依賴的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);
}
}
示例3: parseTableDefinition
import org.antlr.runtime.tree.CommonTreeNodeStream; //導入方法依賴的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);
}
}
示例4: parsePartitionDefinition
import org.antlr.runtime.tree.CommonTreeNodeStream; //導入方法依賴的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);
}
}
示例5: parseQuery
import org.antlr.runtime.tree.CommonTreeNodeStream; //導入方法依賴的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);
}
}
示例6: feedAST
import org.antlr.runtime.tree.CommonTreeNodeStream; //導入方法依賴的package包/類
private static CSSTreeParser feedAST(CommonTokenStream source,
CommonTree ast, Preparator preparator, StyleSheet stylesheet) {
if (log.isTraceEnabled()) {
log.trace("Feeding tree parser with AST:\n{}", TreeUtil
.toStringTree(ast));
}
// Walk resulting tree; create tree-node stream first
CommonTreeNodeStream nodes = new CommonTreeNodeStream(ast);
// AST nodes have payloads that point into token stream
nodes.setTokenStream(source);
CSSTreeParser parser = new CSSTreeParser(nodes);
return parser.init(stylesheet, preparator);
}
示例7: buildWalker
import org.antlr.runtime.tree.CommonTreeNodeStream; //導入方法依賴的package包/類
private static <E> LimboWalker buildWalker(ReferenceContext<E> context, String expr)
throws RecognitionException {
ANTLRStringStream in = new ANTLRStringStream(expr);
LimboLexer lexer = new LimboLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
LimboParser parser = new LimboParser(tokens);
CommonTree tree = (CommonTree) parser.condExpression().getTree();
CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
nodes.setTokenStream(tokens);
LimboWalker walker = new org.codehaus.preon.el.LimboWalker(nodes, new ImplicitsContext(context));
return walker;
}
示例8: parseApiFiles
import org.antlr.runtime.tree.CommonTreeNodeStream; //導入方法依賴的package包/類
private static List<StorableAttributes> parseApiFiles(CommandLine cmd, String mainApiFile, StringTemplateGroup templateLib, GenType genType)
throws IOException, RecognitionException {
TLexer lexer = new TLexer();
ResourceBasedApiReader apiReader = new ResourceBasedApiReader();
lexer.setApiReader(apiReader);
System.out.println(String.format("main api file is " + mainApiFile));
lexer.setCharStream(apiReader.read(mainApiFile));
// Using the lexer as the token source, we create a token
// stream to be consumed by the parser
//
CommonTokenStream tokens = new CommonTokenStream(lexer);
// Now we need an instance of our parser
//
TParser parser = new TParser(tokens);
hmxdef_return psrReturn = parser.hmxdef();
Tree t = psrReturn.getTree();
CommonTreeNodeStream ns = new CommonTreeNodeStream(t);
ns.setTokenStream(tokens);
TTree walker = TreeFactory.createJavaTreeWalker(ns, templateLib);
System.out.println("Generating persistence files.");
if (genType.equals(GenType.API)) {
walker.apiGen();
} else {
walker.sdkGen();
}
return walker.getStorableAttributes();
}
示例9: createTreeParser
import org.antlr.runtime.tree.CommonTreeNodeStream; //導入方法依賴的package包/類
protected JSONTree createTreeParser(String testString) throws IOException, RecognitionException {
JSONLexer lexer = createLexer(testString);
CommonTokenStream tokens = new CommonTokenStream(lexer);
JSONParser parser = new JSONParser(tokens);
// Invoke the program rule in get return value
JSONParser.value_return r = parser.value();
CommonTree t = (CommonTree) r.getTree();
// Walk resulting tree; create treenode stream first
CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
// AST nodes have payloads that point into token stream
nodes.setTokenStream(tokens);
// Create a tree Walker attached to the nodes stream
return new JSONTree(nodes);
}
示例10: reparse
import org.antlr.runtime.tree.CommonTreeNodeStream; //導入方法依賴的package包/類
private CFExpression reparse( cfStringData _string, CFContext _context )
throws cfmRunTimeException {
// note, the fact that calling leftVal.getString() will not include the
// pound signs is what's req'd
// note addition of ';' at end of expression to make it parsable
try {
ANTLRNoCaseReaderStream input = new ANTLRNoCaseReaderStream(
new poundSignFilterStream(new StringReader(_string.getString())));
CFMLLexer lexer = new CFMLLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
CFMLParser parser = new CFMLParser(tokens);
parser.scriptMode = false;
CFMLParser.expression_return r = parser.expression();
CommonTree tree = (CommonTree) r.getTree();
CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
nodes.setTokenStream(tokens);
CFMLTree p2 = new CFMLTree(nodes);
p2.scriptMode = false;
return p2.expression();
} catch (IOException ioe) { // shouldn't happen
throw new CFException("Invalid expression : " + left.Decompile(0),
_context);
} catch (RecognitionException pe) {
throw new CFException("Invalid expression : " + left.Decompile(0),
_context);
} catch (poundSignFilterStreamException e) {
throw new CFException("Invalid expression : " + left.Decompile(0),
_context);
}
}
示例11: feedAST
import org.antlr.runtime.tree.CommonTreeNodeStream; //導入方法依賴的package包/類
private static CSSTreeParser feedAST(CommonTokenStream source, CommonTree ast, Preparator preparator, List<MediaQuery> media)
{
if (log.isTraceEnabled()) {
log.trace("Feeding tree parser with AST:\n{}", TreeUtil.toStringTree(ast));
}
// Walk resulting tree; create tree-node stream first
CommonTreeNodeStream nodes = new CommonTreeNodeStream(ast);
// AST nodes have payloads that point into token stream
nodes.setTokenStream(source);
CSSTreeParser parser = new CSSTreeParser(nodes);
return parser.init(preparator, media);
}
示例12: compile
import org.antlr.runtime.tree.CommonTreeNodeStream; //導入方法依賴的package包/類
public static byte[] compile(List<String> smaliTexts, int apiLevel)
throws RecognitionException, IOException {
DexBuilder dexBuilder = new DexBuilder(Opcodes.forApi(apiLevel));
for (String smaliText : smaliTexts) {
Reader reader = new StringReader(smaliText);
LexerErrorInterface lexer = new smaliFlexLexer(reader);
CommonTokenStream tokens = new CommonTokenStream((TokenSource) lexer);
smaliParser parser = new smaliParser(tokens);
parser.setVerboseErrors(true);
parser.setAllowOdex(false);
parser.setApiLevel(apiLevel);
smaliParser.smali_file_return result = parser.smali_file();
if (parser.getNumberOfSyntaxErrors() > 0 || lexer.getNumberOfSyntaxErrors() > 0) {
throw new RuntimeException(
"Error occured while compiling text:\n" + StringUtils.join(smaliTexts, "\n"));
}
CommonTree t = result.getTree();
CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t);
treeStream.setTokenStream(tokens);
smaliTreeWalker dexGen = new smaliTreeWalker(treeStream);
dexGen.setApiLevel(apiLevel);
dexGen.setVerboseErrors(true);
dexGen.setDexBuilder(dexBuilder);
dexGen.smali_file();
if (dexGen.getNumberOfSyntaxErrors() > 0) {
throw new RuntimeException("Error occured while compiling text");
}
}
MemoryDataStore dataStore = new MemoryDataStore();
dexBuilder.writeTo(dataStore);
// TODO(sgjesse): This returns the full backingstore from MemoryDataStore, which by default
// is 1024k bytes. Our dex file reader does not complain though.
return dataStore.getData();
}
示例13: assembleSmaliFile
import org.antlr.runtime.tree.CommonTreeNodeStream; //導入方法依賴的package包/類
private static boolean assembleSmaliFile(File smaliFile, DexBuilder dexBuilder, boolean verboseErrors,
boolean printTokens, boolean allowOdex, int apiLevel)
throws Exception {
CommonTokenStream tokens;
LexerErrorInterface lexer;
FileInputStream fis = new FileInputStream(smaliFile.getAbsolutePath());
InputStreamReader reader = new InputStreamReader(fis, "UTF-8");
lexer = new smaliFlexLexer(reader);
((smaliFlexLexer)lexer).setSourceFile(smaliFile);
tokens = new CommonTokenStream((TokenSource)lexer);
if (printTokens) {
tokens.getTokens();
for (int i=0; i<tokens.size(); i++) {
Token token = tokens.get(i);
if (token.getChannel() == smaliParser.HIDDEN) {
continue;
}
System.out.println(smaliParser.tokenNames[token.getType()] + ": " + token.getText());
}
}
smaliParser parser = new smaliParser(tokens);
parser.setVerboseErrors(verboseErrors);
parser.setAllowOdex(allowOdex);
parser.setApiLevel(apiLevel);
smaliParser.smali_file_return result = parser.smali_file();
if (parser.getNumberOfSyntaxErrors() > 0 || lexer.getNumberOfSyntaxErrors() > 0) {
return false;
}
CommonTree t = result.getTree();
CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t);
treeStream.setTokenStream(tokens);
smaliTreeWalker dexGen = new smaliTreeWalker(treeStream);
dexGen.setVerboseErrors(verboseErrors);
dexGen.setDexBuilder(dexBuilder);
dexGen.smali_file();
return dexGen.getNumberOfSyntaxErrors() == 0;
}
示例14: assembleSmaliFile
import org.antlr.runtime.tree.CommonTreeNodeStream; //導入方法依賴的package包/類
private static boolean assembleSmaliFile(File smaliFile,
DexBuilder dexBuilder, boolean verboseErrors, boolean printTokens,
boolean allowOdex, int apiLevel) throws Exception {
CommonTokenStream tokens;
LexerErrorInterface lexer;
FileInputStream fis = new FileInputStream(smaliFile.getAbsolutePath());
InputStreamReader reader = new InputStreamReader(fis, "UTF-8");
lexer = new smaliFlexLexer(reader);
((smaliFlexLexer) lexer).setSourceFile(smaliFile);
tokens = new CommonTokenStream((TokenSource) lexer);
if (printTokens) {
tokens.getTokens();
for (int i = 0; i < tokens.size(); i++) {
Token token = tokens.get(i);
if (token.getChannel() == smaliParser.HIDDEN) {
continue;
}
System.out.println(smaliParser.tokenNames[token.getType()]
+ ": " + token.getText());
}
}
smaliParser parser = new smaliParser(tokens);
parser.setVerboseErrors(verboseErrors);
parser.setAllowOdex(allowOdex);
parser.setApiLevel(apiLevel);
smaliParser.smali_file_return result = parser.smali_file();
if (parser.getNumberOfSyntaxErrors() > 0
|| lexer.getNumberOfSyntaxErrors() > 0) {
return false;
}
CommonTree t = result.getTree();
CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t);
treeStream.setTokenStream(tokens);
smaliTreeWalker dexGen = new smaliTreeWalker(treeStream);
dexGen.setVerboseErrors(verboseErrors);
dexGen.setDexBuilder(dexBuilder);
dexGen.smali_file();
return dexGen.getNumberOfSyntaxErrors() == 0;
}
示例15: assembleSmaliFile
import org.antlr.runtime.tree.CommonTreeNodeStream; //導入方法依賴的package包/類
private static boolean assembleSmaliFile(File smaliFile,
DexBuilder dexBuilder, boolean verboseErrors, boolean printTokens,
boolean allowOdex, int apiLevel) throws Exception {
Logger.log("start assemble the file = " + smaliFile.getName());
CommonTokenStream tokens;
LexerErrorInterface lexer;
FileInputStream fis = new FileInputStream(smaliFile.getAbsolutePath());
InputStreamReader reader = new InputStreamReader(fis, "UTF-8");
lexer = new smaliFlexLexer(reader);
((smaliFlexLexer) lexer).setSourceFile(smaliFile);
tokens = new CommonTokenStream((TokenSource) lexer);
if (printTokens) {
tokens.getTokens();
for (int i = 0; i < tokens.size(); i++) {
Token token = tokens.get(i);
if (token.getChannel() == smaliParser.HIDDEN) {
continue;
}
System.out.println(smaliParser.tokenNames[token.getType()]
+ ": " + token.getText());
}
}
smaliParser parser = new smaliParser(tokens);
parser.setVerboseErrors(verboseErrors);
parser.setAllowOdex(allowOdex);
parser.setApiLevel(apiLevel);
smaliParser.smali_file_return result = parser.smali_file();
if (parser.getNumberOfSyntaxErrors() > 0
|| lexer.getNumberOfSyntaxErrors() > 0) {
return false;
}
CommonTree t = result.getTree();
CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t);
treeStream.setTokenStream(tokens);
smaliTreeWalker dexGen = new smaliTreeWalker(treeStream);
dexGen.setVerboseErrors(verboseErrors);
dexGen.setDexBuilder(dexBuilder);
dexGen.smali_file();
return dexGen.getNumberOfSyntaxErrors() == 0;
}