-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTokenMerger.php
More file actions
38 lines (29 loc) · 825 Bytes
/
Copy pathTokenMerger.php
File metadata and controls
38 lines (29 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace Torchlight\Engine\Support;
use Phiki\Token\Token;
class TokenMerger
{
/**
* @param array<int, Token[]> $lines
* @return array<int, Token[]>
*/
public static function merge(array $lines): array
{
foreach ($lines as $i => $tokens) {
$merged = [];
foreach ($tokens as $token) {
if (! empty($merged)) {
$lastToken = end($merged);
if ($lastToken->scopes === $token->scopes) {
$lastToken->text .= $token->text;
$lastToken->end = $token->end;
continue;
}
}
$merged[] = $token;
}
$lines[$i] = $merged;
}
return $lines;
}
}