OpenDDS  Snapshot(2023/04/28-20:55)
FilterExpressionGrammar.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #ifndef OPENDDS_DCPS_FILTER_EXPRESSION_GRAMMAR_H
9 #define OPENDDS_DCPS_FILTER_EXPRESSION_GRAMMAR_H
10 
11 #include "Definitions.h"
12 
13 #ifndef OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE
14 
15 #include <typeinfo>
16 
17 #include "yard/yard_base_grammar.hpp"
18 #include "yard/yard_char_set.hpp"
19 #include "yard/yard_tree.hpp"
20 #include "yard/yard_text_grammar.hpp"
21 
23 
24 namespace OpenDDS {
25 namespace DCPS {
26 
27 namespace GrammarUtils {
28  using namespace yard;
29  using namespace text_grammar;
30 
31  struct WS : CharSetParser<WhiteSpaceCharSet> {};
32  template<typename T> struct Tok : Seq<T, Star<WS> > {};
33  template<typename T> struct Keyword : Tok<Seq<T, NotAlphaNum> > {};
34  template<typename T> struct ST : Tok<Store<T> > {}; // "Store-Tokenize"
35 
36  struct LPAREN : Tok<Char<'('> > {};
37  struct RPAREN : Tok<Char<')'> > {};
38 
39  template<typename R, typename D>
40  struct DelimitedList : Seq<R, Star<Seq<D, R> > > {};
41 }
42 
43 namespace FilterExpressionGrammar {
44  using namespace yard;
45  using namespace text_grammar;
46  using namespace GrammarUtils;
47 
48  struct OptPlusMinus : Opt<Or<Char<'+'>, Char<'-'> > > {};
49  struct IntValDec : Seq<OptPlusMinus, Plus<Digit>, NotAt<Digit>, NotAt<Or<Char<'x'>, Char<'X'>, Char<'.'> > > > {};
50  struct IntValHex : Seq<CharSeqIgnoreCase<'0', 'x'>, Plus<HexDigit>, NotAlphaNum> {};
51  struct IntVal : Or<
52  IntValDec,
53  IntValHex
54  > {};
55 
56  struct Quote : CharSetParser<CharSet<'\'', '`'> > {};
57  struct CharVal : Seq<Quote, AnyChar, Char<'\''> > {};
58 
59  struct OptExp : Opt<Seq<Char<'e'>, OptPlusMinus, Plus<Digit> > > {};
60  struct FloatStartWithDigit : Seq<Plus<Digit>, Opt<Char<'.'> >, Star<Digit> > {};
61  struct FloatStartWithDot : Seq<Char<'.'>, Plus<Digit> > {};
62  struct FloatVal : Seq<OptPlusMinus, Or<FloatStartWithDigit, FloatStartWithDot>, OptExp, NotAlphaNum> {};
63 
64  struct StrVal : Seq<Quote, Star<AnyCharExcept<CharSet<'\n', '\''> > >, Char<'\''> > {};
65 
66  struct ParamVal : Seq<Char<'%'>, Digit, Opt<Digit> > {};
67 
68  struct Param : Tok<Or<Store<IntVal>, Store<CharVal>, Store<FloatVal>, Store<StrVal>, Store<ParamVal> > > {}; // EnumVal is parsed as StrVal
69 
70  struct AND : Keyword<CharSeqIgnoreCase<'a', 'n', 'd'> > {};
71  struct OR : Keyword<CharSeqIgnoreCase<'o', 'r'> > {};
72  struct NOT : Keyword<CharSeqIgnoreCase<'n', 'o', 't'> > {};
73  struct BETWEEN : Keyword<CharSeqIgnoreCase<'b', 'e', 't', 'w', 'e', 'e', 'n'> > {};
74  struct NOT_BETWEEN : Seq <NOT, BETWEEN> { };
75 
76  struct OP_EQ : Tok<Char<'='> > {};
77  struct OP_LT : Tok<Seq<Char<'<'>, NotAt<Or<Char<'='>, Char<'>'> > > > > {};
78  struct OP_GT : Tok<Seq<Char<'>'>, NotAt<Char<'='> > > > {};
79  struct OP_LTEQ : Tok<Seq<Char<'<'>, Char<'='> > > {};
80  struct OP_GTEQ : Tok<Seq<Char<'>'>, Char<'='> > > {};
81  struct OP_NEQ : Tok<Seq<Char<'<'>, Char<'>'> > > {};
82  struct OP_LIKE : Keyword<CharSeqIgnoreCase<'l', 'i', 'k', 'e'> > {};
83  struct RelOp : Or<
84  Store<OP_EQ>,
85  Store<OP_LT>,
86  Store<OP_GT>,
87  Store<OP_LTEQ>,
88  Store<OP_GTEQ>,
89  Store<OP_NEQ>,
90  Store<OP_LIKE>
91  > {};
92 
93  struct FieldName : DelimitedList<Seq<Letter, Star<IdentNextChar> >, Char<'.'> > {};
94 
95  struct Primary;
96  struct CallDef : Seq< ST<FieldName>, Opt<Seq<Tok<Char<'('> >, DelimitedList<Primary, Tok<Char<','> > >, Tok<Char<')'> > > > > { };
97  struct Call : Store<CallDef> { };
98  struct Primary : Or<
99  Call,
100  Param
101  > { };
102 
103  struct BetweenPredDef : Seq<ST<FieldName>, Or<Store<BETWEEN>, Store<NOT_BETWEEN> >, Param, AND, Param> {};
104  struct BetweenPred : Store<BetweenPredDef> { };
105  struct CompPredDef : Seq<Primary, RelOp, Primary> { };
106  struct CompPred : Store<CompPredDef> { };
107  struct Pred : Or<
108  BetweenPred,
109  CompPred
110  > {};
111 
112  struct Cond;
113  struct CondTail : Opt<Seq<Or<Store<AND>, Store<OR> >, Cond, CondTail> > {};
114  struct CondDef : Or<
115  Seq<Pred, CondTail>,
116  Seq<Store<NOT>, Cond, CondTail>,
117  Seq<LPAREN, Cond, RPAREN, CondTail>
118  > {};
119  struct Cond : Store<CondDef> { };
120  struct FilterCompleteInput : Seq<Cond, EndOfInput> {};
121 
122  struct ORDERBY : Keyword<CharSeqIgnoreCase<'o', 'r', 'd', 'e', 'r', ' ', 'b', 'y'> > {};
123  struct Query : Seq<Opt<Cond>, Opt<Seq<Store<ORDERBY>, DelimitedList<ST<FieldName>, Tok<Char<','> > > > > > {};
124  struct QueryCompleteInput : Seq<Query, EndOfInput> {};
125 }
126 }
127 }
128 
130 
131 #endif
132 #endif
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28