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


Java TokenRewriteStream.insertAfter方法代码示例

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


在下文中一共展示了TokenRewriteStream.insertAfter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testReplaceThenInsertAfterLastIndex

import org.antlr.runtime.TokenRewriteStream; //导入方法依赖的package包/类
public void testReplaceThenInsertAfterLastIndex() 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.insertAfter(2, "y");
	String result = tokens.toString();
	String expecting = "abxy";
	assertEquals(result, expecting);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:17,代码来源:TestTokenRewriteStream.java

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

示例4: 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

示例5: testReplaceThenInsertAfterLastIndex

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

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

示例7: testInsertAfterLastIndex

import org.antlr.runtime.TokenRewriteStream; //导入方法依赖的package包/类
public void testInsertAfterLastIndex() 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.insertAfter(2, "x");
	String result = tokens.toString();
	String expecting = "abcx";
	assertEquals(result, expecting);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:16,代码来源:TestTokenRewriteStream.java

示例8: testInsertAfterLastIndex

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

示例9: testToStringStartStop2

import org.antlr.runtime.TokenRewriteStream; //导入方法依赖的package包/类
public void testToStringStartStop2() throws Exception {
    Grammar g = new Grammar(
        "lexer grammar t;\n"+
        "ID : 'a'..'z'+;\n" +
        "INT : '0'..'9'+;\n" +
        "SEMI : ';';\n" +
        "ASSIGN : '=';\n" +
        "PLUS : '+';\n" +
        "MULT : '*';\n" +
        "WS : ' '+;\n");
    // Tokens: 012345678901234567
    // Input:  x = 3 * 0 + 2 * 0;
    CharStream input = new ANTLRStringStream("x = 3 * 0 + 2 * 0;");
    Interpreter lexEngine = new Interpreter(g, input);
    TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
    tokens.LT(1); // fill buffer

    String result = tokens.toOriginalString();
    String expecting = "x = 3 * 0 + 2 * 0;";
    assertEquals(expecting, result);

    tokens.replace(4, 8, "0"); // replace 3 * 0 with 0
    result = tokens.toString();
    expecting = "x = 0 + 2 * 0;";
    assertEquals(expecting, result);

    result = tokens.toString(0,17);
    expecting = "x = 0 + 2 * 0;";
    assertEquals(expecting, result);

    result = tokens.toString(4,8);
    expecting = "0";
    assertEquals(expecting, result);

    result = tokens.toString(0,8);
    expecting = "x = 0";
    assertEquals(expecting, result);

    result = tokens.toString(12,16);
    expecting = "2 * 0";
    assertEquals(expecting, result);

    tokens.insertAfter(17, "// comment");
    result = tokens.toString(12,17);
    expecting = "2 * 0;// comment";
    assertEquals(expecting, result);

    result = tokens.toString(0,8); // try again after insert at end
    expecting = "x = 0";
    assertEquals(expecting, result);
}
 
开发者ID:pcingola,项目名称:jFuzzyLogic,代码行数:52,代码来源:TestTokenRewriteStream.java


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