Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions resources/files/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . ")";
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 11 additions & 2 deletions src/Parser/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, ' .
Expand Down
Loading