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

Commit

Permalink
Grammar: Logical operators are left-associative.
Browse files Browse the repository at this point in the history
Logical operators are commonly left-associative, and so it is in
PHP. This patch change the associativity from right- to left-.
  • Loading branch information
Hywan committed Mar 24, 2017
1 parent c9a965c commit fd13175
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Grammar.pp
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,25 @@
%token identifier [^\s\(\)\[\],\.]+
#expression:
logical_operation()
logical_operation_primary()
logical_operation:
logical_operation_primary:
logical_operation_secondary()
( ( ::or:: #or | ::xor:: #xor ) logical_operation_primary() )?
logical_operation_secondary:
operation()
( ( ::and:: #and | ::or:: #or | ::xor:: #xor ) logical_operation() )?
( ::and:: #and logical_operation_secondary() )?
operation:
operand() ( <identifier> logical_operation() #operation )?
operand() ( <identifier> logical_operation_primary() #operation )?
operand:
::parenthesis_:: logical_operation() ::_parenthesis::
::parenthesis_:: logical_operation_primary() ::_parenthesis::
| value()
value:
::not:: logical_operation() #not
::not:: logical_operation_primary() #not
| <true> | <false> | <null> | <float> | <integer> | <string>
| array_declaration()
| chain()
Expand All @@ -104,5 +108,5 @@
#function_call:
<identifier> ::parenthesis_::
( logical_operation() ( ::comma:: logical_operation() )* )?
( logical_operation_primary() ( ::comma:: logical_operation_primary() )* )?
::_parenthesis::
39 changes: 39 additions & 0 deletions Test/Unit/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,43 @@ public function case_github_70()
->boolean($result)
->isTrue();
}

public function case_github_100_1()
{
$this
->given(
$ruler = new LUT(),
$rule = '(false and true) or true'
)
->when($result = $ruler->assert($rule))
->then
->boolean($result)
->isTrue();
}

public function case_github_100_2()
{
$this
->given(
$ruler = new LUT(),
$rule = 'false and true or true'
)
->when($result = $ruler->assert($rule))
->then
->boolean($result)
->isTrue();
}

public function case_github_100_3()
{
$this
->given(
$ruler = new LUT(),
$rule = 'true or true and false'
)
->when($result = $ruler->assert($rule))
->then
->boolean($result)
->isTrue();
}
}

0 comments on commit fd13175

Please sign in to comment.