Exemplo n.º 1
0
  public List<String> getNodeStrings(
      String input, String xpath, String startRuleName, String parserName, String lexerName)
      throws Exception {
    Pair<Parser, Lexer> pl = getParserAndLexer(input, parserName, lexerName);
    Parser parser = pl.a;
    ParseTree tree = execStartRule(startRuleName, parser);

    List<String> nodes = new ArrayList<String>();
    for (ParseTree t : XPath.findAll(tree, xpath, parser)) {
      if (t instanceof RuleContext) {
        RuleContext r = (RuleContext) t;
        nodes.add(parser.getRuleNames()[r.getRuleIndex()]);
      } else {
        TerminalNode token = (TerminalNode) t;
        nodes.add(token.getText());
      }
    }
    return nodes;
  }
Exemplo n.º 2
0
  protected void testError(
      String input,
      String path,
      String expected,
      String startRuleName,
      String parserName,
      String lexerName)
      throws Exception {
    Pair<Parser, Lexer> pl = getParserAndLexer(input, parserName, lexerName);
    Parser parser = pl.a;
    ParseTree tree = execStartRule(startRuleName, parser);

    IllegalArgumentException e = null;
    try {
      XPath.findAll(tree, path, parser);
    } catch (IllegalArgumentException iae) {
      e = iae;
    }
    assertNotNull(e);
    assertEquals(expected, e.getMessage());
  }