use of suite.node.parser.FactorizeResult.FNode in project suite by stupidsing.
the class RecursiveFactorizerTest method transform.
private FNode transform(FNode fn0) {
FTerminal from = new FTerminal(To.chars("ic-compile-better-option"));
FTerminal to = new FTerminal(To.chars("ic-new-compile-better-option"));
Iterate<FNode> fun = fn_ -> fn_.equals(from) ? to : null;
return transform(fn0, fun);
}
use of suite.node.parser.FactorizeResult.FNode in project suite by stupidsing.
the class RecursiveFactorizerTest method rewriteNewArgument.
private String rewriteNewArgument(String pred0, String predx, String newArgument, String s0) {
Source<Node[]> source = () -> {
Reference[] r = new Reference[64];
for (int i = 0; i < r.length; i++) r[i] = new Reference();
Fun<String, Fun<Boolean, Node>> fun = hs -> b -> {
Source<Node> g = To.source(r);
Node head = terminalNode(hs);
Node n0 = !b ? g.source() : operatorNode(TermOp.TUPLE_, List.of(g.source(), terminalNode(" "), terminalNode(newArgument)));
Node n1 = operatorNode(g, TermOp.TUPLE_, g.source(), n0);
return operatorNode(g, TermOp.TUPLE_, head, n1);
};
return new Node[] { fun.apply(pred0).apply(false), fun.apply(predx).apply(true) };
};
FactorizeResult fr0 = recursiveFactorizer.parse(s0);
FNode fn0 = fr0.node;
Node node0 = nodify.nodify(FNode.class, fn0);
Node nodex = rw.rewrite(source, node0);
FNode fnx = nodify.unnodify(FNode.class, nodex);
FactorizeResult frx = new FactorizeResult(fr0.pre, fnx, fr0.post);
String sx = frx.unparse();
return sx;
}
use of suite.node.parser.FactorizeResult.FNode in project suite by stupidsing.
the class RecursiveParser method node.
private Node node(FNode fn) {
if (fn instanceof FTree) {
FTree ft = (FTree) fn;
String name = ft.name;
List<FPair> pairs = ft.pairs;
FNode fn0 = pairs.get(0).node;
FNode fn1 = pairs.get(1).node;
FNode fn2 = pairs.get(2).node;
if (name.equals("("))
return node(fn1);
else if (name.equals("["))
return Tree.of(TermOp.TUPLE_, Atom.of("[]"), node(fn1));
else if (name.equals("`"))
return Tree.of(TermOp.TUPLE_, Atom.of("`"), node(fn1));
else
return Tree.of(TermOp.valueOf(name), node(fn0), node(fn2));
} else
return terminalParser.parseTerminal(((FTerminal) fn).chars.toString());
}
Aggregations