use of org.antlr.v4.runtime.Lexer in project bookish by parrt.
the class Tool method parseChapter.
public Pair<BookishParser.DocumentContext, BookishParser> parseChapter(String inputDir, String inputFilename, int chapNumber) throws IOException {
CharStream input = CharStreams.fromFileName(inputDir + "/" + inputFilename);
BookishLexer lexer = new BookishLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
BookishParser parser = new BookishParser(tokens, inputFilename, chapNumber);
BookishParser.DocumentContext doctree = parser.document();
return new Pair<>(doctree, parser);
}
use of org.antlr.v4.runtime.Lexer 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 org.antlr.v4.runtime.Lexer 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 org.antlr.v4.runtime.Lexer in project kripton by xcesco.
the class ContentUriChecker method preparePath.
private Pair<ParserRuleContext, CommonTokenStream> preparePath(final String input) {
UriLexer lexer = new UriLexer(CharStreams.fromString(input));
CommonTokenStream tokens = new CommonTokenStream(lexer);
UriParser parser = new UriParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(new ContentUriBaseErrorListener() {
@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, input);
}
});
ParserRuleContext context = parser.path();
return new Pair<>(context, tokens);
}
use of org.antlr.v4.runtime.Lexer in project kripton by xcesco.
the class ContentUriChecker method prepareUri.
private Pair<ParserRuleContext, CommonTokenStream> prepareUri(final String input) {
UriLexer lexer = new UriLexer(CharStreams.fromString(input));
CommonTokenStream tokens = new CommonTokenStream(lexer);
UriParser parser = new UriParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(new ContentUriBaseErrorListener() {
@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 URI '%s'", charPositionInLine, input);
}
@Override
public void reportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, boolean exact, BitSet ambigAlts, ATNConfigSet configs) {
AssertKripton.assertTrue(false, "ambiguity syntax at pos %s of URI '%s'", startIndex, input);
}
@Override
public void reportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex, int stopIndex, BitSet conflictingAlts, ATNConfigSet configs) {
AssertKripton.assertTrue(false, "error at pos %s of URI '%s'", startIndex, input);
}
@Override
public void reportContextSensitivity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, int prediction, ATNConfigSet configs) {
AssertKripton.assertTrue(false, "context eror at pos %s of URI '%s'", startIndex, input);
}
});
ParserRuleContext context = parser.uri();
return new Pair<>(context, tokens);
}
Aggregations