use of us.parr.bookish.model.OutputModelObject in project bookish by parrt.
the class Translator method visitPreabstract.
@Override
public OutputModelObject visitPreabstract(BookishParser.PreabstractContext ctx) {
List<OutputModelObject> paras = new ArrayList<>();
paras.add(visit(ctx.paragraph_optional_blank_line()));
for (ParseTree p : ctx.paragraph()) {
Paragraph para = (Paragraph) visit(p);
paras.add(para);
}
return new PreAbstract(paras);
}
use of us.parr.bookish.model.OutputModelObject in project bookish by parrt.
the class Translator method visitAbstract_.
@Override
public OutputModelObject visitAbstract_(BookishParser.Abstract_Context ctx) {
List<OutputModelObject> paras = new ArrayList<>();
paras.add(visit(ctx.paragraph_optional_blank_line()));
for (ParseTree p : ctx.paragraph()) {
Paragraph para = (Paragraph) visit(p);
paras.add(para);
}
return new Abstract(paras);
}
use of us.parr.bookish.model.OutputModelObject in project bookish by parrt.
the class Translator method visitSection_content.
@Override
public OutputModelObject visitSection_content(BookishParser.Section_contentContext ctx) {
if (ctx.children == null) {
return null;
}
List<OutputModelObject> elements = new ArrayList<>();
for (ParseTree el : ctx.children) {
OutputModelObject m = visit(el);
elements.add(m);
}
return new Join(elements);
}
use of us.parr.bookish.model.OutputModelObject in project bookish by parrt.
the class Translator method visitChapter.
@Override
public OutputModelObject visitChapter(BookishParser.ChapterContext ctx) {
String title = ctx.chap.getText();
title = title.substring(title.indexOf(' ') + 1).trim();
Pair<String, String> results = splitSectionTitle(title);
title = results.a;
String anchor = results.b;
EntityDef def = null;
if (anchor != null) {
def = document.getEntity(anchor);
if (def == null) {
System.err.printf("line %d: Unknown label '%s'\n", ctx.start.getLine(), anchor);
return null;
}
}
OutputModelObject auth = null;
if (ctx.author() != null) {
auth = visit(ctx.author());
}
OutputModelObject preabs = null;
if (ctx.preabstract() != null) {
preabs = visit(ctx.preabstract());
}
OutputModelObject abs = null;
if (ctx.abstract_() != null) {
abs = visit(ctx.abstract_());
}
List<ContainerWithTitle> sections = new ArrayList<>();
for (ParseTree el : ctx.children) {
if (el instanceof BookishParser.SectionContext) {
OutputModelObject m = visit(el);
sections.add((Section) m);
}
}
Join sec = (Join) visitSection_content(ctx.section_content());
Chapter chapter = new Chapter(def, title, null, (Author) auth, (PreAbstract) preabs, (Abstract) abs, sec != null ? sec.elements : null, sections);
return chapter;
}
use of us.parr.bookish.model.OutputModelObject in project bookish by parrt.
the class Translator method visitParagraph_content.
@Override
public OutputModelObject visitParagraph_content(BookishParser.Paragraph_contentContext ctx) {
List<OutputModelObject> elements = new ArrayList<>();
for (ParseTree el : ctx.children) {
OutputModelObject c = visit(el);
if (c != null) {
elements.add(c);
}
}
// find all REFs within paragraph
Collection<ParseTree> refNodes = XPath.findAll(ctx, "//REF", new BookishParser(null));
List<EntityDef> entitiesRefd = new ArrayList<>();
for (ParseTree t : refNodes) {
String label = stripQuotes(t.getText());
EntityDef def = document.getEntity(label);
if (def != null) {
if (!book.entitiesRendered.contains(def) && !document.entitiesRendered.contains(def)) {
// Nobody has shown it yet
entitiesRefd.add(def);
if (document.entitiesRendered.contains(def)) {
document.entitiesRendered.add(def);
}
if (book.entitiesRendered.contains(def)) {
book.entitiesRendered.add(def);
}
}
} else {
System.err.printf("line %d: Unknown label '%s'\n", ctx.start.getLine(), label);
}
}
return new Paragraph(elements, entitiesRefd);
}
Aggregations