diff --git a/GRAMMAR.md b/GRAMMAR.md index 8761de81e3..00721f15af 100644 --- a/GRAMMAR.md +++ b/GRAMMAR.md @@ -90,13 +90,17 @@ import : 'import' '?'? string? eol module : 'mod' '?'? NAME string? eol -expression : 'if' condition '{' expression '}' 'else' '{' expression '}' +expression : disjunct || expression + | disjunct + +disjunct : conjunct && disjunct + | conjunct + +conjunct : 'if' condition '{' expression '}' 'else' '{' expression '}' | 'assert' '(' condition ',' expression ')' | '/' expression | value '/' expression | value '+' expression - | value '&&' expression - | value '||' expression | value condition : expression '==' expression diff --git a/src/parser.rs b/src/parser.rs index 113f25f34d..4bd8317641 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -537,7 +537,7 @@ impl<'run, 'src> Parser<'run, 'src> { let disjunct = if self.accepted(AmpersandAmpersand)? { let lhs = conjunct.into(); - let rhs = self.parse_conjunct()?.into(); + let rhs = self.parse_disjunct()?.into(); Expression::And { lhs, rhs } } else { conjunct diff --git a/tests/and_or.rs b/tests/and_or.rs index 4bdc666ba8..6133f52546 100644 --- a/tests/and_or.rs +++ b/tests/and_or.rs @@ -56,3 +56,9 @@ fn and_has_higher_precedence_than_or() { evaluate("('' && 'foo') || 'bar'", "bar"); evaluate("'' && 'foo' || 'bar'", "bar"); } + +#[test] +fn misc() { + evaluate("'' || '' || '' || '' || 'foo'", "foo"); + evaluate("'foo' && 'foo' && 'foo' && 'foo' && 'bar'", "bar"); +}