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); } }
/** @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"); }
/** @since 2.0.0 */ @Test @Ignore public void testSqlLarge() { SqlTest.LOG.debug("\n" + CommonTreePrinter.toString(this.parse("3.sql")) + "\n"); }