From d5a8975d9bbd5957f7cbecb39dea9e146068c5c3 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Tue, 9 Jun 2020 12:40:44 +0200 Subject: [PATCH 1/2] Add test that fails --- tests_dir/fake_union.fail | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests_dir/fake_union.fail diff --git a/tests_dir/fake_union.fail b/tests_dir/fake_union.fail new file mode 100644 index 0000000..6d73276 --- /dev/null +++ b/tests_dir/fake_union.fail @@ -0,0 +1 @@ +ρ name➡n,age➡a(σTrue(people)) ᑌ ρ age➡a,name➡n(people) From 9d1f25d65d577aeee6b3cbae5adf320220f581f4 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Wed, 12 Aug 2020 20:16:40 +0200 Subject: [PATCH 2/2] Parse unary expressions left to right and fail if extra tokens are found This fixes the case where there is garbage after a valid unary operator. --- relational/parser.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/relational/parser.py b/relational/parser.py index 143edf5..dd8ef63 100644 --- a/relational/parser.py +++ b/relational/parser.py @@ -311,11 +311,14 @@ def parse_tokens(expression: List[Union[list, str]]) -> Node: f'Expected right operand for {expression[i]!r}') return Binary(expression[i], parse_tokens(expression[:i]), parse_tokens(expression[i + 1:])) # type: ignore '''Searches for unary operators, parsing from right to left''' - for i in range(len(expression) - 1, -1, -1): + for i in range(len(expression)): if expression[i] in u_operators: # Unary operator if len(expression) <= i + 2: raise ParserException( f'Expected more tokens in {expression[i]!r}') + elif len(expression) > i + 3: + raise ParserException( + f'Too many tokens in {expression[i]!r}') return Unary( expression[i], # type: ignore