예제 #1
0
  private CommonTree parse(String filename) {
    try {
      final String sql = this.read(filename);

      final SqlLexer lexer = new SqlLexer(new ANTLRStringStream(sql));
      final CommonTokenStream tokenStream = new CommonTokenStream(lexer);
      final SqlParser parser = new SqlParser(tokenStream);

      final CommonTree tree = (CommonTree) parser.statements().getTree();

      final List<String> errors = parser.getErrors();
      if (errors.size() > 0) {
        final String errorMsg = Joiner.on("\n\t").skipNulls().join(errors);

        SqlTest.LOG.error(
            "Cannot parse query: {0}", //
            SqlTest.LOG.boxed(
                filename, //
                new Object[] {
                  "\n\t" + errorMsg,
                  "\n\n" + (tree != null ? CommonTreePrinter.toString(tree) : "") + "\n"
                }));

        throw new RuntimeException("Cannot parse the query:\n" + errorMsg.trim() + ".");
      }

      return tree;
    } catch (final RuntimeException e) {
      throw e;
    } catch (final Exception e) {
      throw new RuntimeException("Cannot parse input", e);
    }
  }
예제 #2
0
  /** @since 2.0.0 */
  @Test
  public void testSql() {
    SqlTest.LOG.debug("\n" + CommonTreePrinter.toString(this.parse("1.sql")) + "\n");

    SqlTest.LOG.debug("\n" + CommonTreePrinter.toString(this.parse("2.sql")) + "\n");
  }
예제 #3
0
 /** @since 2.0.0 */
 @Test
 @Ignore
 public void testSqlLarge() {
   SqlTest.LOG.debug("\n" + CommonTreePrinter.toString(this.parse("3.sql")) + "\n");
 }