use of org.antlr.v4.runtime.ConsoleErrorListener in project bookish by parrt.
the class Tool method translateString.
public String translateString(Translator trans, String markdown, String startRule) throws Exception {
CharStream input = CharStreams.fromString(markdown);
BookishLexer lexer = new BookishLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
BookishParser parser = new BookishParser(tokens, null, 0);
parser.removeErrorListeners();
parser.addErrorListener(new ConsoleErrorListener() {
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
msg = "Parsing author string: " + msg;
super.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e);
}
});
Method startMethod = BookishParser.class.getMethod(startRule, (Class[]) null);
ParseTree doctree = (ParseTree) startMethod.invoke(parser, (Object[]) null);
// get single chapter
OutputModelObject omo = trans.visit(doctree);
ModelConverter converter = new ModelConverter(trans.templates);
ST outputST = converter.walk(omo);
return outputST.render();
}
Aggregations