77use JsPhpize \Lexer \Token ;
88use JsPhpize \Nodes \Assignation ;
99use JsPhpize \Nodes \Block ;
10+ use JsPhpize \Nodes \Value ;
1011use JsPhpize \Nodes \BracketsArray ;
1112use JsPhpize \Nodes \Constant ;
1213use JsPhpize \Nodes \Dyiade ;
@@ -90,13 +91,24 @@ protected function exceptionInfos()
9091
9192 protected function unexpected ($ token )
9293 {
93- // var_dump($token);
94- // var_dump($this->stack[0]->instructions[2]->instructions[0]);
95- // exit;
96-
9794 throw new Exception ('Unexpected ' . $ token ->type . rtrim (' ' . ($ token ->value ?: '' )) . $ this ->exceptionInfos (), 8 );
9895 }
9996
97+ protected function parseLambda (Value $ parameters )
98+ {
99+ $ lambda = new Block ('function ' );
100+ $ lambda ->setValue ($ parameters );
101+ $ next = $ this ->next ();
102+ if ($ next ) {
103+ if ($ next ->is ('{ ' )) {
104+ $ this ->skip ();
105+ $ this ->parseBlock ($ lambda );
106+ }
107+ }
108+
109+ return $ lambda ;
110+ }
111+
100112 protected function parseParentheses ()
101113 {
102114 $ parentheses = new Parenthesis ();
@@ -105,6 +117,10 @@ protected function parseParentheses()
105117 while ($ token = $ this ->next ()) {
106118 $ debug [] = $ token ;
107119 if ($ token ->is (') ' )) {
120+ $ next = $ this ->get (0 );
121+ if ($ next && $ next ->is ('lambda ' )) {
122+ return $ this ->parseLambda ($ parentheses );
123+ }
108124 return $ parentheses ;
109125 }
110126 if ($ expectComma ) {
@@ -237,6 +253,10 @@ protected function parseVariable($name)
237253 continue ;
238254 }
239255
256+ if ($ next ->is ('lambda ' )) {
257+ return $ this ->parseLambda (new Variable ($ name , $ children ));
258+ }
259+
240260 break ;
241261 }
242262
@@ -303,7 +323,8 @@ protected function parseValue($token)
303323 if ($ token ->isAssignation ()) {
304324 $ this ->skip ();
305325 $ arguments = array ();
306- $ value = new Assignation ($ token ->type , $ value , $ this ->expectValue ($ this ->next ()));
326+ $ valueToAssign = $ this ->expectValue ($ this ->next ());
327+ $ value = new Assignation ($ token ->type , $ value , $ valueToAssign );
307328
308329 continue ;
309330 }
0 commit comments