Search in sources :

Example 1 with OplPragma

use of catdata.opl.OplExp.OplPragma in project fql by CategoricalData.

the class OplParser method toPragma.

private static OplExp toPragma(Object t) {
    Tuple3 tb = (Tuple3) t;
    List<Tuple3> l = (List<Tuple3>) tb.b;
    Map<String, String> map = new HashMap<>();
    for (Tuple3 x : l) {
        String k = (String) x.a;
        String v = (String) x.c;
        if (map.containsKey(k)) {
            throw new DoNotIgnore("Duplicate key: " + k);
        }
        map.put(k, v);
    }
    return new OplPragma(map);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) OplPragma(catdata.opl.OplExp.OplPragma)

Example 2 with OplPragma

use of catdata.opl.OplExp.OplPragma in project fql by CategoricalData.

the class OplDriver method makeEnv.

// : let x be the position of the first change between old and new
// program.
// a definition y is 'safe' if definition y+1 begins before x.
// each code editor's driver should copy over the safe definitions and start
// the driver
// at the appropriate spot
public static Environment<OplObject> makeEnv(String str, Program<OplExp> init, String[] toUpdate, String last_str, Program<OplExp> last_prog, Environment<OplObject> last_env) {
    Environment<OplObject> ret = new Environment<>();
    // Map<String, Integer> extra = new HashMap<>();
    boolean usesPragma = false;
    for (String k : init.order) {
        OplExp se = init.exps.get(k);
        if (se instanceof OplPragma) {
            se.accept(init, new OplOps(ret));
            ret.put(k, se);
            usesPragma = true;
        }
    }
    if (DefunctGlobalOptions.debug.opl.opl_lazy_gui && usesPragma) {
        throw new RuntimeException("Pragmas and lazy guis are not compatible");
    }
    if (DefunctGlobalOptions.debug.opl.opl_prover_force_prec) {
        inferPrec(init);
    }
    Set<String> unchanged = new HashSet<>();
    int i = 0;
    if (last_str != null && DefunctGlobalOptions.debug.opl.opl_cache_gui) {
        for (String k : init.order) {
            if (i >= last_prog.order.size()) {
                break;
            }
            String v = last_prog.order.get(i);
            if (!v.equals(k)) {
                break;
            }
            OplExp a = init.exps.get(k);
            OplExp b = last_prog.exps.get(k);
            if (!a.equals(b)) {
                break;
            }
            unchanged.add(k);
            i++;
        }
    }
    // toUpdate[0] = "Processed:";
    for (String k : init.order) {
        OplExp se = init.exps.get(k);
        if (se instanceof OplPragma) {
            continue;
        }
        if (unchanged.contains(k)) {
            ret.put(k, last_env.get(k));
            continue;
        }
        try {
            OplObject xxx = se.accept(init, new OplOps(ret));
            ret.put(k, xxx);
            if (toUpdate != null) {
                toUpdate[0] = "Last Processed: " + k;
            }
        // i++;
        } catch (Throwable t) {
            t.printStackTrace();
            throw new LineException(t.getLocalizedMessage(), k, "");
        }
    }
    return ret;
}
Also used : LineException(catdata.LineException) Environment(catdata.Environment) OplPragma(catdata.opl.OplExp.OplPragma) HashSet(java.util.HashSet)

Aggregations

OplPragma (catdata.opl.OplExp.OplPragma)2 Environment (catdata.Environment)1 LineException (catdata.LineException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Tuple3 (org.jparsec.functors.Tuple3)1