|
15 | 15 | use Codewithkyrian\Jinja\AST\KeywordArgumentExpression; |
16 | 16 | use Codewithkyrian\Jinja\AST\Macro; |
17 | 17 | use Codewithkyrian\Jinja\AST\MemberExpression; |
| 18 | +use Codewithkyrian\Jinja\AST\NullLiteral; |
18 | 19 | use Codewithkyrian\Jinja\AST\NumericLiteral; |
19 | 20 | use Codewithkyrian\Jinja\AST\ObjectLiteral; |
20 | 21 | use Codewithkyrian\Jinja\AST\Program; |
@@ -541,16 +542,20 @@ private function parseMultiplicativeExpression(): Statement |
541 | 542 | private function parseTestExpression(): Statement |
542 | 543 | { |
543 | 544 | $operand = $this->parseFilterExpression(); |
| 545 | + |
544 | 546 | while ($this->is(TokenType::Is)) { |
545 | 547 | $this->current++; // consume is |
546 | 548 | $negate = $this->is(TokenType::Not); |
| 549 | + |
547 | 550 | if ($negate) { |
548 | 551 | $this->current++; // consume not |
549 | 552 | } |
| 553 | + |
550 | 554 | $filter = $this->parsePrimaryExpression(); |
551 | 555 | if ($filter instanceof BooleanLiteral) { |
552 | | - // PHP version: treating boolean literals as identifiers might require manual handling |
553 | 556 | $filter = new Identifier((string)$filter->value); |
| 557 | + } elseif ($filter instanceof NullLiteral) { |
| 558 | + $filter = new Identifier("none"); |
554 | 559 | } |
555 | 560 | if (!($filter instanceof Identifier)) { |
556 | 561 | throw new SyntaxError("Expected identifier for the test"); |
@@ -597,6 +602,10 @@ private function parsePrimaryExpression(): Statement |
597 | 602 | $this->current++; |
598 | 603 | return new BooleanLiteral(strtolower($token->value) === "true"); |
599 | 604 |
|
| 605 | + case TokenType::NullLiteral: |
| 606 | + $this->current++; |
| 607 | + return new NullLiteral(); |
| 608 | + |
600 | 609 | case TokenType::Identifier: |
601 | 610 | $this->current++; |
602 | 611 | return new Identifier($token->value); |
|
0 commit comments