Package org.antlr.v4.tool

Examples of org.antlr.v4.tool.LexerGrammar


    String expecting = "barc";
    assertEquals(expecting, result);
  }

  @Test public void testOverlappingReplace4() throws Exception {
    LexerGrammar g = new LexerGrammar(
                       "lexer grammar T;\n"+
                       "A : 'a';\n" +
                       "B : 'b';\n" +
                       "C : 'c';\n");
    String input = "abcc";
    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.replace(1, 2, "foo");
    tokens.replace(1, 3, "bar");
View Full Code Here


    String expecting = "abar";
    assertEquals(expecting, result);
  }

  @Test public void testDropIdenticalReplace() throws Exception {
    LexerGrammar g = new LexerGrammar(
                       "lexer grammar T;\n"+
                       "A : 'a';\n" +
                       "B : 'b';\n" +
                       "C : 'c';\n");
    String input = "abcc";
    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.replace(1, 2, "foo");
    tokens.replace(1, 2, "foo");
View Full Code Here

    String expecting = "afooc";
    assertEquals(expecting, result);
  }

  @Test public void testDropPrevCoveredInsert() throws Exception {
    LexerGrammar g = new LexerGrammar(
                       "lexer grammar T;\n"+
                       "A : 'a';\n" +
                       "B : 'b';\n" +
                       "C : 'c';\n");
    String input = "abc";
    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.insertBefore(1, "foo");
    tokens.replace(1, 2, "foo");
View Full Code Here

    String expecting = "afoofoo";
    assertEquals(expecting, result);
  }

  @Test public void testLeaveAloneDisjointInsert() throws Exception {
    LexerGrammar g = new LexerGrammar(
                       "lexer grammar T;\n"+
                       "A : 'a';\n" +
                       "B : 'b';\n" +
                       "C : 'c';\n");
    String input = "abcc";
    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.insertBefore(1, "x");
    tokens.replace(2, 3, "foo");
View Full Code Here

    String expecting = "axbfoo";
    assertEquals(expecting, result);
  }

  @Test public void testLeaveAloneDisjointInsert2() throws Exception {
    LexerGrammar g = new LexerGrammar(
                       "lexer grammar T;\n"+
                       "A : 'a';\n" +
                       "B : 'b';\n" +
                       "C : 'c';\n");
    String input = "abcc";
    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.replace(2, 3, "foo");
    tokens.insertBefore(1, "x");
View Full Code Here

    String expecting = "axbfoo";
    assertEquals(expecting, result);
  }

  @Test public void testInsertBeforeTokenThenDeleteThatToken() throws Exception {
    LexerGrammar g = new LexerGrammar(
                       "lexer grammar T;\n"+
                       "A : 'a';\n" +
                       "B : 'b';\n" +
                       "C : 'c';\n");
    String input = "abc";
    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.insertBefore(2, "y");
    tokens.delete(2);
View Full Code Here

  // NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH
  // NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH

public class TestATNInterpreter extends BaseTest {
  @Test public void testSimpleNoBlock() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n" +
      "A : 'a' ;\n" +
      "B : 'b' ;\n" +
      "C : 'c' ;\n");
    Grammar g = new Grammar(
View Full Code Here

      "a : A B ;");
    checkMatchedAlt(lg, g, "ab", 1);
  }

  @Test public void testSet() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n" +
      "A : 'a' ;\n" +
      "B : 'b' ;\n" +
      "C : 'c' ;\n");
    Grammar g = new Grammar(
View Full Code Here

      "a : ~A ;");
    checkMatchedAlt(lg, g, "b", 1);
  }

  @Test public void testPEGAchillesHeel() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n" +
      "A : 'a' ;\n" +
      "B : 'b' ;\n" +
      "C : 'c' ;\n");
    Grammar g = new Grammar(
View Full Code Here

    checkMatchedAlt(lg, g, "ab", 2);
    checkMatchedAlt(lg, g, "abc", 2);
  }

  @Test public void testMustTrackPreviousGoodAlt() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n" +
      "A : 'a' ;\n" +
      "B : 'b' ;\n" +
      "C : 'c' ;\n");
    Grammar g = new Grammar(
View Full Code Here

TOP

Related Classes of org.antlr.v4.tool.LexerGrammar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.