10 #ifndef smtk_model_FilterGrammar_h
11 #define smtk_model_FilterGrammar_h
14 #include "smtk/model/LimitingClause.h"
16 #include "tao/pegtl.hpp"
23 using namespace tao::pegtl;
33 namespace floating_point
35 struct plus_minus : opt< one< '+', '-' > > {};
36 struct dot : one< '.' > {};
37 struct inf : seq< TAO_PEGTL_ISTRING("inf"),
38 opt< TAO_PEGTL_ISTRING("inity") > > {};
39 struct nan : seq< TAO_PEGTL_ISTRING("nan"),
43 template<
typename D >
47 seq< plus< D >, opt< dot, star< D > > >
49 struct e : one< 'e', 'E' > {};
50 struct p : one< 'p', 'P' > {};
51 struct exponent : seq< plus_minus, plus< digit > > {};
52 struct decimal : seq< number< digit >, opt< e, exponent > > {};
53 struct hexadecimal : seq< one< '0' >, one< 'x', 'X' >, number< xdigit >, opt< p, exponent > > {};
54 struct value : seq< plus_minus, sor< hexadecimal, decimal, inf, nan > > {};
60 template <
char left,
char right,
typename... arguments>
61 struct enclosed : if_must<one<left>, until<one<right>, arguments...> > {};
63 template <
typename... arguments>
64 struct bracketed : enclosed<'[', ']', arguments...> {};
66 template <
typename... arguments>
67 struct braced : enclosed<'{', '}', arguments...> {};
69 template <
typename... arguments>
70 struct parenthesized : enclosed<'(', ')', arguments...> {};
72 template <
typename... arguments>
73 struct quoted : enclosed<'\'', '\'', arguments...> {};
75 template <
typename... arguments>
76 struct slashed : enclosed<'/', '/', arguments...> {};
79 struct int_property_name : pad<TAO_PEGTL_ISTRING("integer"), space> {};
80 struct float_property_name : pad<TAO_PEGTL_ISTRING("floating-point"), space> {};
81 struct string_property_name : pad<TAO_PEGTL_ISTRING("string"), space> {};
92 struct name_property_value : plus<not_one<'\''> > {};
93 struct name_property : pad<quoted<name_property_value>, space> {};
95 struct name_property_regex_value : plus<not_one<'/'> > {};
96 struct name_property_regex : pad<slashed<name_property_regex_value>, space> {};
98 struct int_property_value : plus<digit> {};
99 struct int_property : pad<int_property_value, space> {};
101 struct float_property_value : floating_point::value {};
102 struct float_property : pad<float_property_value, space>{};
104 struct string_property_value : plus<not_one<'\''> > {};
105 struct string_property : pad<quoted<string_property_value>, space> {};
107 struct string_property_regex_value : plus<not_one<'/'> > {};
108 struct string_property_regex : pad<slashed<string_property_regex_value>, space> {};
112 template <
typename property>
113 struct property_sequence
114 : pad<sor<property, parenthesized<list<property, one<','>, space> > >, space> {};
121 template<
typename property>
127 typedef int_property_name name;
128 typedef property_sequence<int_property> sequence;
134 typedef float_property_name name;
135 typedef property_sequence<float_property> sequence;
141 typedef string_property_name name;
142 typedef property_sequence<sor<string_property, string_property_regex>> sequence;
148 template<
typename property>
152 typename property_traits<property>::name,
154 sor<name_property, name_property_regex>,
155 opt<pad<TAO_PEGTL_ISTRING("="), space>, typename property_traits<property>::sequence>>>>,
163 sor<grammar_for<int_property>, grammar_for<float_property>, grammar_for<string_property>>>
168 template<
typename Rule>
176 template<
typename Input>
186 template<
typename Input>
196 template<
typename Input>
206 template<
typename Input>
209 clause.m_propName = in.string();
216 template<
typename Input>
219 clause.m_propName = in.string();
220 clause.m_propNameIsRegex =
true;
227 template<
typename Input>
230 clause.m_propIntValues.push_back(std::stoi(in.string()));
237 template<
typename Input>
240 clause.m_propFloatValues.push_back(std::stod(in.string()));
247 template<
typename Input>
250 clause.m_propStringValues.push_back(in.string());
251 clause.m_propStringIsRegex.push_back(
false);
258 template<
typename Input>
261 clause.m_propStringValues.push_back(in.string());
262 clause.m_propStringIsRegex.push_back(
true);
268 #endif // smtk_model_FilterGrammar_h