use of us.parr.bookish.parse.BookishLexer 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 us.parr.bookish.parse.BookishLexer 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);
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