Search in sources :

Example 6 with EntityDef

use of us.parr.bookish.model.entity.EntityDef 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 7 with EntityDef

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

Example 8 with EntityDef

use of us.parr.bookish.model.entity.EntityDef in project bookish by parrt.

the class Translator method visitSidequote.

@Override
public OutputModelObject visitSidequote(BookishParser.SidequoteContext ctx) {
    String label = null;
    EntityDef def = null;
    if (ctx.REF() != null) {
        label = stripQuotes(ctx.REF().getText());
        def = document.getEntity(label);
        if (def == null) {
            System.err.printf("line %d: Unknown label '%s'\n", ctx.start.getLine(), label);
        }
    }
    SideQuote q = new SideQuote(def, label, (TextBlock) visit(ctx.q), (TextBlock) visit(ctx.a));
    if (def != null) {
        def.model = q;
    }
    if (label == null) {
        // if no label, insert inline here
        return q;
    }
    return null;
}
Also used : SideQuote(us.parr.bookish.model.SideQuote) EntityDef(us.parr.bookish.model.entity.EntityDef)

Example 9 with EntityDef

use of us.parr.bookish.model.entity.EntityDef in project bookish by parrt.

the class Translator method visitSidenote.

@Override
public OutputModelObject visitSidenote(BookishParser.SidenoteContext ctx) {
    String label = null;
    EntityDef def = null;
    if (ctx.REF() != null) {
        label = stripQuotes(ctx.REF().getText());
        def = document.getEntity(label);
        if (def == null) {
            System.err.printf("line %d: Unknown label '%s'\n", ctx.start.getLine(), label);
        }
    }
    SideNote q = new SideNote(def, label, (TextBlock) visit(ctx.block));
    if (def != null) {
        def.model = q;
    }
    if (label == null) {
        // if no label, insert inline here
        return q;
    }
    return null;
}
Also used : SideNote(us.parr.bookish.model.SideNote) EntityDef(us.parr.bookish.model.entity.EntityDef)

Example 10 with EntityDef

use of us.parr.bookish.model.entity.EntityDef 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

EntityDef (us.parr.bookish.model.entity.EntityDef)13 ArrayList (java.util.ArrayList)5 ParseTree (org.antlr.v4.runtime.tree.ParseTree)4 Join (us.parr.bookish.model.Join)4 ContainerWithTitle (us.parr.bookish.model.ContainerWithTitle)3 SubSubSection (us.parr.bookish.model.SubSubSection)3 OutputModelObject (us.parr.bookish.model.OutputModelObject)2 Paragraph (us.parr.bookish.model.Paragraph)2 SubSection (us.parr.bookish.model.SubSection)2 TextBlock (us.parr.bookish.model.TextBlock)2 BookishParser (us.parr.bookish.parse.BookishParser)2 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 JsonArray (javax.json.JsonArray)1 JsonObject (javax.json.JsonObject)1 JsonReader (javax.json.JsonReader)1