本文整理汇总了Java中org.antlr.runtime.TokenRewriteStream类的典型用法代码示例。如果您正苦于以下问题:Java TokenRewriteStream类的具体用法?Java TokenRewriteStream怎么用?Java TokenRewriteStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TokenRewriteStream类属于org.antlr.runtime包,在下文中一共展示了TokenRewriteStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rename
import org.antlr.runtime.TokenRewriteStream; //导入依赖的package包/类
/**
* Returns renamed versions of the stored control programs.
* @return a mapping from program names to changed programs
*/
public Map<QualName,String> rename(QualName oldCallName, QualName newCallName) {
Map<QualName,String> result = new HashMap<>();
for (Map.Entry<QualName,CtrlTree> entry : this.controlTreeMap.entrySet()) {
QualName name = entry.getKey();
CtrlTree tree = entry.getValue();
TokenRewriteStream rewriter = getRewriter(tree);
boolean changed = false;
for (CtrlTree t : tree.getRuleIdTokens(oldCallName)) {
rewriter.replace(t.getToken(), t.getChild(0)
.getToken(), newCallName);
changed = true;
}
if (changed) {
result.put(name, rewriter.toString());
}
}
return result;
}
示例2: parseHiveType
import org.antlr.runtime.TokenRewriteStream; //导入依赖的package包/类
private static ASTNode parseHiveType(final String hiveType) {
try {
final ParseDriver driver = new ParseDriver();
final HiveLexer lexer = new HiveLexer(driver.new ANTLRNoCaseStringStream(hiveType));
final HiveParser parser = new HiveParser(new TokenRewriteStream(lexer));
parser.setTreeAdaptor(ParseDriver.adaptor);
final HiveParser.type_return type = parser.type();
final ASTNode ast = (ASTNode) type.getTree();
ast.setUnknownTokenBoundaries();
return ast;
} catch (Exception e) {
throw new IllegalArgumentException("invalid type: " + hiveType, e);
}
}
示例3: getEntPath
import org.antlr.runtime.TokenRewriteStream; //导入依赖的package包/类
public static String getEntPath(String path, IEntitlementsContext entCtx) {
EntLexer lexer = new EntLexer();
lexer.setCharStream(new ANTLRStringStream(path));
TokenRewriteStream tokens = new TokenRewriteStream(lexer);
EntParser parser = new EntParser(tokens);
parser.setEctx(entCtx);
try {
parser.entpath();
return parser.getPath();
} catch (RecognitionException e) {
// If we don't recognize it, ignore it and return the path
log.error("Could not parse path " + path + ", error was " + e.getMessage());
}
return path;
}
示例4: parse
import org.antlr.runtime.TokenRewriteStream; //导入依赖的package包/类
/**
* Parses a command, optionally assigning the parser's token stream to the
* given context.
*
* @param command command to parse
* @param ctx context with which to associate this parser's token stream, or
* null if either no context is available or the context already has
* an existing stream
* @return parsed AST
*/
public ASTNode parse(String command) throws ParseException {
LOG.info("Parsing command: " + command);
HiveLexerX lexer = new HiveLexerX(new ANTLRNoCaseStringStream(command));
TokenRewriteStream tokens = new TokenRewriteStream(lexer);
HiveParser parser = new HiveParser(tokens);
parser.setTreeAdaptor(adaptor);
HiveParser.statement_return r = null;
try {
r = parser.statement();
} catch (RecognitionException e) {
// e.printStackTrace();
throw new ParseException(parser.errors);
}
if (lexer.getErrors().size() == 0 && parser.errors.size() == 0) {
LOG.info("Parse Completed");
} else if (lexer.getErrors().size() != 0) {
throw new ParseException(lexer.getErrors());
} else {
throw new ParseException(parser.errors);
}
return (ASTNode) r.getTree();
}
示例5: parseSelect
import org.antlr.runtime.TokenRewriteStream; //导入依赖的package包/类
public ASTNode parseSelect(String command) throws ParseException {
LOG.info("Parsing command: " + command);
HiveLexerX lexer = new HiveLexerX(new ANTLRNoCaseStringStream(command));
TokenRewriteStream tokens = new TokenRewriteStream(lexer);
HiveParser parser = new HiveParser(tokens);
parser.setTreeAdaptor(adaptor);
HiveParser_SelectClauseParser.selectClause_return r = null;
try {
r = parser.selectClause();
} catch (RecognitionException e) {
e.printStackTrace();
throw new ParseException(parser.errors);
}
if (lexer.getErrors().size() == 0 && parser.errors.size() == 0) {
LOG.info("Parse Completed");
} else if (lexer.getErrors().size() != 0) {
throw new ParseException(lexer.getErrors());
} else {
throw new ParseException(parser.errors);
}
return (ASTNode) r.getTree();
}
示例6: test2InsertBeforeAfterMiddleIndex
import org.antlr.runtime.TokenRewriteStream; //导入依赖的package包/类
public void test2InsertBeforeAfterMiddleIndex() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abc");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.insertBefore(1, "x");
tokens.insertAfter(1, "x");
String result = tokens.toString();
String expecting = "axbxc";
assertEquals(result, expecting);
}
示例7: test2ReplaceMiddleIndex
import org.antlr.runtime.TokenRewriteStream; //导入依赖的package包/类
public void test2ReplaceMiddleIndex() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abc");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.replace(1, "x");
tokens.replace(1, "y");
String result = tokens.toString();
String expecting = "ayc";
assertEquals(result, expecting);
}
示例8: testReplaceThenDeleteMiddleIndex
import org.antlr.runtime.TokenRewriteStream; //导入依赖的package包/类
public void testReplaceThenDeleteMiddleIndex() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abc");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.replace(1, "x");
tokens.delete(1);
String result = tokens.toString();
String expecting = "ac";
assertEquals(result, expecting);
}
示例9: testReplaceThenInsertSameIndex
import org.antlr.runtime.TokenRewriteStream; //导入依赖的package包/类
public void testReplaceThenInsertSameIndex() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abc");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.replace(0, "x");
tokens.insertBefore(0, "0");
String result = tokens.toString();
String expecting = "0xbc";
assertEquals(result, expecting);
}
示例10: testReplaceThen2InsertSameIndex
import org.antlr.runtime.TokenRewriteStream; //导入依赖的package包/类
public void testReplaceThen2InsertSameIndex() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abc");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.replace(0, "x");
tokens.insertBefore(0, "y");
tokens.insertBefore(0, "z");
String result = tokens.toString();
String expecting = "zyxbc";
assertEquals(result, expecting);
}
示例11: testInsertThenReplaceSameIndex
import org.antlr.runtime.TokenRewriteStream; //导入依赖的package包/类
public void testInsertThenReplaceSameIndex() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abc");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.insertBefore(0, "0");
tokens.replace(0, "x");
String result = tokens.toString();
String expecting = "0xbc";
assertEquals(result, expecting);
}
示例12: test2InsertMiddleIndex
import org.antlr.runtime.TokenRewriteStream; //导入依赖的package包/类
public void test2InsertMiddleIndex() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abc");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.insertBefore(1, "x");
tokens.insertBefore(1, "y");
String result = tokens.toString();
String expecting = "ayxbc";
assertEquals(result, expecting);
}
示例13: test2InsertThenReplaceIndex0
import org.antlr.runtime.TokenRewriteStream; //导入依赖的package包/类
public void test2InsertThenReplaceIndex0() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abc");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.insertBefore(0, "x");
tokens.insertBefore(0, "y");
tokens.replace(0, "z");
String result = tokens.toString();
String expecting = "yxzbc";
assertEquals(result, expecting);
}
示例14: testReplaceThenInsertBeforeLastIndex
import org.antlr.runtime.TokenRewriteStream; //导入依赖的package包/类
public void testReplaceThenInsertBeforeLastIndex() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abc");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.replace(2, "x");
tokens.insertBefore(2, "y");
String result = tokens.toString();
String expecting = "abyx";
assertEquals(result, expecting);
}
示例15: testInsertThenReplaceLastIndex
import org.antlr.runtime.TokenRewriteStream; //导入依赖的package包/类
public void testInsertThenReplaceLastIndex() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abc");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.insertBefore(2, "y");
tokens.replace(2, "x");
String result = tokens.toString();
String expecting = "abyx";
assertEquals(result, expecting);
}