@@ -175,6 +175,37 @@ protected function parseHooksArray()
175175 throw new Exception ('Missing ] to match ' . $ exceptionInfos , 6 );
176176 }
177177
178+ protected function getBracketsArrayItemKeyFromToken ($ token )
179+ {
180+ $ type = null ;
181+
182+ if ($ token ->is ('keyword ' )) {
183+ $ type = 'string ' ;
184+ $ value = var_export ($ token ->value , true );
185+ } elseif ($ token ->isValue ()) {
186+ $ type = $ token ->type ;
187+ $ value = $ token ->value ;
188+ if ($ type === 'variable ' ) {
189+ $ type = 'string ' ;
190+ $ value = var_export ($ value , true );
191+ }
192+ }
193+
194+ if ($ type ) {
195+ $ token = $ this ->next ();
196+ if (!$ token ) {
197+ throw new Exception ('Missing value after ' . $ value . $ this ->exceptionInfos (), 12 );
198+ }
199+ if (!$ token ->is (': ' )) {
200+ $ this ->unexpected ($ token );
201+ }
202+ $ key = new Constant ($ type , $ value );
203+ $ value = $ this ->expectValue ($ this ->next ());
204+
205+ return array ($ key , $ value );
206+ }
207+ }
208+
178209 protected function parseBracketsArray ()
179210 {
180211 $ array = new BracketsArray ();
@@ -192,28 +223,8 @@ protected function parseBracketsArray()
192223 }
193224 $ this ->unexpected ($ token );
194225 }
195- $ type = null ;
196- if ($ token ->is ('keyword ' )) {
197- $ type = 'string ' ;
198- $ value = var_export ($ token ->value , true );
199- } elseif ($ token ->isValue ()) {
200- $ type = $ token ->type ;
201- $ value = $ token ->value ;
202- if ($ type === 'variable ' ) {
203- $ type = 'string ' ;
204- $ value = var_export ($ value , true );
205- }
206- }
207- if ($ type ) {
208- $ token = $ this ->next ();
209- if (!$ token ) {
210- throw new Exception ('Missing value after ' . $ value . $ this ->exceptionInfos (), 12 );
211- }
212- if (!$ token ->is (': ' )) {
213- $ this ->unexpected ($ token );
214- }
215- $ key = new Constant ($ type , $ value );
216- $ value = $ this ->expectValue ($ this ->next ());
226+ if ($ pair = $ this ->getBracketsArrayItemKeyFromToken ($ token )) {
227+ list ($ key , $ value ) = $ pair ;
217228 $ expectComma = true ;
218229 $ array ->addItem ($ key , $ value );
219230
@@ -440,7 +451,7 @@ protected function getValueFromToken($token)
440451 return $ value ;
441452 }
442453
443- protected function parseKeyword ($ token )
454+ protected function parseKeywordStatement ($ token )
444455 {
445456 $ name = $ token ->value ;
446457 $ keyword = new Block ($ name );
@@ -477,6 +488,13 @@ protected function parseKeyword($token)
477488 throw new Exception ("' " . $ keyword ->type . "' block need parentheses. " , 17 );
478489 }
479490 }
491+
492+ return $ keyword ;
493+ }
494+
495+ protected function parseKeyword ($ token )
496+ {
497+ $ keyword = $ this ->parseKeywordStatement ($ token );
480498 if ($ keyword ->handleInstructions ()) {
481499 $ this ->parseBlock ($ keyword );
482500 }
@@ -494,6 +512,17 @@ protected function parseLet($token)
494512 return $ letVariable ->value ;
495513 }
496514
515+ protected function getInstructionFromToken ($ token )
516+ {
517+ if ($ token ->is ('keyword ' )) {
518+ return $ this ->parseKeyword ($ token );
519+ }
520+
521+ if ($ value = $ this ->getValueFromToken ($ token )) {
522+ return $ value ;
523+ }
524+ }
525+
497526 protected function parseInstructions ($ block , $ waitForClosure )
498527 {
499528 while ($ token = $ this ->next ()) {
@@ -507,12 +536,8 @@ protected function parseInstructions($block, $waitForClosure)
507536 $ block ->let ($ this ->parseLet ($ token ));
508537 continue ;
509538 }
510- if ($ token ->is ('keyword ' )) {
511- $ block ->addInstruction ($ this ->parseKeyword ($ token ));
512- continue ;
513- }
514- if ($ value = $ this ->getValueFromToken ($ token )) {
515- $ block ->addInstruction ($ value );
539+ if ($ instruction = $ this ->getInstructionFromToken ($ token )) {
540+ $ block ->addInstruction ($ instruction );
516541 continue ;
517542 }
518543 if ($ token ->is ('; ' )) {
0 commit comments