@@ -149,9 +149,50 @@ public static function getTokensArrayFromContent(
149149 $ start = $ fullStart = $ pos ;
150150 break ;
151151 case \T_OPEN_TAG :
152+ if ($ token [1 ] === '<? ' && $ i + 1 < $ tokenCount ) {
153+ $ nextToken = $ tokens [$ keys [$ i + 1 ]];
154+ if (\is_array ($ nextToken ) && $ nextToken [0 ] === \T_STRING && \strcasecmp ($ nextToken [1 ], 'php ' ) === 0 ) {
155+ $ pos += \strlen ($ nextToken [1 ]);
156+ $ i ++;
157+ $ strlen += \strlen ($ nextToken [1 ]);
158+ }
159+ }
152160 $ arr [] = new Token (TokenKind::ScriptSectionStartTag, $ fullStart , $ start , $ pos -$ fullStart );
153161 $ start = $ fullStart = $ pos ;
154162 break ;
163+ case \T_YIELD :
164+ if ($ treatCommentsAsTrivia ) {
165+ $ yieldFromEndIndex = $ i ;
166+ for ($ lookahead = $ i + 1 ; $ lookahead < $ tokenCount ; $ lookahead ++) {
167+ $ lookaheadToken = $ tokens [$ keys [$ lookahead ]];
168+ if (\is_array ($ lookaheadToken )) {
169+ $ lookaheadKind = $ lookaheadToken [0 ];
170+ if ($ lookaheadKind === \T_WHITESPACE ) {
171+ continue ;
172+ }
173+ if (($ lookaheadKind === \T_COMMENT || $ lookaheadKind === \T_DOC_COMMENT ) && $ treatCommentsAsTrivia ) {
174+ continue ;
175+ }
176+ if ($ lookaheadKind === \T_STRING && \strcasecmp ($ lookaheadToken [1 ], 'from ' ) === 0 ) {
177+ $ yieldFromEndIndex = $ lookahead ;
178+ }
179+ }
180+ break ;
181+ }
182+ if ($ yieldFromEndIndex !== $ i ) {
183+ for ($ consume = $ i + 1 ; $ consume <= $ yieldFromEndIndex ; $ consume ++) {
184+ $ consumed = $ tokens [$ keys [$ consume ]];
185+ $ pos += \is_array ($ consumed ) ? \strlen ($ consumed [1 ]) : \strlen ($ consumed );
186+ }
187+ $ i = $ yieldFromEndIndex ;
188+ $ arr [] = new Token (TokenKind::YieldFromKeyword, $ fullStart , $ start , $ pos - $ fullStart );
189+ $ start = $ fullStart = $ pos ;
190+ break ;
191+ }
192+ }
193+ $ arr [] = new Token (TokenKind::YieldKeyword, $ fullStart , $ start , $ pos - $ fullStart );
194+ $ start = $ fullStart = $ pos ;
195+ break ;
155196 case \PHP_VERSION_ID >= 80000 ? \T_NAME_QUALIFIED : -1000 :
156197 case \PHP_VERSION_ID >= 80000 ? \T_NAME_FULLY_QUALIFIED : -1001 :
157198 // NOTE: This switch is called on every token of every file being parsed, so this traded performance for readability.
@@ -167,8 +208,8 @@ public static function getTokensArrayFromContent(
167208 //
168209 // T_NAME_* was added in php 8.0 to forbid whitespace between parts of names.
169210 // Here, emulate the tokenization of php 7 by splitting it up into 1 or more tokens.
170- foreach (\explode ('\\' , $ token [1 ]) as $ i => $ name ) {
171- if ($ i ) {
211+ foreach (\explode ('\\' , $ token [1 ]) as $ segmentIndex => $ name ) {
212+ if ($ segmentIndex ) {
172213 $ arr [] = new Token (TokenKind::BackslashToken, $ fullStart , $ start , 1 + $ start - $ fullStart );
173214 $ start ++;
174215 $ fullStart = $ start ;
@@ -185,9 +226,9 @@ public static function getTokensArrayFromContent(
185226 break ;
186227 case \PHP_VERSION_ID >= 80000 ? \T_NAME_RELATIVE : -1002 :
187228 // This is a namespace-relative name: namespace\...
188- foreach (\explode ('\\' , $ token [1 ]) as $ i => $ name ) {
229+ foreach (\explode ('\\' , $ token [1 ]) as $ segmentIndex => $ name ) {
189230 $ len = \strlen ($ name );
190- if (!$ i ) {
231+ if (!$ segmentIndex ) {
191232 $ arr [] = new Token (TokenKind::NamespaceKeyword, $ fullStart , $ start , $ len + $ start - $ fullStart );
192233 $ start += $ len ;
193234 $ fullStart = $ start ;
0 commit comments