Search in sources :

Example 1 with SigExp

use of catdata.fql.decl.SigExp in project fql by CategoricalData.

the class TransChecker method visit.

@SuppressWarnings("unused")
@Override
public Pair<String, String> visit(FQLProgram env, Const e) {
    InstExp src = env.insts.get(e.src);
    if (src == null) {
        throw new RuntimeException("Missing instance " + e.src);
    }
    InstExp dst = env.insts.get(e.dst);
    if (dst == null) {
        throw new RuntimeException("Missing instance " + e.src);
    }
    if (!(src instanceof InstExp.Const)) {
        throw new RuntimeException(e.src + " is not a constant.");
    }
    if (!(dst instanceof InstExp.Const)) {
        throw new RuntimeException(e.dst + " is not a constant.");
    }
    InstExp.Const src0 = (InstExp.Const) src;
    InstExp.Const dst0 = (InstExp.Const) dst;
    SigExp srct = src0.type(env);
    SigExp dstt = dst0.type(env);
    if (!srct.equals(dstt)) {
        throw new RuntimeException("Instances not of same type on " + e + " are " + srct + " and " + dstt);
    }
    Signature sig = srct.toSig(env);
    List<Pair<String, List<Pair<Object, Object>>>> bbb = e.objs;
    try {
        new Transform(new Instance(sig, src0.data), new Instance(sig, dst0.data), bbb);
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getLocalizedMessage());
    }
    return new Pair<>(e.src, e.dst);
}
Also used : InstExp(catdata.fql.decl.InstExp) FQLException(catdata.fql.FQLException) SigExp(catdata.fql.decl.SigExp) Instance(catdata.fql.decl.Instance) Const(catdata.fql.decl.TransExp.Const) Signature(catdata.fql.decl.Signature) Transform(catdata.fql.decl.Transform) Pair(catdata.Pair)

Example 2 with SigExp

use of catdata.fql.decl.SigExp in project fql by CategoricalData.

the class FQLParser method toSchema.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static SigExp toSchema(Object o) {
    try {
        Tuple3<?, ?, ?> t = (Tuple3<?, ?, ?>) o;
        Token z = (Token) t.b;
        String y = z.toString();
        switch(y) {
            case "+":
                return new SigExp.Plus(toSchema(t.a), toSchema(t.c));
            case "*":
                return new SigExp.Times(toSchema(t.a), toSchema(t.c));
            case "^":
                return new SigExp.Exp(toSchema(t.a), toSchema(t.c));
            case "union":
                return new Union(toSchema(t.a), toSchema(t.c));
            default:
                break;
        }
    } catch (RuntimeException cce) {
    }
    try {
        org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
        if (p.a.toString().equals("unit")) {
            return new SigExp.One(new HashSet<>((Collection<String>) p.b));
        } else if (p.a.toString().equals("opposite")) {
            return new SigExp.Opposite(toSchema(p.b));
        }
    } catch (RuntimeException cce) {
    }
    try {
        if (o.toString().equals("void")) {
            return new SigExp.Zero();
        } else if (o.toString().equals("?")) {
            return new Unknown("?" + unknown_idx++);
        }
        throw new RuntimeException();
    } catch (RuntimeException cce) {
    }
    try {
        return toSchemaConst(o);
    } catch (RuntimeException cce) {
    }
    return new SigExp.Var(o.toString());
}
Also used : Zero(catdata.fql.decl.InstExp.Zero) Var(catdata.fql.decl.FullQueryExp.Var) One(catdata.fql.decl.InstExp.One) Token(org.jparsec.Token) Union(catdata.fql.decl.SigExp.Union) Unknown(catdata.fql.decl.SigExp.Unknown) SigExp(catdata.fql.decl.SigExp) Tuple3(org.jparsec.functors.Tuple3) Times(catdata.fql.decl.InstExp.Times) Plus(catdata.fql.decl.InstExp.Plus) FullQueryExp(catdata.fql.decl.FullQueryExp) Exp(catdata.fql.decl.InstExp.Exp) MapExp(catdata.fql.decl.MapExp) TransExp(catdata.fql.decl.TransExp) QueryExp(catdata.fql.decl.QueryExp) SigExp(catdata.fql.decl.SigExp) InstExp(catdata.fql.decl.InstExp) Pair(catdata.Pair)

Example 3 with SigExp

use of catdata.fql.decl.SigExp in project fql by CategoricalData.

the class TransChecker method visit.

@Override
public Pair<String, String> visit(FQLProgram env, TT e) {
    InstExp x = env.insts.get(e.obj);
    if (x == null) {
        throw new RuntimeException("Missing " + e.obj + " in " + e);
    }
    if (!(x instanceof One)) {
        throw new RuntimeException(e.obj + " is not a unit: " + x);
    }
    // InstExp.One y = (InstExp.One) x;
    InstExp z = env.insts.get(e.tgt);
    if (z == null) {
        throw new RuntimeException("Missing " + e.tgt + " in " + e);
    }
    SigExp xt = x.type(env);
    SigExp yt = z.type(env);
    if (!xt.equals(yt)) {
        throw new RuntimeException("Instances have different types in " + e + ": " + xt + " and " + yt);
    }
    return new Pair<>(e.tgt, e.obj);
}
Also used : InstExp(catdata.fql.decl.InstExp) SigExp(catdata.fql.decl.SigExp) One(catdata.fql.decl.InstExp.One) Pair(catdata.Pair)

Example 4 with SigExp

use of catdata.fql.decl.SigExp in project fql by CategoricalData.

the class TransChecker method visit.

@Override
public Pair<String, String> visit(FQLProgram env, External e) {
    InstExp src = env.insts.get(e.src);
    if (src == null) {
        throw new RuntimeException("Missing instance " + e.src);
    }
    InstExp dst = env.insts.get(e.dst);
    if (dst == null) {
        throw new RuntimeException("Missing instance " + e.src);
    }
    if (!(src instanceof InstExp.External)) {
        throw new RuntimeException(e.src + " is not external.");
    }
    if (!(dst instanceof InstExp.External)) {
        throw new RuntimeException(e.dst + " is not external.");
    }
    InstExp.External src0 = (InstExp.External) src;
    InstExp.External dst0 = (InstExp.External) dst;
    SigExp srct = src0.type(env);
    SigExp dstt = dst0.type(env);
    if (!srct.equals(dstt)) {
        throw new RuntimeException("Instances not of same type on " + e + " are " + srct + " and " + dstt);
    }
    return new Pair<>(e.src, e.dst);
}
Also used : InstExp(catdata.fql.decl.InstExp) SigExp(catdata.fql.decl.SigExp) External(catdata.fql.decl.TransExp.External) Pair(catdata.Pair)

Example 5 with SigExp

use of catdata.fql.decl.SigExp in project fql by CategoricalData.

the class TransChecker method visit.

@Override
public Pair<String, String> visit(FQLProgram env, FF e) {
    InstExp x = env.insts.get(e.obj);
    if (x == null) {
        throw new RuntimeException("Missing " + e.obj + " in " + e);
    }
    if (!(x instanceof Zero)) {
        throw new RuntimeException(e.obj + " is not void: " + x);
    }
    // InstExp.One y = (InstExp.One) x;
    InstExp z = env.insts.get(e.tgt);
    if (z == null) {
        throw new RuntimeException("Missing " + e.tgt + " in " + e);
    }
    SigExp xt = x.type(env);
    SigExp yt = z.type(env);
    if (!xt.equals(yt)) {
        throw new RuntimeException("Instances have different types in " + e + ": " + xt + " and " + yt);
    }
    return new Pair<>(e.obj, e.tgt);
}
Also used : InstExp(catdata.fql.decl.InstExp) Zero(catdata.fql.decl.InstExp.Zero) SigExp(catdata.fql.decl.SigExp) Pair(catdata.Pair)

Aggregations

Pair (catdata.Pair)5 InstExp (catdata.fql.decl.InstExp)5 SigExp (catdata.fql.decl.SigExp)5 One (catdata.fql.decl.InstExp.One)2 Zero (catdata.fql.decl.InstExp.Zero)2 FQLException (catdata.fql.FQLException)1 FullQueryExp (catdata.fql.decl.FullQueryExp)1 Var (catdata.fql.decl.FullQueryExp.Var)1 Exp (catdata.fql.decl.InstExp.Exp)1 Plus (catdata.fql.decl.InstExp.Plus)1 Times (catdata.fql.decl.InstExp.Times)1 Instance (catdata.fql.decl.Instance)1 MapExp (catdata.fql.decl.MapExp)1 QueryExp (catdata.fql.decl.QueryExp)1 Union (catdata.fql.decl.SigExp.Union)1 Unknown (catdata.fql.decl.SigExp.Unknown)1 Signature (catdata.fql.decl.Signature)1 TransExp (catdata.fql.decl.TransExp)1 Const (catdata.fql.decl.TransExp.Const)1 External (catdata.fql.decl.TransExp.External)1