namespace example;
-use function Widmogrod\Functional\dropWhile;
use Widmogrod\Monad\Identity;
use Widmogrod\Monad\Maybe\Just;
use Widmogrod\Monad\Maybe\Maybe;
use function Widmogrod\Functional\bind;
use function Widmogrod\Functional\concatM;
use function Widmogrod\Functional\curryN;
+use function Widmogrod\Functional\dropWhile;
use function Widmogrod\Functional\emptyM;
use function Widmogrod\Functional\equal;
use function Widmogrod\Functional\fromIterable;
$trimNil = dropWhile(function (Stringg $s) {
return trim($s->extract()) === "";
}, $a);
+
return $fn($trimNil);
})(...func_get_args());
};
$trimNil = dropWhile(function (Stringg $s) {
return trim($s->extract(), " ") === "";
}, $a);
+
return $fn($trimNil);
})(...func_get_args());
};
$grouping = allOfP(fromIterable([
$parOp, &$typeName, $parCl,
]), function (Listt $attr) {
- return ['grp' => $attr->extract()[1]];
+ return ['grp', $attr->extract()[1]];
});
$args = $lexeme2(manyP(fromIterable([
])));
$representations = manyP(fromIterable([
- oneOfP(fromIterable([$or, $typeName])),
+ oneOfP(fromIterable([$typeName, $or])),
]), function (Listt $a) {
return ['representation', $a->extract()];
});
$result = $expression($tokens);
$ast = $result->extract()[0];
- print_r($ast);
-
-// $this->assertEquals(['typeName', "Some"], $ast);
+ $this->assertEquals(
+ ["types",
+ [
+ ["declaration",
+ [
+ ["typeName", ["Maybe", ["args", ["a"]]]],
+ ["representation",
+ [
+ ["typeName", ["Just", ["args", ["a"]]]],
+ "|",
+ ["typeName", ["Nothing", []]]
+ ]
+ ]
+ ]
+ ],
+ ["declaration",
+ [
+ ["typeName", ["A", []]],
+ ["representation", [
+ ["typeName", ["B", []]]]
+ ]
+ ]
+ ],
+ ["declaration",
+ [
+ ["typeName", ["Either", ["args", ["a", "b"]]]],
+ ["representation",
+ [
+ ["typeName", ["Left", ["args", ["a"]]]],
+ "|",
+ ["typeName", ["Right", ["args", ["b"]]]]
+ ]
+ ]
+ ]
+ ],
+ ["declaration",
+ [
+ ["typeName", ["Free", ["args", ["f", "a"]]]],
+ ["representation",
+ [
+ ["typeName", ["Pure", ["args", ["a"]]]], "|",
+ ["typeName", ["Free", ["args", ["f", ["grp", ["typeName", ["Free", ["args", ["f", "a"]]]]]]]]]
+ ]
+ ]
+ ]
+ ]
+ ]
+ ],
+ $ast
+ );
}
}