Example usage for org.antlr.v4.runtime TokenSource nextToken

List of usage examples for org.antlr.v4.runtime TokenSource nextToken

Introduction

In this page you can find the example usage for org.antlr.v4.runtime TokenSource nextToken.

Prototype

public Token nextToken();

Source Link

Document

Return a Token object from your input stream (usually a CharStream ).

Usage

From source file:io.prestosql.sql.parser.StatementSplitter.java

License:Apache License

public StatementSplitter(String sql, Set<String> delimiters) {
    TokenSource tokens = getLexer(sql, delimiters);
    ImmutableList.Builder<Statement> list = ImmutableList.builder();
    StringBuilder sb = new StringBuilder();
    while (true) {
        Token token = tokens.nextToken();
        if (token.getType() == Token.EOF) {
            break;
        }/*w w  w.  j  a va2  s .c om*/
        if (token.getType() == SqlBaseParser.DELIMITER) {
            String statement = sb.toString().trim();
            if (!statement.isEmpty()) {
                list.add(new Statement(statement, token.getText()));
            }
            sb = new StringBuilder();
        } else {
            sb.append(token.getText());
        }
    }
    this.completeStatements = list.build();
    this.partialStatement = sb.toString().trim();
}

From source file:io.prestosql.sql.parser.StatementSplitter.java

License:Apache License

public static String squeezeStatement(String sql) {
    TokenSource tokens = getLexer(sql, ImmutableSet.of());
    StringBuilder sb = new StringBuilder();
    while (true) {
        Token token = tokens.nextToken();
        if (token.getType() == Token.EOF) {
            break;
        }//from www.  ja  v a 2 s  .  co m
        if (token.getType() == SqlBaseLexer.WS) {
            sb.append(' ');
        } else {
            sb.append(token.getText());
        }
    }
    return sb.toString().trim();
}

From source file:io.prestosql.sql.parser.StatementSplitter.java

License:Apache License

public static boolean isEmptyStatement(String sql) {
    TokenSource tokens = getLexer(sql, ImmutableSet.of());
    while (true) {
        Token token = tokens.nextToken();
        if (token.getType() == Token.EOF) {
            return true;
        }//  www. j av a2s.  com
        if (token.getChannel() != Token.HIDDEN_CHANNEL) {
            return false;
        }
    }
}