Search in sources :

Example 1 with Paragraph

use of us.parr.bookish.model.Paragraph 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);
}
Also used : OutputModelObject(us.parr.bookish.model.OutputModelObject) PreAbstract(us.parr.bookish.model.PreAbstract) ArrayList(java.util.ArrayList) ParseTree(org.antlr.v4.runtime.tree.ParseTree) Paragraph(us.parr.bookish.model.Paragraph)

Example 2 with Paragraph

use of us.parr.bookish.model.Paragraph 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);
}
Also used : OutputModelObject(us.parr.bookish.model.OutputModelObject) Abstract(us.parr.bookish.model.Abstract) PreAbstract(us.parr.bookish.model.PreAbstract) ArrayList(java.util.ArrayList) ParseTree(org.antlr.v4.runtime.tree.ParseTree) Paragraph(us.parr.bookish.model.Paragraph)

Example 3 with Paragraph

use of us.parr.bookish.model.Paragraph in project bookish by parrt.

the class Translator method visitSidefig.

// figure    : FIGURE attrs END_OF_TAG paragraph_content END_FIGURE
@Override
public OutputModelObject visitSidefig(BookishParser.SidefigContext ctx) {
    String label = ctx.attrs.attrMap.get("label");
    EntityDef def = null;
    if (label != null) {
        def = document.getEntity(label);
        if (def == null) {
            System.err.printf("line %d: Unknown label '%s'\n", ctx.start.getLine(), label);
            return null;
        }
    }
    Paragraph p = (Paragraph) visit(ctx.paragraph_content());
    TextBlock figText = new TextBlock(p.elements);
    SideFigure f = new SideFigure(def, label, figText, ctx.attrs.attrMap);
    if (def != null) {
        def.model = f;
    }
    // a ref will make this appear
    return null;
}
Also used : SideFigure(us.parr.bookish.model.SideFigure) TextBlock(us.parr.bookish.model.TextBlock) EntityDef(us.parr.bookish.model.entity.EntityDef) Paragraph(us.parr.bookish.model.Paragraph)

Example 4 with Paragraph

use of us.parr.bookish.model.Paragraph 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);
}
Also used : OutputModelObject(us.parr.bookish.model.OutputModelObject) ArrayList(java.util.ArrayList) ParseTree(org.antlr.v4.runtime.tree.ParseTree) BookishParser(us.parr.bookish.parse.BookishParser) EntityDef(us.parr.bookish.model.entity.EntityDef) Paragraph(us.parr.bookish.model.Paragraph)

Aggregations

Paragraph (us.parr.bookish.model.Paragraph)4 ArrayList (java.util.ArrayList)3 ParseTree (org.antlr.v4.runtime.tree.ParseTree)3 OutputModelObject (us.parr.bookish.model.OutputModelObject)3 PreAbstract (us.parr.bookish.model.PreAbstract)2 EntityDef (us.parr.bookish.model.entity.EntityDef)2 Abstract (us.parr.bookish.model.Abstract)1 SideFigure (us.parr.bookish.model.SideFigure)1 TextBlock (us.parr.bookish.model.TextBlock)1 BookishParser (us.parr.bookish.parse.BookishParser)1