use of suite.node.Node in project suite by stupidsing.
the class LogicCompilerLevel1Test method testMemberOfMember.
@Test
public void testMemberOfMember() {
RuleSet rs = Suite.newRuleSet(List.of("auto.sl"));
Node goal = Suite.parse("source .lln, member .lln .ln, member .ln .n, sink .n");
Node input = Suite.parse("((1, 2,), (3, 4,),)");
List<Node> results = FindUtil.collectList(finder(rs, goal), input);
System.out.println(results);
assertTrue(results.size() == 4);
}
use of suite.node.Node in project suite by stupidsing.
the class BinderFactoryTest method test.
private void test(String pattern, String match) {
for (BinderFactory bf : new BinderFactory[] { //
new CompileBinderImpl0(), //
new CompileBinderImpl(), new SewingBinderImpl() }) {
Node node = new Generalizer().generalize(Suite.parse(pattern));
Bind_ p = bf.binder(node);
BindEnv be = new BindEnv(bf.mapper().env());
assertTrue(p.test(be, Suite.parse(match)));
}
}
use of suite.node.Node in project suite by stupidsing.
the class Comparer method compare.
@Override
public int compare(Node n0, Node n1) {
n0 = n0.finalNode();
n1 = n1.finalNode();
Class<? extends Node> clazz0 = n0.getClass();
Class<? extends Node> clazz1 = n1.getClass();
int c = Integer.compare(order.get(clazz0), order.get(clazz1));
if (c == 0)
if (clazz0 == Atom.class)
return ((Atom) n0).name.compareTo(((Atom) n1).name);
else if (clazz0 == Dict.class) {
Map<Node, Reference> m0 = ((Dict) n0).map;
Map<Node, Reference> m1 = ((Dict) n1).map;
Set<Node> keys = new HashSet<>();
keys.addAll(m0.keySet());
keys.addAll(m1.keySet());
for (Node key : Read.from(keys).sort(this::compare)) c = c != 0 ? c : Object_.compare(m0.get(key), m1.get(key));
return c;
} else if (clazz0 == Int.class)
return Integer.compare(((Int) n0).number, ((Int) n1).number);
else if (clazz0 == Reference.class)
return Integer.compare(((Reference) n0).getId(), ((Reference) n1).getId());
else if (clazz0 == Str.class)
return ((Str) n0).value.compareTo(((Str) n1).value);
else if (Tree.class.isAssignableFrom(clazz0)) {
Tree t0 = (Tree) n0;
Tree t1 = (Tree) n1;
c = t0.getOperator().getPrecedence() - t1.getOperator().getPrecedence();
c = c != 0 ? c : compare(t0.getLeft(), t1.getLeft());
c = c != 0 ? c : compare(t0.getRight(), t1.getRight());
return c;
} else if (clazz0 == Tuple.class) {
Node[] nodes0 = ((Tuple) n0).nodes;
Node[] nodes1 = ((Tuple) n1).nodes;
int i = 0, l = min(nodes0.length, nodes1.length);
while (c == 0 && i < l) c = compare(nodes0[i], nodes1[i]);
if (c == 0)
c = Integer.compare(nodes0.length, nodes1.length);
return c;
} else
return Integer.compare(n0.hashCode(), n1.hashCode());
else
return c;
}
use of suite.node.Node 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.node.Node in project suite by stupidsing.
the class TermKey method equals.
@Override
public boolean equals(Object object) {
if (Object_.clazz(object) == TermKey.class) {
Node node1 = ((TermKey) object).node;
TermLister tl0 = new TermLister(node);
TermLister tl1 = new TermLister(node1);
return Objects.equals(tl0, tl1);
} else
return false;
}
Aggregations