Search in sources :

Example 1 with ColonStatementLexer

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

the class ColonPrefixSqlParser method internalParse.

@Override
ParsedSql internalParse(String sql) {
    ParsedSql.Builder parsedSql = ParsedSql.builder();
    ColonStatementLexer lexer = new ColonStatementLexer(CharStreams.fromString(sql));
    lexer.addErrorListener(new ErrorListener());
    Token t = lexer.nextToken();
    while (t.getType() != EOF) {
        switch(t.getType()) {
            case COMMENT:
            case LITERAL:
            case QUOTED_TEXT:
            case DOUBLE_QUOTED_TEXT:
                parsedSql.append(t.getText());
                break;
            case NAMED_PARAM:
                parsedSql.appendNamedParameter(t.getText().substring(1));
                break;
            case POSITIONAL_PARAM:
                parsedSql.appendPositionalParameter();
                break;
            case ESCAPED_TEXT:
                parsedSql.append(t.getText().substring(1));
                break;
            default:
                break;
        }
        t = lexer.nextToken();
    }
    return parsedSql.build();
}
Also used : ErrorListener(org.jdbi.v3.core.statement.internal.ErrorListener) Token(org.antlr.v4.runtime.Token) ColonStatementLexer(org.jdbi.v3.core.internal.lexer.ColonStatementLexer)

Aggregations

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