@@ -731,6 +731,72 @@ protected function tokenize($string)
731
731
continue ;
732
732
}//end if
733
733
734
+ /*
735
+ Before PHP 7.0, the "yield from" was tokenized as
736
+ T_YIELD, T_WHITESPACE and T_STRING. So look for
737
+ and change this token in earlier versions.
738
+ */
739
+
740
+ if (PHP_VERSION_ID < 70000
741
+ && PHP_VERSION_ID >= 50500
742
+ && $ tokenIsArray === true
743
+ && $ token [0 ] === T_YIELD
744
+ && isset ($ tokens [($ stackPtr + 1 )]) === true
745
+ && isset ($ tokens [($ stackPtr + 2 )]) === true
746
+ && $ tokens [($ stackPtr + 1 )][0 ] === T_WHITESPACE
747
+ && $ tokens [($ stackPtr + 2 )][0 ] === T_STRING
748
+ && strtolower ($ tokens [($ stackPtr + 2 )][1 ]) === 'from '
749
+ ) {
750
+ $ newToken = array ();
751
+ $ newToken ['code ' ] = T_YIELD_FROM ;
752
+ $ newToken ['type ' ] = 'T_YIELD_FROM ' ;
753
+ $ newToken ['content ' ] = $ token [1 ].$ tokens [($ stackPtr + 1 )][1 ].$ tokens [($ stackPtr + 2 )][1 ];
754
+ $ finalTokens [$ newStackPtr ] = $ newToken ;
755
+
756
+ $ newStackPtr ++;
757
+ $ stackPtr += 2 ;
758
+ continue ;
759
+ }
760
+
761
+ /*
762
+ Before PHP 5.5, the yield keyword was tokenized as
763
+ T_STRING. So look for and change this token in
764
+ earlier versions.
765
+ Checks also if it is just "yield" or "yield from".
766
+ */
767
+
768
+ if (PHP_VERSION_ID < 50500
769
+ && $ tokenIsArray === true
770
+ && $ token [0 ] === T_STRING
771
+ && strtolower ($ token [1 ]) === 'yield '
772
+ ) {
773
+ if (isset ($ tokens [($ stackPtr + 1 )]) === true
774
+ && isset ($ tokens [($ stackPtr + 2 )]) === true
775
+ && $ tokens [($ stackPtr + 1 )][0 ] === T_WHITESPACE
776
+ && $ tokens [($ stackPtr + 2 )][0 ] === T_STRING
777
+ && strtolower ($ tokens [($ stackPtr + 2 )][1 ]) === 'from '
778
+ ) {
779
+ $ newToken = array ();
780
+ $ newToken ['code ' ] = T_YIELD_FROM ;
781
+ $ newToken ['type ' ] = 'T_YIELD_FROM ' ;
782
+ $ newToken ['content ' ] = $ token [1 ].$ tokens [($ stackPtr + 1 )][1 ].$ tokens [($ stackPtr + 2 )][1 ];
783
+ $ finalTokens [$ newStackPtr ] = $ newToken ;
784
+
785
+ $ newStackPtr ++;
786
+ $ stackPtr += 2 ;
787
+ continue ;
788
+ }
789
+
790
+ $ newToken = array ();
791
+ $ newToken ['code ' ] = T_YIELD ;
792
+ $ newToken ['type ' ] = 'T_YIELD ' ;
793
+ $ newToken ['content ' ] = $ token [1 ];
794
+ $ finalTokens [$ newStackPtr ] = $ newToken ;
795
+
796
+ $ newStackPtr ++;
797
+ continue ;
798
+ }//end if
799
+
734
800
/*
735
801
Before PHP 5.6, the ... operator was tokenized as three
736
802
T_STRING_CONCAT tokens in a row. So look for and combine
0 commit comments