From aa8af156c861e76fc5b3423661ff0e60dfa6b7d0 Mon Sep 17 00:00:00 2001 From: Ziyang Hu Date: Mon, 8 May 2023 17:26:06 +0800 Subject: [PATCH] Fixes https://github.com/cozodb/cozo/issues/97 --- cozo-core/src/cozoscript.pest | 6 +++--- cozo-core/src/runtime/tests.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/cozo-core/src/cozoscript.pest b/cozo-core/src/cozoscript.pest index 1dddee1c..dbaf8ad4 100644 --- a/cozo-core/src/cozoscript.pest +++ b/cozo-core/src/cozoscript.pest @@ -84,11 +84,11 @@ relation_named_apply = {relation_ident ~ "{" ~ named_apply_args ~ validity_claus relation_apply = {relation_ident ~ "[" ~ apply_args ~ validity_clause? ~ "]"} search_apply = {search_index_ident ~ "{" ~ named_apply_args ~ "|" ~ (index_opt_field ~ ",")* ~ index_opt_field? ~ "}"} -disjunction = {(atom ~ "or" )* ~ atom} +disjunction = {(atom ~ WHITESPACE+ ~ "or" ~ WHITESPACE+ )* ~ atom} atom = _{ negation | relation_named_apply | relation_apply | search_apply | rule_apply | unify_multi | unify | expr | grouped} unify = {var ~ "=" ~ expr} -unify_multi = {var ~ "in" ~ expr} -negation = {"not" ~ atom} +unify_multi = {var ~ WHITESPACE+ ~ "in" ~ WHITESPACE+ ~ expr} +negation = {"not" ~ WHITESPACE+ ~ atom} apply = {ident ~ "(" ~ apply_args ~ ")"} apply_args = {(expr ~ ",")* ~ expr?} named_apply_args = {(named_apply_pair ~ ",")* ~ named_apply_pair?} diff --git a/cozo-core/src/runtime/tests.rs b/cozo-core/src/runtime/tests.rs index fa032ead..c4a42127 100644 --- a/cozo-core/src/runtime/tests.rs +++ b/cozo-core/src/runtime/tests.rs @@ -1159,3 +1159,22 @@ fn multi_index_vec() { println!("{}", row); } } + +#[test] +fn parser_corner_case() { + let db = DbInstance::new("mem", "", "").unwrap(); + db.run_script( + r#" + ?[C] := C = 1 + orx[C] := C = 1 + "#, + Default::default(), + ).unwrap(); + db.run_script( + r#" + ?[C] := C = true, C + inx[C] := C = 1 + "#, + Default::default(), + ).unwrap(); +} \ No newline at end of file