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: // 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);