Search in sources :

Example 1 with ContainerWithTitle

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

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

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

the class Translator method visitSubsection.

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

Aggregations

ArrayList (java.util.ArrayList)3 ParseTree (org.antlr.v4.runtime.tree.ParseTree)3 ContainerWithTitle (us.parr.bookish.model.ContainerWithTitle)3 Join (us.parr.bookish.model.Join)3 EntityDef (us.parr.bookish.model.entity.EntityDef)3 SubSection (us.parr.bookish.model.SubSection)2 SubSubSection (us.parr.bookish.model.SubSubSection)2 Chapter (us.parr.bookish.model.Chapter)1 OutputModelObject (us.parr.bookish.model.OutputModelObject)1 Section (us.parr.bookish.model.Section)1