From dcd6365595bbce211e67cb0169e1bfc4f03fb0e8 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Thu, 23 Apr 2026 20:12:14 +0200 Subject: [PATCH 1/2] Implement logical AND and OR assignment operators (&&=, ||=) --- src/main/php/lang/ast/syntax/PHP.class.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/php/lang/ast/syntax/PHP.class.php b/src/main/php/lang/ast/syntax/PHP.class.php index 145e560..ac75364 100755 --- a/src/main/php/lang/ast/syntax/PHP.class.php +++ b/src/main/php/lang/ast/syntax/PHP.class.php @@ -4,6 +4,7 @@ ArrayLiteral, Annotation, Annotations, + Assignment, Block, Braced, BreakStatement, @@ -233,8 +234,15 @@ public function __construct() { $this->assignment('>>='); $this->assignment('<<='); $this->assignment('??='); - $this->assignment('&&='); - $this->assignment('||='); + + // Logical AND and OR, not supported in PHP + foreach (['&&=', '||='] as $op) { + $this->symbol($op, 10)->led= function($parse, $token, $left) use($op) { + $assign= new Assignment($left, $op, $this->expression($parse, 9), $left->line); + $assign->kind= 'logicalassignment'; + return $assign; + }; + } // This is ambiguous: // From 89f85a87513427899a98ac9b153aa30f85b0db11 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Thu, 23 Apr 2026 20:14:34 +0200 Subject: [PATCH 2/2] Fix tests --- .../php/lang/ast/unittest/parse/OperatorTest.class.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/php/lang/ast/unittest/parse/OperatorTest.class.php b/src/test/php/lang/ast/unittest/parse/OperatorTest.class.php index 89569bc..fd298f6 100755 --- a/src/test/php/lang/ast/unittest/parse/OperatorTest.class.php +++ b/src/test/php/lang/ast/unittest/parse/OperatorTest.class.php @@ -64,7 +64,7 @@ public function prefix($operator) { ); } - #[Test, Values(['=', '+=', '-=', '*=', '/=', '%=', '.=', '**=', '&=', '|=', '^=', '>>=', '<<=', '??=', '&&=', '||='])] + #[Test, Values(['=', '+=', '-=', '*=', '/=', '%=', '.=', '**=', '&=', '|=', '^=', '>>=', '<<=', '??='])] public function assignment($operator) { $this->assertParsed( [new Assignment(new Variable('a', self::LINE), $operator, new Variable('b', self::LINE), self::LINE)], @@ -72,6 +72,13 @@ public function assignment($operator) { ); } + #[Test, Values(['&&=', '||='])] + public function logical_assignment($operator) { + $assignment= new Assignment(new Variable('a', self::LINE), $operator, new Variable('b', self::LINE), self::LINE); + $assignment->kind= 'logicalassignment'; + $this->assertParsed([$assignment], '$a '.$operator.' $b;'); + } + #[Test] public function assignment_to_offset() { $target= new OffsetExpression(new Variable('a', self::LINE), new Literal('0', self::LINE), self::LINE);