Search in sources :

Example 1 with FNode

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);
}
Also used : FNode(suite.node.parser.FactorizeResult.FNode) Read(suite.streamlet.Read) Singleton(suite.node.util.Singleton) Fun(suite.util.FunUtil.Fun) Node(suite.node.Node) FTree(suite.node.parser.FactorizeResult.FTree) FileUtil(suite.os.FileUtil) Nodify(suite.util.Nodify) Dict(suite.node.Dict) FPair(suite.node.parser.FactorizeResult.FPair) Reference(suite.node.Reference) Source(suite.util.FunUtil.Source) Assert.assertTrue(org.junit.Assert.assertTrue) TermOp(suite.node.io.TermOp) FTerminal(suite.node.parser.FactorizeResult.FTerminal) Test(org.junit.Test) To(suite.util.To) Tree(suite.node.Tree) Iterate(suite.util.FunUtil.Iterate) List(java.util.List) Rewrite(suite.node.util.Rewrite) Assert.assertFalse(org.junit.Assert.assertFalse) Atom(suite.node.Atom) Operator(suite.node.io.Operator) Assert.assertEquals(org.junit.Assert.assertEquals) Str(suite.node.Str) FNode(suite.node.parser.FactorizeResult.FNode) FTerminal(suite.node.parser.FactorizeResult.FTerminal)

Example 2 with FNode

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;
}
Also used : Reference(suite.node.Reference) FNode(suite.node.parser.FactorizeResult.FNode) Node(suite.node.Node) FNode(suite.node.parser.FactorizeResult.FNode) Fun(suite.util.FunUtil.Fun)

Example 3 with FNode

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());
}
Also used : FPair(suite.node.parser.FactorizeResult.FPair) FTree(suite.node.parser.FactorizeResult.FTree) FNode(suite.node.parser.FactorizeResult.FNode)

Aggregations

FNode (suite.node.parser.FactorizeResult.FNode)3 Node (suite.node.Node)2 Reference (suite.node.Reference)2 FPair (suite.node.parser.FactorizeResult.FPair)2 FTree (suite.node.parser.FactorizeResult.FTree)2 Fun (suite.util.FunUtil.Fun)2 List (java.util.List)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Test (org.junit.Test)1 Atom (suite.node.Atom)1 Dict (suite.node.Dict)1 Str (suite.node.Str)1 Tree (suite.node.Tree)1 Operator (suite.node.io.Operator)1 TermOp (suite.node.io.TermOp)1 FTerminal (suite.node.parser.FactorizeResult.FTerminal)1 Rewrite (suite.node.util.Rewrite)1 Singleton (suite.node.util.Singleton)1