diff --git a/src/Parser/Parser.php b/src/Parser/Parser.php index fb3fc34..5029228 100644 --- a/src/Parser/Parser.php +++ b/src/Parser/Parser.php @@ -14,6 +14,7 @@ namespace Phalcon\Volt\Parser; use Phalcon\Volt\Compiler; +use Phalcon\Volt\Exception; use Phalcon\Volt\Scanner\Opcode; use Phalcon\Volt\Scanner\Scanner; use Phalcon\Volt\Scanner\State; @@ -37,6 +38,7 @@ public function __construct(private string $code) * @param string $templatePath * * @return array + * @throws Exception */ public function parseView(string $templatePath): array { @@ -386,24 +388,26 @@ public function parseView(string $templatePath): array break; case Compiler::PHVOLT_T_RAW_FRAGMENT: - if ($state->extendsMode === 1 && $state->blockLevel === 0) { - $this->createErrorMessage( - $parserStatus, - 'Child templates only may contain blocks' - ); - $parserStatus->setStatus(Status::PHVOLT_PARSING_FAILED); - break; - } + if ($state->rawFragment !== '') { + if ($state->extendsMode === 1 && $state->blockLevel === 0) { + $this->createErrorMessage( + $parserStatus, + 'Child templates only may contain blocks' + ); + $parserStatus->setStatus(Status::PHVOLT_PARSING_FAILED); + break; + } + + if (!$this->phvoltIsBlankString($this->token)) { + $state->statementPosition++; + } - if (!$this->phvoltIsBlankString($this->token)) { - $state->statementPosition++; + $this->phvoltParseWithToken( + $parser, + Compiler::PHVOLT_T_RAW_FRAGMENT, + Opcode::PHVOLT_RAW_FRAGMENT + ); } - - $this->phvoltParseWithToken( - $parser, - Compiler::PHVOLT_T_RAW_FRAGMENT, - Opcode::PHVOLT_RAW_FRAGMENT - ); break; case Compiler::PHVOLT_T_SET: @@ -595,7 +599,7 @@ public function parseView(string $templatePath): array } if ($parserStatus->getStatus() !== Status::PHVOLT_PARSING_OK) { - break; + throw new Exception($parserStatus->getSyntaxError()); } $state->setEnd($state->getStart());