Skip to content

Commit

Permalink
Remove angle variant + allow for better nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
assertchris committed Jun 13, 2017
1 parent 2eb7e22 commit 3e021ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 108 deletions.
60 changes: 7 additions & 53 deletions src/macros.yay
Original file line number Diff line number Diff line change
@@ -1,52 +1,10 @@
<?php

macro {
, <>
} >> {
, (new \Pre\Collections\Collection)
}

macro {
= <>
} >> {
= (new \Pre\Collections\Collection)
}

macro {
return <>
} >> {
return (new \Pre\Collections\Collection)
}

macro {
, {}
} >> {
, (new \Pre\Collections\Collection)
}

macro {
= {}
} >> {
= (new \Pre\Collections\Collection)
}

macro {
return {}
} >> {
return (new \Pre\Collections\Collection)
}

macro ·recursion {
·chain(
·either(
·token("<"),
·token("{")
),
·token("{"),
·angle_layer()·values,
·either(
·token(">"),
·token("}")
),
·token("}"),
·token("="),
·_()·keys
)
Expand All @@ -70,18 +28,14 @@ macro ·recursion {
·chain(
·either(
return,
·token("["),
·token("("),
·token(","),
·token("=")
)·before,
·either(
·token("<"),
·token("{")
),
·angle_layer()·values,
·either(
·token(">"),
·token("}")
),
·token("{"),
·optional(·angle_layer())·values,
·token("}"),
·_()·is_array,
·_()·is_not_array
)
Expand Down
75 changes: 20 additions & 55 deletions tests/specs/collections.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,105 +4,70 @@ Test collections macros

--GIVEN--

return [true, {"foo" => "bar"}];
({});

return [true, <"foo" => "bar">];
[{}];

return {};
({"foo" => "bar"});

return <>;
[{"foo" => "bar"}];

$a1 = <>;
[true, {"foo" => "bar"}];

$a2 = {};
return {};

return <$a1>;
$a = {};

return {$a2};

$b1 = <$a1>;

$b2 = {$a2};

return <"foo" => "bar">;
$b = {$a2};

return {"foo" => "bar"};

$c1 = <"foo" => "bar">;

$c2 = {"foo" => "bar"};

return <
"hello" => "world",
"goodbye" => "world",
>;
$c = {"foo" => "bar"};

return {
"hello" => "world",
"goodbye" => "world",
};

$d1 = <
"hello" => "world",
"goodbye" => "world",
>;

$d2 = {
$d = {
"hello" => "world",
"goodbye" => "world",
};

< $a, $b, $c > = ["a" => 1, "b" => 2, "c" => 3];

{ $a, $b, $c } = ["a" => 1, "b" => 2, "c" => 3];

--EXPECT--

((new \Pre\Collections\Collection()));

return [true, (new \Pre\Collections\Collection(["foo" => "bar"]))];

return [true, (new \Pre\Collections\Collection(["foo" => "bar"]))];
[ (new \Pre\Collections\Collection())];

return (new \Pre\Collections\Collection);
((new \Pre\Collections\Collection(["foo" => "bar"])));

return (new \Pre\Collections\Collection);
[ (new \Pre\Collections\Collection(["foo" => "bar"]))];

$a1 = (new \Pre\Collections\Collection);
[true, (new \Pre\Collections\Collection(["foo" => "bar"]))];

$a2 = (new \Pre\Collections\Collection);
return (new \Pre\Collections\Collection());

return (new \Pre\Collections\Collection($a1));
$a = (new \Pre\Collections\Collection());

return (new \Pre\Collections\Collection($a2));

$b1 = (new \Pre\Collections\Collection($a1));

$b2 = (new \Pre\Collections\Collection($a2));

return (new \Pre\Collections\Collection(["foo" => "bar"]));
$b = (new \Pre\Collections\Collection($a2));

return (new \Pre\Collections\Collection(["foo" => "bar"]));

$c1 = (new \Pre\Collections\Collection(["foo" => "bar"]));

$c2 = (new \Pre\Collections\Collection(["foo" => "bar"]));
$c = (new \Pre\Collections\Collection(["foo" => "bar"]));

return (new \Pre\Collections\Collection(["hello" => "world",
"goodbye" => "world",
]));

return (new \Pre\Collections\Collection(["hello" => "world",
$d = (new \Pre\Collections\Collection(["hello" => "world",
"goodbye" => "world",
]));

$d1 = (new \Pre\Collections\Collection(["hello" => "world",
"goodbye" => "world",
]));

$d2 = (new \Pre\Collections\Collection(["hello" => "world",
"goodbye" => "world",
]));

['a' => $a, 'b' => $b, 'c' => $c] = ["a" => 1, "b" => 2, "c" => 3];

['a' => $a, 'b' => $b, 'c' => $c] = ["a" => 1, "b" => 2, "c" => 3];

0 comments on commit 3e021ff

Please sign in to comment.