diff --git a/composer.lock b/composer.lock index 5623551..3320ed8 100644 --- a/composer.lock +++ b/composer.lock @@ -347,11 +347,11 @@ }, { "name": "phpstan/phpstan", - "version": "2.1.46", + "version": "2.1.47", "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/a193923fc2d6325ef4e741cf3af8c3e8f54dbf25", - "reference": "a193923fc2d6325ef4e741cf3af8c3e8f54dbf25", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/79015445d8bd79e62b29140f12e5bfced1dcca65", + "reference": "79015445d8bd79e62b29140f12e5bfced1dcca65", "shasum": "" }, "require": { @@ -396,7 +396,7 @@ "type": "github" } ], - "time": "2026-04-01T09:25:14+00:00" + "time": "2026-04-13T15:49:08+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/resources/files/parser.php b/resources/files/parser.php index 73cbeb1..81d173d 100644 --- a/resources/files/parser.php +++ b/resources/files/parser.php @@ -3253,7 +3253,7 @@ private function yy_syntax_error(): void $error_str .= $token_name; } - $tokenValue = $this->status->getToken()->value; + $tokenValue = $this->status->getToken()->value ?? $this->status->getLastTokenValue(); $tokenValue = $tokenValue !== null ? trim($tokenValue) : null; if ($tokenValue) { $error_str .= "(" . $tokenValue . ")"; @@ -3528,12 +3528,8 @@ function phvolt_ret_for_statement( ): void { $ret = [ - "type" => Compiler::PHVOLT_T_FOR, + "type" => Compiler::PHVOLT_T_FOR, "variable" => $variable->value, - "expr" => $expr, - "block_statements" => $block_statements, - "file" => $state->getActiveFile(), - "line" => $state->getActiveLine(), ]; unset($variable); @@ -3543,9 +3539,15 @@ function phvolt_ret_for_statement( unset($key); } + $ret["expr"] = $expr; + if ($if_expr !== null) { $ret["if_expr"] = $if_expr; } + + $ret["block_statements"] = $block_statements; + $ret["file"] = $state->getActiveFile(); + $ret["line"] = $state->getActiveLine(); } function phvolt_ret_literal_zval(&$ret, $type, ?Token $token = null, ?State $state = null): void @@ -3596,8 +3598,6 @@ function phvolt_ret_macro_call_statement(&$ret, $expr, $arguments, $caller, Stat $ret = [ "type" => Compiler::PHVOLT_T_CALL, "name" => $expr, - "file" => $state->getActiveFile(), - "line" => $state->getActiveLine(), ]; if ($arguments !== null) { @@ -3607,6 +3607,9 @@ function phvolt_ret_macro_call_statement(&$ret, $expr, $arguments, $caller, Stat if ($caller !== null) { $ret["caller"] = $caller; } + + $ret["file"] = $state->getActiveFile(); + $ret["line"] = $state->getActiveLine(); } function phvolt_ret_echo_statement(&$ret, $expr, State $state): void diff --git a/src/Compiler.php b/src/Compiler.php index 2622d7c..2faedb1 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -79,7 +79,7 @@ class Compiler public const PHVOLT_T_AND = 266; public const PHVOLT_T_ARRAY = 360; public const PHVOLT_T_ARRAYACCESS = 361; - public const PHVOLT_T_ASSIGN = 64; //'='; + public const PHVOLT_T_ASSIGN = 61; //'='; public const PHVOLT_T_AUTOESCAPE = 317; public const PHVOLT_T_BLOCK = 307; public const PHVOLT_T_BREAK = 320; @@ -192,8 +192,8 @@ class Compiler public const PHVOLT_T_RAW_FRAGMENT = 357; public const PHVOLT_T_RESOLVED_EXPR = 364; public const PHVOLT_T_RETURN = 327; - public const PHVOLT_T_SBRACKET_CLOSE = 91; //']'; - public const PHVOLT_T_SBRACKET_OPEN = 93; //'['; + public const PHVOLT_T_SBRACKET_CLOSE = 93; //']'; + public const PHVOLT_T_SBRACKET_OPEN = 91; //'['; public const PHVOLT_T_SCALAR = 384; public const PHVOLT_T_SET = 306; public const PHVOLT_T_SLICE = 365; diff --git a/src/Parser/Status.php b/src/Parser/Status.php index 2a8a4cd..7b19f6e 100644 --- a/src/Parser/Status.php +++ b/src/Parser/Status.php @@ -21,8 +21,9 @@ class Status public const PHVOLT_PARSING_FAILED = 0; public const PHVOLT_PARSING_OK = 1; - private ?string $syntaxError = null; - private ?Token $token = null; + private ?string $lastTokenValue = null; + private ?string $syntaxError = null; + private ?Token $token = null; public function __construct( private State $scannerState, @@ -45,6 +46,11 @@ public function getSyntaxError(): ?string return $this->syntaxError; } + public function getLastTokenValue(): ?string + { + return $this->lastTokenValue; + } + public function getToken(): ?Token { return $this->token; @@ -67,6 +73,9 @@ public function setSyntaxError(string $syntaxError): static public function setToken(Token $token): static { $this->token = $token; + if ($token->value !== null) { + $this->lastTokenValue = $token->value; + } return $this; } diff --git a/tests/unit/ParseTest.php b/tests/unit/ParseTest.php index 47b4b89..e5fb816 100644 --- a/tests/unit/ParseTest.php +++ b/tests/unit/ParseTest.php @@ -288,7 +288,7 @@ public static function getVoltSyntaxErrors(): array {% endfor %} ', - 'Syntax error, unexpected token ~ in eval code on line 4', + 'Syntax error, unexpected token ~(id) in eval code on line 4', ], [ '\'{{ link_to("album/" ~ album.id ~ "/" ~ $album.uri, ' .