Skip to content

Commit 97b59e4

Browse files
committed
Coalesce pipe operator tokens on older runtimes
1 parent fd0ade1 commit 97b59e4

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/PhpTokenizer.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,22 @@ public static function getTokensArrayFromContent(
108108

109109
// Convert tokens from token_get_all to Token instances,
110110
// skipping whitespace and (usually, when parseContext is null) comments.
111-
foreach ($tokens as $token) {
111+
$tokens = \array_values($tokens);
112+
$tokenCount = \count($tokens);
113+
for ($i = 0; $i < $tokenCount; $i++) {
114+
$token = $tokens[$i];
112115
if (\is_array($token)) {
113116
$tokenKind = $token[0];
114117
$strlen = \strlen($token[1]);
115118
} else {
119+
if ($token === '|' && $i + 1 < $tokenCount && $tokens[$i + 1] === '>') {
120+
$pos += 1; // '|'
121+
$i++;
122+
$pos += 1; // '>'
123+
$arr[] = new Token(TokenKind::PipeToken, $fullStart, $start, $pos - $fullStart);
124+
$start = $fullStart = $pos;
125+
continue;
126+
}
116127
$pos += \strlen($token);
117128
$newTokenKind = self::TOKEN_MAP[$token] ?? TokenKind::Unknown;
118129
$arr[] = new Token($newTokenKind, $fullStart, $start, $pos - $fullStart);

0 commit comments

Comments
 (0)