From bb16ffa7fe89002854530550506a465b5508a2d0 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Tue, 10 Nov 2015 13:17:27 -0800 Subject: [PATCH] add required padding around string operators, use pegtl_istring_t --- src/object-store/parser/parser.cpp | 30 ++++++++++++++++++------------ src/object-store/parser/query.abnf | 23 ----------------------- 2 files changed, 18 insertions(+), 35 deletions(-) delete mode 100644 src/object-store/parser/query.abnf diff --git a/src/object-store/parser/parser.cpp b/src/object-store/parser/parser.cpp index 03dbd39d..699739db 100644 --- a/src/object-store/parser/parser.cpp +++ b/src/object-store/parser/parser.cpp @@ -23,6 +23,7 @@ #include #include #include +#include using namespace pegtl; @@ -71,27 +72,32 @@ struct lteq : pegtl::string< '<', '=' > {}; struct lt : one< '<' > {}; struct gteq : pegtl::string< '>', '=' > {}; struct gt : one< '>' > {}; -struct begins : istring< 'b','e','g','i','n','s','w','i','t','h' > {}; -struct ends : istring< 'e','n','d','s','w','i','t','h' > {}; -struct contains : istring< 'c','o','n','t','a','i','n','s' > {}; -struct oper : sor< eq, noteq, lteq, lt, gteq, gt, begins, ends, contains > {}; +struct contains : pegtl_istring_t("contains") {}; +struct begins : pegtl_istring_t("beginswith") {}; +struct ends : pegtl_istring_t("endswith") {}; + +template +struct pad_plus : seq< plus< B >, A, plus< B > > {}; + +struct padded_oper : pad_plus< sor< contains, begins, ends >, blank > {}; +struct symbolic_oper : pad< sor< eq, noteq, lteq, lt, gteq, gt >, blank > {}; // predicates -struct comparison_pred : seq< expr, pad< oper, blank >, expr > {}; +struct comparison_pred : seq< expr, sor< padded_oper, symbolic_oper >, expr > {}; struct pred; struct group_pred : if_must< one< '(' >, pad< pred, blank >, one< ')' > > {}; -struct true_pred : sor< istring<'t','r','u','e','p','r','e','d','i','c','a','t','e'>, istring<'t','r','u','e'> > {}; -struct false_pred : sor< istring<'f','a','l','s','e','p','r','e','d','i','c','a','t','e'>, istring<'f','a','l','s','e'> > {}; +struct true_pred : sor< pegtl_istring_t("truepredicate"), pegtl_istring_t("true") > {}; +struct false_pred : sor< pegtl_istring_t("falsepredicate"), pegtl_istring_t("false") > {}; -struct not_pre : sor< seq< one< '!' >, star< blank > >, seq< istring< 'N', 'O', 'T' >, plus< blank > > > {}; +struct not_pre : sor< seq< one< '!' >, star< blank > >, seq< pegtl_istring_t("not"), plus< blank > > > {}; struct atom_pred : seq< opt< not_pre >, pad< sor< group_pred, true_pred, false_pred, comparison_pred >, blank > > {}; -struct and_op : sor< two< '&' >, istring< 'A', 'N', 'D' > > {}; -struct or_op : sor< two< '|' >, istring< 'O', 'R' > > {}; +struct and_op : sor< pad< two< '&' >, blank >, pad_plus< pegtl_istring_t("and"), blank > > {}; +struct or_op : sor< pad< two< '|' >, blank> , pad_plus< pegtl_istring_t("or"), blank > > {}; -struct or_ext : seq< pad< or_op, blank >, pred > {}; -struct and_ext : seq< pad< and_op, blank >, pred > {}; +struct or_ext : if_must< or_op, pred > {}; +struct and_ext : if_must< and_op, pred > {}; struct and_pred : seq< atom_pred, star< and_ext > > {}; struct pred : seq< and_pred, star< or_ext > > {}; diff --git a/src/object-store/parser/query.abnf b/src/object-store/parser/query.abnf deleted file mode 100644 index d315fd35..00000000 --- a/src/object-store/parser/query.abnf +++ /dev/null @@ -1,23 +0,0 @@ - - -pred = expr 1*WSP oper 1*WSP expr -;pred =/ "(" *WSP pred *WSP ")" -;pred =/ ("NOT" / "!") 1*WSP pred -;pred =/ pred 1*WSP ("OR" / "||") !*WSP pred -;pred =/ pred 1*WSP ("AND" / "&&") 1*WSP pred - -oper = "=" / "==" / "!=" / "<" / "<=" / ">" / ">=" - -expr = string / num / key-path - -key-path = key *("." key) -key = 1*(ALPHA / "_") - -string = dq-string / sq-string -sq-string = "'" *(%x20-ffffffff) "'" -dq-string = DQUOTE *("\\" / %x20-21 / %x23-ffffffff) DQUOTE - -num = ["-"] (float-num / int-num / hex-num) -float-num = (*DIGIT "." 1*DIGIT / "." 1*DIGIT) -int-num = 1*DIGIT -hex-num = ("0x" / "0X") 1*HEXDIG