From 6c0608356a9ff0eb745134f10346d29c8ffbf5b8 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Thu, 19 May 2016 01:25:53 -0700 Subject: [PATCH 1/3] Allow key paths to start with "not" in queries Fixes #445 --- src/parser/parser.cpp | 8 +++++--- tests/parser.cpp | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp index 6b981b3e..88f2a9f0 100644 --- a/src/parser/parser.cpp +++ b/src/parser/parser.cpp @@ -24,6 +24,8 @@ #include #include +#define string_operator_t(s) seq< pegtl_istring_t(s), not_at< identifier_other > > + using namespace pegtl; namespace realm { @@ -93,11 +95,11 @@ struct group_pred : if_must< one< '(' >, pad< pred, blank >, one< ')' > > {}; struct true_pred : pegtl_istring_t("truepredicate") {}; struct false_pred : pegtl_istring_t("falsepredicate") {}; -struct not_pre : seq< sor< one< '!' >, pegtl_istring_t("not") > > {}; +struct not_pre : seq< sor< one< '!' >, string_operator_t("not") > > {}; struct atom_pred : seq< opt< not_pre >, pad< sor< group_pred, true_pred, false_pred, comparison_pred >, blank > > {}; -struct and_op : pad< sor< two< '&' >, pegtl_istring_t("and") >, blank > {}; -struct or_op : pad< sor< two< '|' >, pegtl_istring_t("or") >, blank > {}; +struct and_op : pad< sor< two< '&' >, string_operator_t("and") >, blank > {}; +struct or_op : pad< sor< two< '|' >, string_operator_t("or") >, blank > {}; struct or_ext : if_must< or_op, pred > {}; struct and_ext : if_must< and_op, pred > {}; diff --git a/tests/parser.cpp b/tests/parser.cpp index 93d5f159..6062928e 100644 --- a/tests/parser.cpp +++ b/tests/parser.cpp @@ -66,6 +66,9 @@ static std::vector valid_queries = { "!(0=0)", "! (0=0)", "NOT0=0", // keypath NOT0 + "NOT0.a=0", // keypath NOT0 + "NOT0a.b=0", // keypath NOT0a + "not-1=1", "not 0=0", "NOT(0=0)", "not (0=0)", @@ -121,6 +124,7 @@ static std::vector invalid_queries = { "(0=0))", "! =0", "NOTNOT(0=0)", + "not.a=0", "(!!0=0)", "0=0 !", @@ -130,7 +134,7 @@ static std::vector invalid_queries = { "a==a &| a==a", "a==a && OR a==a", "a==aORa==a", - //"a=1ANDNOT b=2", + "a=1ANDNOT b=2", "truepredicate &&", "truepredicate & truepredicate", From 56b0871a2633f782e52ab300f38db7544a8a5d59 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Thu, 19 May 2016 13:08:39 -0700 Subject: [PATCH 2/3] Add a few more parser tests --- tests/parser.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/parser.cpp b/tests/parser.cpp index 6062928e..15c5cf2c 100644 --- a/tests/parser.cpp +++ b/tests/parser.cpp @@ -134,6 +134,9 @@ static std::vector invalid_queries = { "a==a &| a==a", "a==a && OR a==a", "a==aORa==a", + "a==a ORa==a", + "a==a AND==a", + "a==a ANDa==a", "a=1ANDNOT b=2", "truepredicate &&", From ea697f9904a71373cbd309fd88c0bdb1a04f70d1 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Thu, 19 May 2016 13:12:40 -0700 Subject: [PATCH 3/3] Include comment about string_operator_t --- src/parser/parser.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp index 88f2a9f0..07b97bb4 100644 --- a/src/parser/parser.cpp +++ b/src/parser/parser.cpp @@ -24,6 +24,7 @@ #include #include +// String operators (e.g. AND, OR, NOT) can't be followed by [A-z0-9_]. #define string_operator_t(s) seq< pegtl_istring_t(s), not_at< identifier_other > > using namespace pegtl;