当前位置: 首页>>代码示例>>Java>>正文


Java TokenRewriteStream.insertBefore方法代码示例

本文整理汇总了Java中org.antlr.runtime.TokenRewriteStream.insertBefore方法的典型用法代码示例。如果您正苦于以下问题:Java TokenRewriteStream.insertBefore方法的具体用法?Java TokenRewriteStream.insertBefore怎么用?Java TokenRewriteStream.insertBefore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.antlr.runtime.TokenRewriteStream的用法示例。


在下文中一共展示了TokenRewriteStream.insertBefore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:17,代码来源:TestTokenRewriteStream.java

示例2: 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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:17,代码来源:TestTokenRewriteStream.java

示例3: 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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:18,代码来源:TestTokenRewriteStream.java

示例4: 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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:17,代码来源:TestTokenRewriteStream.java

示例5: 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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:17,代码来源:TestTokenRewriteStream.java

示例6: 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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:18,代码来源:TestTokenRewriteStream.java

示例7: 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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:17,代码来源:TestTokenRewriteStream.java

示例8: 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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:17,代码来源:TestTokenRewriteStream.java

示例9: 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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:17,代码来源:TestTokenRewriteStream.java

示例10: 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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:17,代码来源:TestTokenRewriteStream.java

示例11: 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);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:17,代码来源:TestTokenRewriteStream.java

示例12: 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(expecting, result);
}
 
开发者ID:pcingola,项目名称:jFuzzyLogic,代码行数:17,代码来源:TestTokenRewriteStream.java

示例13: test2ReplaceMiddleIndex1InsertBefore

import org.antlr.runtime.TokenRewriteStream; //导入方法依赖的package包/类
public void test2ReplaceMiddleIndex1InsertBefore() 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, "_");
       tokens.replace(1, "x");
	tokens.replace(1, "y");
	String result = tokens.toString();
	String expecting = "_ayc";
	assertEquals(expecting, result);
}
 
开发者ID:pcingola,项目名称:jFuzzyLogic,代码行数:18,代码来源:TestTokenRewriteStream.java

示例14: testInsertInPriorReplace

import org.antlr.runtime.TokenRewriteStream; //导入方法依赖的package包/类
public void testInsertInPriorReplace() 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, 2, "x");
	tokens.insertBefore(1, "0");
	Exception exc = null;
	try {
		tokens.toString();
	}
	catch (IllegalArgumentException iae) {
		exc = iae;
	}
	String expecting = "insert op <[email protected]:\"0\"> within boundaries of previous <[email protected]:\"x\">";
	assertNotNull(exc);
	assertEquals(expecting, exc.getMessage());
}
 
开发者ID:pcingola,项目名称:jFuzzyLogic,代码行数:24,代码来源:TestTokenRewriteStream.java

示例15: 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"); // supercedes insert at 0
	String result = tokens.toString();
	String expecting = "xbc";
	assertEquals(expecting, result);
}
 
开发者ID:pcingola,项目名称:jFuzzyLogic,代码行数:17,代码来源:TestTokenRewriteStream.java


注:本文中的org.antlr.runtime.TokenRewriteStream.insertBefore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。