use of suite.lp.Trail in project suite by stupidsing.
the class Chr method chrIf.
private Streamlet<State> chrIf(Streamlet<State> states, Trail trail, Node if_) {
Prototype prototype = Prototype.of(if_);
Fun<State, Streamlet<State>> fun = state -> {
ISet<Node> facts = getFacts(state, prototype);
Predicate<Node> bindFun = bindFun(trail, if_);
return facts.streamlet().filter(bindFun).map(node -> setFacts(state, prototype, facts.remove(node)));
};
return states.concatMap(fun);
}
use of suite.lp.Trail in project suite by stupidsing.
the class Chr method chr.
private Streamlet<State> chr(State state, Rule rule) {
Generalizer generalizer = new Generalizer();
Trail trail = new Trail();
Streamlet<State> states = Read.each(state);
for (Node if_ : rule.ifs) states = chrIf(states, trail, generalizer.generalize(if_));
for (Node given : rule.givens) states = chrGiven(states, trail, generalizer.generalize(given));
states = chrWhen(states, generalizer.generalize(rule.when));
for (Node then : rule.thens) states = chrThen(states, generalizer.generalize(then));
return states;
}
use of suite.lp.Trail in project suite by stupidsing.
the class FunTypeTest method checkType.
private void checkType(String fps, String bindTo, String ts) {
Trail trail = new Trail();
Node type = getType(fps);
assertTrue(Binder.bind(type, SewingGeneralizerImpl.generalize(Suite.parse(bindTo)), trail));
assertTrue(Comparer.comparer.compare(Suite.parse(ts), type) == 0);
}
use of suite.lp.Trail in project suite by stupidsing.
the class Rewrite method rewrite.
public Node rewrite(Source<Node[]> source, Node node) {
Trail trail = new Trail();
return rewrite(node0 -> {
Node node1;
if (!(node0 instanceof Reference)) {
int pit = trail.getPointInTime();
Node[] ft = source.source();
if (Binder.bind(node0, ft[0], trail))
node1 = ft[1];
else {
trail.unwind(pit);
node1 = node0;
}
} else
node1 = node0;
return node1;
}, node);
}
use of suite.lp.Trail in project suite by stupidsing.
the class ClonerFactoryTest method test.
private void test(String pattern, String match) {
for (ClonerFactory cf : new ClonerFactory[] { new CompileClonerImpl(), new SewingClonerImpl() }) {
Node node = new Generalizer().generalize(Suite.parse(pattern));
Clone_ p = cf.cloner(node);
assertTrue(Binder.bind(p.apply(cf.mapper().env()), Suite.parse(match), new Trail()));
}
}
Aggregations