From ac852446dd964c40ee2f465a1e955b997cd0d096 Mon Sep 17 00:00:00 2001 From: brendt Date: Thu, 16 Jul 2026 09:55:58 +0200 Subject: [PATCH 1/2] wip --- packages/view/src/Parser/TempestViewLexer.php | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/packages/view/src/Parser/TempestViewLexer.php b/packages/view/src/Parser/TempestViewLexer.php index 36750baae..f1f26bf5a 100644 --- a/packages/view/src/Parser/TempestViewLexer.php +++ b/packages/view/src/Parser/TempestViewLexer.php @@ -24,17 +24,17 @@ public function lex(): TokenCollection $tokens = []; while ($this->current !== null) { - if ($this->comesNext('comesNext('lexXml(); - } elseif ($this->comesNext('comesNext('lexPhp(); - } elseif ($this->comesNext('' && $this->current !== null) { + while (! $this->comesNext('-->', 3) && $this->current !== null) { $buffer .= $this->consume(); } @@ -264,7 +279,7 @@ private function lexCharacterData(): array $contentLine = $this->line; - while ($this->seek(3) !== ']]>' && $this->current !== null) { + while (! $this->comesNext(']]>', 3) && $this->current !== null) { $buffer .= $this->consume(); } From 904e9dfec6a62eef25863d276ea991d7fa1a2c85 Mon Sep 17 00:00:00 2001 From: brendt Date: Thu, 16 Jul 2026 10:31:35 +0200 Subject: [PATCH 2/2] wip --- packages/view/src/Parser/TempestViewLexer.php | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/packages/view/src/Parser/TempestViewLexer.php b/packages/view/src/Parser/TempestViewLexer.php index f1f26bf5a..83ee0ff78 100644 --- a/packages/view/src/Parser/TempestViewLexer.php +++ b/packages/view/src/Parser/TempestViewLexer.php @@ -59,6 +59,10 @@ private function comesNext(string $search, ?int $length = null): bool private function seek(int $length = 1, int $offset = 0): ?string { + if ($length === 1) { + return $this->html[$this->position + $offset] ?? null; + } + $seek = substr($this->html, $this->position + $offset, $length); if ($seek === '') { @@ -68,11 +72,12 @@ private function seek(int $length = 1, int $offset = 0): ?string return $seek; } - private function seekIgnoringWhitespace(int $length = 1): ?string + private function seekIgnoringWhitespace(): ?string { - $offset = strspn($this->html, self::WHITESPACE, $this->position); - - return $this->seek(length: $length, offset: $offset); + return $this->seek( + // Whitespace offset + offset: strspn($this->html, self::WHITESPACE, $this->position), + ); } private function consume(int $length = 1): string @@ -139,8 +144,15 @@ private function lexTag(): array } else { $tokens[] = $this->makeToken($tag, TokenType::OPEN_TAG_START, $tagLine); - while ($this->seek() !== null && $this->seekIgnoringWhitespace() !== '>' && $this->seekIgnoringWhitespace() !== '/') { - if ($this->seekIgnoringWhitespace(2) === 'current !== null) { + $whitespaceOffset = strspn($this->html, self::WHITESPACE, $this->position); + $next = $this->seek(offset: $whitespaceOffset); + + if ($next === '>' || $next === '/') { + break; + } + + if ($next === '<' && $this->seek(length: 2, offset: $whitespaceOffset) === 'lexPhp(); continue; } @@ -179,7 +191,12 @@ private function lexTag(): array } } - if ($this->seekIgnoringWhitespace() === '>') { + $next = $this->seek( + // Whitespace offset + offset: strspn($this->html, self::WHITESPACE, $this->position), + ); + + if ($next === '>') { $openTagEndLine = $this->line; $tokens[] = $this->makeToken( @@ -187,7 +204,7 @@ private function lexTag(): array type: TokenType::OPEN_TAG_END, line: $openTagEndLine, ); - } elseif ($this->seekIgnoringWhitespace() === '/') { + } elseif ($next === '/') { $selfClosingTagEndLine = $this->line; $tokens[] = $this->makeToken(