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;
}
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);
}
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);
}
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);
}
Aggregations