add required padding around string operators, use pegtl_istring_t
This commit is contained in:
parent
e7e4b6715e
commit
bb16ffa7fe
|
@ -23,6 +23,7 @@
|
||||||
#include <pegtl.hh>
|
#include <pegtl.hh>
|
||||||
#include <pegtl/analyze.hh>
|
#include <pegtl/analyze.hh>
|
||||||
#include <pegtl/trace.hh>
|
#include <pegtl/trace.hh>
|
||||||
|
#include <pegtl/internal/pegtl_string.hh>
|
||||||
|
|
||||||
using namespace pegtl;
|
using namespace pegtl;
|
||||||
|
|
||||||
|
@ -71,27 +72,32 @@ struct lteq : pegtl::string< '<', '=' > {};
|
||||||
struct lt : one< '<' > {};
|
struct lt : one< '<' > {};
|
||||||
struct gteq : pegtl::string< '>', '=' > {};
|
struct gteq : pegtl::string< '>', '=' > {};
|
||||||
struct gt : one< '>' > {};
|
struct gt : one< '>' > {};
|
||||||
struct begins : istring< 'b','e','g','i','n','s','w','i','t','h' > {};
|
struct contains : pegtl_istring_t("contains") {};
|
||||||
struct ends : istring< 'e','n','d','s','w','i','t','h' > {};
|
struct begins : pegtl_istring_t("beginswith") {};
|
||||||
struct contains : istring< 'c','o','n','t','a','i','n','s' > {};
|
struct ends : pegtl_istring_t("endswith") {};
|
||||||
struct oper : sor< eq, noteq, lteq, lt, gteq, gt, begins, ends, contains > {};
|
|
||||||
|
template<typename A, typename B>
|
||||||
|
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
|
// predicates
|
||||||
struct comparison_pred : seq< expr, pad< oper, blank >, expr > {};
|
struct comparison_pred : seq< expr, sor< padded_oper, symbolic_oper >, expr > {};
|
||||||
|
|
||||||
struct pred;
|
struct pred;
|
||||||
struct group_pred : if_must< one< '(' >, pad< pred, blank >, one< ')' > > {};
|
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 true_pred : sor< pegtl_istring_t("truepredicate"), pegtl_istring_t("true") > {};
|
||||||
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 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 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 and_op : sor< pad< two< '&' >, blank >, pad_plus< pegtl_istring_t("and"), blank > > {};
|
||||||
struct or_op : sor< two< '|' >, istring< 'O', 'R' > > {};
|
struct or_op : sor< pad< two< '|' >, blank> , pad_plus< pegtl_istring_t("or"), blank > > {};
|
||||||
|
|
||||||
struct or_ext : seq< pad< or_op, blank >, pred > {};
|
struct or_ext : if_must< or_op, pred > {};
|
||||||
struct and_ext : seq< pad< and_op, blank >, pred > {};
|
struct and_ext : if_must< and_op, pred > {};
|
||||||
struct and_pred : seq< atom_pred, star< and_ext > > {};
|
struct and_pred : seq< atom_pred, star< and_ext > > {};
|
||||||
|
|
||||||
struct pred : seq< and_pred, star< or_ext > > {};
|
struct pred : seq< and_pred, star< or_ext > > {};
|
||||||
|
|
|
@ -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
|
|
Loading…
Reference in New Issue