use of suite.node.io.Rewrite_.NodeRead in project suite by stupidsing.
the class Grapher method graph_.
private int graph_(Map<IdentityKey<Node>, Integer> ids, Node node) {
IdentityKey<Node> key = IdentityKey.of(node);
Integer id = ids.get(key);
if (id == null) {
ids.put(key, id = gns.size());
gns.add(null);
NodeRead nr = NodeRead.of(node);
List<IntIntPair> children = //
Read.from(//
nr.children).map(//
p -> IntIntPair.of(graph_(ids, p.t0), graph_(ids, p.t1))).toList();
gns.set(id, new GN(nr.type, nr.terminal, nr.op, children));
}
return id;
}
use of suite.node.io.Rewrite_.NodeRead in project suite by stupidsing.
the class Lister method leaves.
private Streamlet<IList<Node>> leaves(Node node, IList<Node> prefix) {
NodeRead nr = NodeRead.of(node);
Streamlet<IList<Node>> st;
if (nr.type == ReadType.TUPLE)
st = //
Read.from(//
nr.children).index().map(//
(i, p) -> leaves(p.t1, IList.cons(Int.of(i), prefix))).collect(As::concat);
else if (nr.type != ReadType.TERM)
st = Read.from(nr.children).concatMap(p -> leaves(p.t1, IList.cons(p.t0, prefix)));
else
st = Read.from(List.of(IList.cons(nr.terminal, prefix)));
if (nr.op != null)
st = st.cons(IList.cons(Atom.of(nr.op.toString()), prefix));
return st;
}
Aggregations