Search in sources :

Example 1 with JqlLexer

use of com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlLexer in project kripton by xcesco.

the class SQLiteSchemaVerifierHelper method extractCommands.

static List<String> extractCommands(SQLiteDatabase database, InputStream inputStream) {
    final List<String> result = new ArrayList<>();
    final String input = IOUtils.readText(inputStream);
    JqlLexer lexer = new JqlLexer(CharStreams.fromString(input));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    JqlParser parser = new JqlParser(tokens);
    ParserRuleContext parseContext = parser.parse();
    ParseTreeWalker walk = new ParseTreeWalker();
    walk.walk(new JqlBaseListener() {

        @Override
        public void enterSql_stmt(Sql_stmtContext ctx) {
            int start = ctx.getStart().getStartIndex();
            int stop = ctx.getStop().getStopIndex() + 1;
            if (start == stop)
                return;
            result.add(input.substring(start, stop));
        }
    }, parseContext);
    return result;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) JqlLexer(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlLexer) ArrayList(java.util.ArrayList) JqlBaseListener(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlBaseListener) JqlParser(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser) Sql_stmtContext(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Sql_stmtContext) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker)

Example 2 with JqlLexer

use of com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlLexer in project kripton by xcesco.

the class MigrationSQLChecker method prepareParser.

protected Pair<ParserRuleContext, CommonTokenStream> prepareParser(final String jql) {
    JqlLexer lexer = new JqlLexer(CharStreams.fromString(jql));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    JqlParser parser = new JqlParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(new JQLBaseErrorListener() {

        @Override
        public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
            AssertKripton.assertTrue(false, "unespected char at pos %s of SQL '%s'", charPositionInLine, jql);
        }
    });
    ParserRuleContext context = parser.parse();
    return new Pair<>(context, tokens);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) JqlLexer(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlLexer) JqlParser(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser) RecognitionException(org.antlr.v4.runtime.RecognitionException) Pair(com.abubusoft.kripton.common.Pair)

Example 3 with JqlLexer

use of com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlLexer in project kripton by xcesco.

the class JQLChecker method prepareParser.

protected Pair<ParserRuleContext, CommonTokenStream> prepareParser(final JQLContext jqlContext, final String jql) {
    JqlLexer lexer = new JqlLexer(CharStreams.fromString(jql));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    JqlParser parser = new JqlParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(new JQLBaseErrorListener() {

        @Override
        public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
            AssertKripton.assertTrue(false, jqlContext.getContextDescription() + ": unespected char at pos %s of SQL '%s'", charPositionInLine, jql);
        }
    });
    ParserRuleContext context = parser.parse();
    return new Pair<>(context, tokens);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) JqlLexer(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlLexer) JqlParser(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser) RecognitionException(org.antlr.v4.runtime.RecognitionException) Pair(com.abubusoft.kripton.common.Pair)

Example 4 with JqlLexer

use of com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlLexer in project kripton by xcesco.

the class JQLChecker method prepareVariableStatement.

/**
 * <p>
 * Parse the variable parts of a SQL:
 * </p>
 *
 * <ul>
 * <li>where_stmt</li>
 * <li>group_stmt</li>
 * <li>having_stmt</li>
 * <li>order_stmt</li>
 * <li>limit_stmt</li>
 * <li>offset_stmt</li>
 * </ul>
 *
 * @param jql
 * @return
 */
protected Pair<ParserRuleContext, CommonTokenStream> prepareVariableStatement(final JQLContext jqlContext, final String jql) {
    JqlLexer lexer = new JqlLexer(CharStreams.fromString(jql));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    JqlParser parser = new JqlParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(new JQLBaseErrorListener() {

        @Override
        public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
            AssertKripton.assertTrue(false, jqlContext.getContextDescription() + ": unespected char at pos %s of JQL '%s'", charPositionInLine, jql);
        }
    });
    ParserRuleContext context = parser.parse_variable();
    return new Pair<>(context, tokens);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) JqlLexer(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlLexer) JqlParser(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser) RecognitionException(org.antlr.v4.runtime.RecognitionException) Pair(com.abubusoft.kripton.common.Pair)

Aggregations

JqlLexer (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlLexer)4 JqlParser (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser)4 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)4 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)4 Pair (com.abubusoft.kripton.common.Pair)3 RecognitionException (org.antlr.v4.runtime.RecognitionException)3 JqlBaseListener (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlBaseListener)1 Sql_stmtContext (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Sql_stmtContext)1 ArrayList (java.util.ArrayList)1 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)1