Search in sources :

Example 1 with EntityRef

use of us.parr.bookish.model.ref.EntityRef in project bookish by parrt.

the class Translator method visitRef.

@Override
public OutputModelObject visitRef(BookishParser.RefContext ctx) {
    String label = stripQuotes(ctx.REF().getText());
    EntityDef def = document.getEntity(label);
    System.out.println("Ref to " + def);
    if (def == null) {
        System.err.printf("line %d: Unknown label '%s'\n", ctx.start.getLine(), label);
        return new UnknownRef(ctx.REF().getSymbol());
    }
    Class<? extends EntityRef> refClass = defToRefMap.get(def.getClass());
    try {
        Constructor<? extends EntityRef> ctor = refClass.getConstructor(EntityDef.class);
        EntityRef entityRef = ctor.newInstance(def);
        return entityRef;
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
    return null;
}
Also used : UnknownRef(us.parr.bookish.model.ref.UnknownRef) EntityRef(us.parr.bookish.model.ref.EntityRef) IOException(java.io.IOException) EntityDef(us.parr.bookish.model.entity.EntityDef)

Aggregations

IOException (java.io.IOException)1 EntityDef (us.parr.bookish.model.entity.EntityDef)1 EntityRef (us.parr.bookish.model.ref.EntityRef)1 UnknownRef (us.parr.bookish.model.ref.UnknownRef)1