Search in sources :

Example 1 with EntityDef

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

the class Translator method visitSite.

@Override
public OutputModelObject visitSite(BookishParser.SiteContext 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);
            return null;
        }
    }
    def.model = new Site((SiteDef) def);
    return null;
}
Also used : Site(us.parr.bookish.model.Site) SiteDef(us.parr.bookish.model.entity.SiteDef) EntityDef(us.parr.bookish.model.entity.EntityDef)

Example 2 with EntityDef

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

the class Translator method visitCitation.

@Override
public OutputModelObject visitCitation(BookishParser.CitationContext 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);
            return null;
        }
    }
    def.model = new Citation(def, label, (TextBlock) visit(ctx.t), (TextBlock) visit(ctx.a));
    return null;
}
Also used : Citation(us.parr.bookish.model.Citation) TextBlock(us.parr.bookish.model.TextBlock) EntityDef(us.parr.bookish.model.entity.EntityDef)

Example 3 with EntityDef

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

the class Translator method visitSection.

@Override
public OutputModelObject visitSection(BookishParser.SectionContext ctx) {
    String title = ctx.sec.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;
        }
    }
    List<ContainerWithTitle> subsections = new ArrayList<>();
    for (ParseTree el : ctx.subsection()) {
        subsections.add((SubSection) visit(el));
    }
    Join sec = (Join) visitSection_content(ctx.section_content());
    return new Section(def, title, anchor, sec.elements, subsections);
}
Also used : ContainerWithTitle(us.parr.bookish.model.ContainerWithTitle) ArrayList(java.util.ArrayList) Join(us.parr.bookish.model.Join) SubSubSection(us.parr.bookish.model.SubSubSection) SubSection(us.parr.bookish.model.SubSection) Section(us.parr.bookish.model.Section) ParseTree(org.antlr.v4.runtime.tree.ParseTree) EntityDef(us.parr.bookish.model.entity.EntityDef)

Example 4 with EntityDef

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

the class Translator method visitSubsubsection.

@Override
public OutputModelObject visitSubsubsection(BookishParser.SubsubsectionContext ctx) {
    String title = ctx.sec.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);
        }
    }
    Join sec = (Join) visitSection_content(ctx.section_content());
    return new SubSubSection(def, title, anchor, sec != null ? sec.elements : null);
}
Also used : Join(us.parr.bookish.model.Join) SubSubSection(us.parr.bookish.model.SubSubSection) EntityDef(us.parr.bookish.model.entity.EntityDef)

Example 5 with EntityDef

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

the class Translator method lookupEntity.

public EntityDef lookupEntity(TerminalNode refNode) {
    EntityDef def = null;
    if (refNode != null) {
        String label = stripQuotes(refNode.getText());
        def = document.getEntity(label);
        if (def == null) {
            System.err.printf("line %d: Unknown label '%s'\n", refNode.getSymbol().getLine(), label);
        }
    }
    return def;
}
Also used : EntityDef(us.parr.bookish.model.entity.EntityDef)

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