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


Java TokenRewriteStream.toOriginalString方法代码示例

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


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

示例1: testToStringStartStop

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

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

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

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

    result = tokens.toString(4,8);
    expecting = "0";
    assertEquals(expecting, result);
}
 
开发者ID:pcingola,项目名称:jFuzzyLogic,代码行数:34,代码来源:TestTokenRewriteStream.java

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