Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Commit fd13175

Browse files
committed
Grammar: Logical operators are left-associative.
Logical operators are commonly left-associative, and so it is in PHP. This patch change the associativity from right- to left-.
1 parent c9a965c commit fd13175

2 files changed

Lines changed: 50 additions & 7 deletions

File tree

Grammar.pp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,25 @@
6767
%token identifier [^\s\(\)\[\],\.]+
6868
6969
#expression:
70-
logical_operation()
70+
logical_operation_primary()
7171
72-
logical_operation:
72+
logical_operation_primary:
73+
logical_operation_secondary()
74+
( ( ::or:: #or | ::xor:: #xor ) logical_operation_primary() )?
75+
76+
logical_operation_secondary:
7377
operation()
74-
( ( ::and:: #and | ::or:: #or | ::xor:: #xor ) logical_operation() )?
78+
( ::and:: #and logical_operation_secondary() )?
7579
7680
operation:
77-
operand() ( <identifier> logical_operation() #operation )?
81+
operand() ( <identifier> logical_operation_primary() #operation )?
7882
7983
operand:
80-
::parenthesis_:: logical_operation() ::_parenthesis::
84+
::parenthesis_:: logical_operation_primary() ::_parenthesis::
8185
| value()
8286
8387
value:
84-
::not:: logical_operation() #not
88+
::not:: logical_operation_primary() #not
8589
| <true> | <false> | <null> | <float> | <integer> | <string>
8690
| array_declaration()
8791
| chain()
@@ -104,5 +108,5 @@
104108
105109
#function_call:
106110
<identifier> ::parenthesis_::
107-
( logical_operation() ( ::comma:: logical_operation() )* )?
111+
( logical_operation_primary() ( ::comma:: logical_operation_primary() )* )?
108112
::_parenthesis::

Test/Unit/Issue.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,43 @@ public function case_github_70()
7979
->boolean($result)
8080
->isTrue();
8181
}
82+
83+
public function case_github_100_1()
84+
{
85+
$this
86+
->given(
87+
$ruler = new LUT(),
88+
$rule = '(false and true) or true'
89+
)
90+
->when($result = $ruler->assert($rule))
91+
->then
92+
->boolean($result)
93+
->isTrue();
94+
}
95+
96+
public function case_github_100_2()
97+
{
98+
$this
99+
->given(
100+
$ruler = new LUT(),
101+
$rule = 'false and true or true'
102+
)
103+
->when($result = $ruler->assert($rule))
104+
->then
105+
->boolean($result)
106+
->isTrue();
107+
}
108+
109+
public function case_github_100_3()
110+
{
111+
$this
112+
->given(
113+
$ruler = new LUT(),
114+
$rule = 'true or true and false'
115+
)
116+
->when($result = $ruler->assert($rule))
117+
->then
118+
->boolean($result)
119+
->isTrue();
120+
}
82121
}

0 commit comments

Comments
 (0)