本文整理汇总了Java中org.antlr.runtime.TokenRewriteStream.replace方法的典型用法代码示例。如果您正苦于以下问题:Java TokenRewriteStream.replace方法的具体用法?Java TokenRewriteStream.replace怎么用?Java TokenRewriteStream.replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.runtime.TokenRewriteStream
的用法示例。
在下文中一共展示了TokenRewriteStream.replace方法的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: 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);
}
示例3: 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);
}
示例4: 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);
}
示例5: 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);
}
示例6: 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);
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: testReplaceSingleMiddleThenOverlappingSuperset
import org.antlr.runtime.TokenRewriteStream; //导入方法依赖的package包/类
public void testReplaceSingleMiddleThenOverlappingSuperset() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abcba");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.replace(2, 2, "xyz");
tokens.replace(0, 3, "foo");
String result = tokens.toString();
String expecting = "fooa";
assertEquals(result, expecting);
}
示例11: testReplaceRangeThenInsertInMiddle
import org.antlr.runtime.TokenRewriteStream; //导入方法依赖的package包/类
public void testReplaceRangeThenInsertInMiddle() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abcccba");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.replace(2, 4, "x");
tokens.insertBefore(3, "y"); // no effect; can't insert in middle of replaced region
String result = tokens.toString();
String expecting = "abxba";
assertEquals(result, expecting);
}
示例12: testReplaceRangeThenInsertAtLeftEdge
import org.antlr.runtime.TokenRewriteStream; //导入方法依赖的package包/类
public void testReplaceRangeThenInsertAtLeftEdge() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abcccba");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.replace(2, 4, "x");
tokens.insertBefore(2, "y");
String result = tokens.toString();
String expecting = "abyxba";
assertEquals(result, expecting);
}
示例13: testReplaceRangeThenInsertAtRightEdge
import org.antlr.runtime.TokenRewriteStream; //导入方法依赖的package包/类
public void testReplaceRangeThenInsertAtRightEdge() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abcccba");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.replace(2, 4, "x");
tokens.insertBefore(4, "y"); // no effect; within range of a replace
String result = tokens.toString();
String expecting = "abxba";
assertEquals(result, expecting);
}
示例14: testReplaceRangeThenInsertAfterRightEdge
import org.antlr.runtime.TokenRewriteStream; //导入方法依赖的package包/类
public void testReplaceRangeThenInsertAfterRightEdge() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abcccba");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.replace(2, 4, "x");
tokens.insertAfter(4, "y");
String result = tokens.toString();
String expecting = "abxyba";
assertEquals(result, expecting);
}
示例15: testReplaceThenReplaceSuperset
import org.antlr.runtime.TokenRewriteStream; //导入方法依赖的package包/类
public void testReplaceThenReplaceSuperset() throws Exception {
Grammar g = new Grammar(
"lexer grammar t;\n"+
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n");
CharStream input = new ANTLRStringStream("abcccba");
Interpreter lexEngine = new Interpreter(g, input);
TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
tokens.LT(1); // fill buffer
tokens.replace(2, 4, "xyz");
tokens.replace(2, 5, "foo"); // kills previous replace
String result = tokens.toString();
String expecting = "abfooa";
assertEquals(result, expecting);
}