Example usage for org.antlr.v4.runtime CommonTokenStream setTokenSource

List of usage examples for org.antlr.v4.runtime CommonTokenStream setTokenSource

Introduction

In this page you can find the example usage for org.antlr.v4.runtime CommonTokenStream setTokenSource.

Prototype

public void setTokenSource(TokenSource tokenSource) 

Source Link

Document

Reset this token stream by setting its token source.

Usage

From source file:com.antsdb.saltedfish.sql.mysql.ExprGenerator.java

License:Open Source License

public static Operator gen(GeneratorContext ctx, Planner cursorMeta, String expr) {
    CharStream cs = new ANTLRInputStream(expr);
    MysqlLexer lexer = new MysqlLexer(cs);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    tokens.setTokenSource(lexer);
    MysqlParser parser = new MysqlParser(tokens);
    parser.setErrorHandler(new BailErrorStrategy());
    MysqlParser.ExprContext rule = parser.expr();
    return gen(ctx, cursorMeta, rule);
}

From source file:com.antsdb.saltedfish.sql.mysql.MysqlParserFactory.java

License:Open Source License

static MysqlParser.ScriptContext parse(CharStream cs) {
    if (isCommtedStatement(cs)) {
        String s = cs.toString();
        s = s.substring(9);/*from w ww  .j  a  va2s  . c  o m*/
        s = s.substring(0, s.length() - 3);
        cs = new ANTLRInputStream(s);
    }
    MysqlLexer lexer = new MysqlLexer(cs);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    tokens.setTokenSource(lexer);
    MysqlParser parser = new MysqlParser(tokens);
    parser.setErrorHandler(new BailErrorStrategy());
    boolean success = false;
    try {
        MysqlParser.ScriptContext script = parser.script();
        success = true;
        return script;
    } finally {
        if (!success && (parser.lastStatement != null)) {
            _log.debug("last passed statement: {}", ((ParseTree) parser.lastStatement).getText());
        }
    }
}