Examples of ParseTreePatternMatcher


Examples of org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher

   * {@link Lexer} rather than trying to deduce it from this parser.
   */
  public ParseTreePattern compileParseTreePattern(String pattern, int patternRuleIndex,
                          Lexer lexer)
  {
    ParseTreePatternMatcher m = new ParseTreePatternMatcher(lexer, this);
    return m.compile(pattern, patternRuleIndex);
  }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher

import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class TestParseTreeMatcher extends BaseTest {
  @Test public void testChunking() throws Exception {
    ParseTreePatternMatcher m = new ParseTreePatternMatcher(null, null);
    assertEquals("[ID, ' = ', expr, ' ;']", m.split("<ID> = <expr> ;").toString());
    assertEquals("[' ', ID, ' = ', expr]", m.split(" <ID> = <expr>").toString());
    assertEquals("[ID, ' = ', expr]", m.split("<ID> = <expr>").toString());
    assertEquals("[expr]", m.split("<expr>").toString());
    assertEquals("['<x> foo']", m.split("\\<x\\> foo").toString());
    assertEquals("['foo <x> bar ', tag]", m.split("foo \\<x\\> bar <tag>").toString());
  }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher

    assertEquals("['<x> foo']", m.split("\\<x\\> foo").toString());
    assertEquals("['foo <x> bar ', tag]", m.split("foo \\<x\\> bar <tag>").toString());
  }

  @Test public void testDelimiters() throws Exception {
    ParseTreePatternMatcher m = new ParseTreePatternMatcher(null, null);
    m.setDelimiters("<<", ">>", "$");
    String result = m.split("<<ID>> = <<expr>> ;$<< ick $>>").toString();
    assertEquals("[ID, ' = ', expr, ' ;<< ick >>']", result);
  }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher

    String result = m.split("<<ID>> = <<expr>> ;$<< ick $>>").toString();
    assertEquals("[ID, ' = ', expr, ' ;<< ick >>']", result);
  }

  @Test public void testInvertedTags() throws Exception {
    ParseTreePatternMatcher m= new ParseTreePatternMatcher(null, null);
    String result = null;
    try {
      m.split(">expr<");
    }
    catch (IllegalArgumentException iae) {
      result = iae.getMessage();
    }
    String expected = "tag delimiters out of order in pattern: >expr<";
View Full Code Here

Examples of org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher

    String expected = "tag delimiters out of order in pattern: >expr<";
    assertEquals(expected, result);
  }

  @Test public void testUnclosedTag() throws Exception {
    ParseTreePatternMatcher m = new ParseTreePatternMatcher(null, null);
    String result = null;
    try {
      m.split("<expr hi mom");
    }
    catch (IllegalArgumentException iae) {
      result = iae.getMessage();
    }
    String expected = "unterminated tag in pattern: <expr hi mom";
View Full Code Here

Examples of org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher

    String expected = "unterminated tag in pattern: <expr hi mom";
    assertEquals(expected, result);
  }

  @Test public void testExtraClose() throws Exception {
    ParseTreePatternMatcher m = new ParseTreePatternMatcher(null, null);
    String result = null;
    try {
      m.split("<expr> >");
    }
    catch (IllegalArgumentException iae) {
      result = iae.getMessage();
    }
    String expected = "missing start tag in pattern: <expr> >";
View Full Code Here

Examples of org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher

      "WS : [ \\r\\n\\t]+ -> skip ;\n";
    boolean ok =
      rawGenerateAndBuildRecognizer("X1.g4", grammar, "X1Parser", "X1Lexer", false);
    assertTrue(ok);

    ParseTreePatternMatcher m = getPatternMatcher("X1");

    List<? extends Token> tokens = m.tokenize("<ID> = <expr> ;");
    String results = tokens.toString();
    String expected = "[ID:3, [@-1,1:1='=',<1>,1:1], expr:7, [@-1,1:1=';',<2>,1:1]]";
    assertEquals(expected, results);
  }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher

      "WS : [ \\r\\n\\t]+ -> skip ;\n";
    boolean ok =
      rawGenerateAndBuildRecognizer("X2.g4", grammar, "X2Parser", "X2Lexer", false);
    assertTrue(ok);

    ParseTreePatternMatcher m = getPatternMatcher("X2");

    ParseTreePattern t = m.compile("<ID> = <expr> ;", m.getParser().getRuleIndex("s"));
    String results = t.getPatternTree().toStringTree(m.getParser());
    String expected = "(s <ID> = (expr <expr>) ;)";
    assertEquals(expected, results);
  }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher

      "WS : [ \\r\\n\\t]+ -> skip ;\n";
    boolean ok =
      rawGenerateAndBuildRecognizer("X2.g4", grammar, "X2Parser", "X2Lexer", false);
    assertTrue(ok);

    ParseTreePatternMatcher m = getPatternMatcher("X2");

    boolean failed = false;
    try {
      m.compile("<ID> = <expr> ; extra", m.getParser().getRuleIndex("s"));
    }
    catch (ParseTreePatternMatcher.StartRuleDoesNotConsumeFullPattern e) {
      failed = true;
    }
    assertTrue(failed);
View Full Code Here

Examples of org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher

      "WS : [ \\r\\n\\t]+ -> skip ;\n";
    boolean ok =
      rawGenerateAndBuildRecognizer("X2.g4", grammar, "X2Parser", "X2Lexer", false);
    assertTrue(ok);

    ParseTreePatternMatcher m = getPatternMatcher("X2");

    boolean failed = false;
    try {
      m.compile("<ID> ;", m.getParser().getRuleIndex("s"));
    }
    catch (InputMismatchException e) {
      failed = true;
    }
    assertTrue(failed);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.