Search in sources :

Example 1 with SqlScriptLexer

use of org.jdbi.v3.core.internal.lexer.SqlScriptLexer in project jdbi by jdbi.

the class SqlScriptParser method parse.

public String parse(CharStream charStream) {
    StringBuilder sb = new StringBuilder();
    SqlScriptLexer lexer = new SqlScriptLexer(charStream);
    lexer.addErrorListener(new ErrorListener());
    boolean endOfFile = false;
    while (!endOfFile) {
        Token t = lexer.nextToken();
        switch(t.getType()) {
            case Token.EOF:
                endOfFile = true;
                break;
            case SqlScriptLexer.SEMICOLON:
                semicolonHandler.handle(t, sb);
                break;
            case SqlScriptLexer.COMMENT:
            case SqlScriptLexer.MULTI_LINE_COMMENT:
                break;
            case SqlScriptLexer.NEWLINES:
                if (sb.length() > 0) {
                    sb.append(' ');
                }
                break;
            case SqlScriptLexer.QUOTED_TEXT:
            case SqlScriptLexer.LITERAL:
            case SqlScriptLexer.OTHER:
                sb.append(t.getText());
                break;
            default:
                throw new IllegalArgumentException("Unrecognizable token " + t);
        }
    }
    return sb.toString();
}
Also used : ErrorListener(org.jdbi.v3.core.statement.internal.ErrorListener) Token(org.antlr.v4.runtime.Token) SqlScriptLexer(org.jdbi.v3.core.internal.lexer.SqlScriptLexer)

Aggregations

Token (org.antlr.v4.runtime.Token)1 SqlScriptLexer (org.jdbi.v3.core.internal.lexer.SqlScriptLexer)1 ErrorListener (org.jdbi.v3.core.statement.internal.ErrorListener)1