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()) {
                // EOF ends parsing
                case Token.EOF:
                    endOfFile = true;
                    break;
                // Strip comments out
                case COMMENT:
                case MULTI_LINE_COMMENT:
                    break;
                // collapse newlines
                case NEWLINES:
                    if (sb.length() > 0) {
                        sb.append('\n');
                    }
                    break;
                // everything else is done by the handler
                case SEMICOLON:
                case BLOCK_BEGIN:
                case BLOCK_END:
                case QUOTED_TEXT:
                case LITERAL:
                case OTHER:
                    tokenHandler.handle(t, sb);
                    break;
                default:
                    throw new IllegalArgumentException("Unrecognizable token " + t);
            }
        }
        return sb.toString();
    }
An SQL script parser.

<p>It performs lexical analysis of a script and generates events for semicolons.
As a result it returns a script without comments and newlines.</p>
core/src/main/java/org/jdbi/v3/core/internal/SqlScriptParser.java