44
55use JsPhpize \JsPhpize ;
66use JsPhpize \Lexer \Lexer ;
7+ use JsPhpize \Nodes \Assignation ;
78use JsPhpize \Nodes \Block ;
89use JsPhpize \Nodes \BracketsArray ;
910use JsPhpize \Nodes \Constant ;
11+ use JsPhpize \Nodes \FunctionCall ;
1012use JsPhpize \Nodes \HooksArray ;
1113use JsPhpize \Nodes \Main ;
1214use JsPhpize \Nodes \Node ;
@@ -156,9 +158,39 @@ protected function parseBracketsArray()
156158 throw new Exception ('Missing } to match ' . $ exceptionInfos , 7 );
157159 }
158160
161+ protected function parseFunctionCallChildren ($ function , $ applicant = null )
162+ {
163+ $ arguments = $ this ->parseParentheses ()->nodes ;
164+ $ children = array ();
165+
166+ while ($ next = $ this ->get (0 )) {
167+ if ($ value = $ this ->getVariableChildFromToken ($ next )) {
168+ $ children [] = $ value ;
169+
170+ $ next = $ this ->get (0 );
171+ if ($ next && $ next ->is ('( ' )) {
172+ $ this ->skip ();
173+
174+ return $ this ->parseFunctionCallChildren (
175+ new FunctionCall ($ function , $ arguments , $ children , $ applicant )
176+ );
177+
178+ break ;
179+ }
180+
181+ continue ;
182+ }
183+
184+ break ;
185+ }
186+
187+ return new FunctionCall ($ function , $ arguments , $ children , $ applicant );
188+ }
189+
159190 protected function parseVariable ($ name )
160191 {
161192 $ children = array ();
193+ $ variable = null ;
162194 while ($ next = $ this ->get (0 )) {
163195 if ($ next ->type === 'lambda ' ) {
164196 $ this ->skip ();
@@ -171,20 +203,31 @@ protected function parseVariable($name)
171203 if ($ value = $ this ->getVariableChildFromToken ($ next )) {
172204 $ children [] = $ value ;
173205
206+ $ next = $ this ->get (0 );
207+ if ($ next && $ next ->is ('( ' )) {
208+ $ this ->skip ();
209+
210+ $ variable = $ this ->parseFunctionCallChildren (new Variable ($ name , $ children ));
211+
212+ break ;
213+ }
214+
174215 continue ;
175216 }
176217
177218 break ;
178219 }
179220
180- $ variable = new Variable ($ name , $ children );
221+ if ($ variable === null ) {
222+ $ variable = new Variable ($ name , $ children );
181223
182- for ($ i = count ($ this ->stack ) - 1 ; $ i >= 0 ; $ i --) {
183- $ block = $ this ->stack [$ i ];
184- if ($ block ->isLet ($ name )) {
185- $ variable ->setScope ($ block );
224+ for ($ i = count ($ this ->stack ) - 1 ; $ i >= 0 ; $ i --) {
225+ $ block = $ this ->stack [$ i ];
226+ if ($ block ->isLet ($ name )) {
227+ $ variable ->setScope ($ block );
186228
187- break ;
229+ break ;
230+ }
188231 }
189232 }
190233
0 commit comments