Search in sources :

Example 51 with Node

use of suite.node.Node in project suite by stupidsing.

the class RecursiveFactorizerTest method operatorNode.

private Node operatorNode(Source<Node> g, TermOp op, Node n0, Node n1) {
    Str name = new Str(op.toString());
    List<Node> nodes = List.of(n0, terminalNode(op.getName().trim()), n1);
    return treeNode(g, name, nodes);
}
Also used : Str(suite.node.Str) FNode(suite.node.parser.FactorizeResult.FNode) Node(suite.node.Node)

Example 52 with Node

use of suite.node.Node in project suite by stupidsing.

the class FunctionalTemplateRendererTest method test.

@Test
public void test() {
    List<Node> fruits = Arrays.<Node>asList(new Str("orange"), new Str("apple"), new Str("pear"));
    Map<String, Node> map = // 
    Read.from2(// 
    List.of(// 
    Pair.of("list", Tree.of(TermOp.OR____, fruits)), // 
    Pair.of("title", new Str("My favourite things")))).collect(As::map);
    System.out.println(// 
    new FunctionalTemplateRenderer().render(// 
    "" + // 
    "<html> \n" + // 
    "    <head> \n" + // 
    "        <#= title #> \n" + // 
    "    </head> \n" + // 
    "    </body> \n" + // 
    "        Fruits: \n" + // 
    "<# . (list | apply . map {fruit => id#>        <li><#= fruit #></li> \n" + // 
    "<#}) #>    <body> \n" + // 
    "</html> \n", map));
}
Also used : Str(suite.node.Str) As(suite.streamlet.As) Node(suite.node.Node) Test(org.junit.Test)

Example 53 with Node

use of suite.node.Node in project suite by stupidsing.

the class Fun23TreeTest method test.

@Test
public void test() throws IOException {
    int n = 100;
    String list100 = "0 until " + n + " | map {insert} | apply | {Tree (9999, Empty;)}";
    Node fp0 = Suite.substitute("use 23-TREE >> " + list100);
    Node result0 = Suite.evaluateFun(Suite.fcc(fp0, false));
    String out0 = Formatter.dump(result0);
    System.out.println("OUT:\n" + out0);
    int nPars0 = Read.from(String_.chars(out0)).filter(c -> c == '(').size();
    assertTrue(3 <= nPars0);
    Node fp1 = Suite.substitute("use 23-TREE >> 0 until " + n / 2 + " | map {remove} | apply | {" + list100 + "}");
    Node result1 = Suite.evaluateFun(Suite.fcc(fp1, false));
    String out1 = Formatter.dump(result1);
    System.out.println("OUT:\n" + out1);
    int nPars1 = Read.from(String_.chars(out1)).filter(c -> c == '(').size();
    assertTrue(3 <= nPars1);
}
Also used : Suite(suite.Suite) Formatter(suite.node.io.Formatter) Read(suite.streamlet.Read) String_(suite.util.String_) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Node(suite.node.Node) Node(suite.node.Node) Test(org.junit.Test)

Example 54 with Node

use of suite.node.Node 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);
}
Also used : Trail(suite.lp.Trail) Node(suite.node.Node)

Example 55 with Node

use of suite.node.Node in project suite by stupidsing.

the class SuiteIntrinsicsTest method testSubstitute.

@Test
public void testSubstitute() {
    String fp0 = // 
    "" + // 
    "use SUITE >> chars:\"1 + 2\" \n" + // 
    "| suite-parse \n" + // 
    "| (n => suite-substitute {chars:\"fn {.0}\"} {n;}) \n" + "| suite-to-chars";
    Node n = Suite.evaluateFun(fp0, true);
    assertEquals("fn {1 + 2}", Data.get(n).toString());
}
Also used : Node(suite.node.Node) Test(org.junit.Test)

Aggregations

Node (suite.node.Node)139 Tree (suite.node.Tree)50 Reference (suite.node.Reference)41 Atom (suite.node.Atom)37 Int (suite.node.Int)33 ArrayList (java.util.ArrayList)32 Pair (suite.adt.pair.Pair)25 List (java.util.List)24 TermOp (suite.node.io.TermOp)21 Read (suite.streamlet.Read)21 Test (org.junit.Test)20 Map (java.util.Map)19 Suite (suite.Suite)18 Generalizer (suite.lp.doer.Generalizer)18 Fail (suite.util.Fail)18 Fun (suite.util.FunUtil.Fun)18 Str (suite.node.Str)17 Trail (suite.lp.Trail)16 RuleSet (suite.lp.kb.RuleSet)16 Tuple (suite.node.Tuple)16