feat: CI/CD pipeline setup complete - Ansible playbooks updated, secrets configured, workflow ready
This commit is contained in:
@@ -186,15 +186,86 @@ final readonly class TokenCollection implements IteratorAggregate, Countable
|
||||
{
|
||||
$groups = [];
|
||||
foreach ($this->tokens as $token) {
|
||||
if (! isset($groups[$token->line])) {
|
||||
$groups[$token->line] = [];
|
||||
// Split whitespace tokens that span multiple lines
|
||||
if ($token->type === TokenType::WHITESPACE && str_contains($token->value, "\n")) {
|
||||
$splitTokens = $this->splitWhitespaceAtNewlines($token);
|
||||
foreach ($splitTokens as $splitToken) {
|
||||
if (! isset($groups[$splitToken->line])) {
|
||||
$groups[$splitToken->line] = [];
|
||||
}
|
||||
$groups[$splitToken->line][] = $splitToken;
|
||||
}
|
||||
} else {
|
||||
if (! isset($groups[$token->line])) {
|
||||
$groups[$token->line] = [];
|
||||
}
|
||||
$groups[$token->line][] = $token;
|
||||
}
|
||||
$groups[$token->line][] = $token;
|
||||
}
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split a whitespace token at newline boundaries
|
||||
*
|
||||
* When a whitespace token spans multiple lines like "\n ", the leading spaces
|
||||
* after the newline belong to the NEXT line, not the current one.
|
||||
*
|
||||
* Example: Token with value "\n " on line 13:
|
||||
* - "\n" belongs to line 13 (ends the line)
|
||||
* - " " belongs to line 14 (starts the next line)
|
||||
*
|
||||
* @return Token[]
|
||||
*/
|
||||
private function splitWhitespaceAtNewlines(Token $token): array
|
||||
{
|
||||
$parts = preg_split('/(\r\n|\n|\r)/', $token->value, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$result = [];
|
||||
|
||||
// Calculate starting line: token.line is where it ENDS
|
||||
$startLine = $token->line - substr_count($token->value, "\n");
|
||||
$currentLine = $startLine;
|
||||
|
||||
for ($i = 0; $i < count($parts); $i++) {
|
||||
$part = $parts[$i];
|
||||
|
||||
// Skip empty parts
|
||||
if ($part === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if this is a newline delimiter
|
||||
$isNewline = in_array($part, ["\r\n", "\n", "\r"], true);
|
||||
|
||||
if ($isNewline) {
|
||||
// Newline belongs to current line (ends it)
|
||||
$result[] = new Token(
|
||||
type: TokenType::WHITESPACE,
|
||||
value: $part,
|
||||
line: $currentLine,
|
||||
position: $token->position,
|
||||
id: $token->id,
|
||||
context: $token->context
|
||||
);
|
||||
$currentLine++;
|
||||
} else {
|
||||
// Non-newline whitespace: assign to current line
|
||||
// (which is the line AFTER the newline if we just processed one)
|
||||
$result[] = new Token(
|
||||
type: TokenType::WHITESPACE,
|
||||
value: $part,
|
||||
line: $currentLine,
|
||||
position: $token->position,
|
||||
id: $token->id,
|
||||
context: $token->context
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if collection is empty
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user