FilterExpressionGrammar.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #ifndef OPENDDS_DCPS_FILTER_EXPRESSION_GRAMMAR_H
00009 #define OPENDDS_DCPS_FILTER_EXPRESSION_GRAMMAR_H
00010 
00011 #include "dds/DCPS/Definitions.h"
00012 
00013 #ifndef OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE
00014 
00015 #include <cassert>
00016 #include <typeinfo>
00017 
00018 #include "yard/yard_base_grammar.hpp"
00019 #include "yard/yard_char_set.hpp"
00020 #include "yard/yard_tree.hpp"
00021 #include "yard/yard_text_grammar.hpp"
00022 
00023 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00024 
00025 namespace OpenDDS {
00026 namespace DCPS {
00027 
00028 namespace GrammarUtils {
00029   using namespace yard;
00030   using namespace text_grammar;
00031 
00032   struct WS : CharSetParser<WhiteSpaceCharSet> {};
00033   template<typename T> struct Tok : Seq<T, Star<WS> > {};
00034   template<typename T> struct Keyword : Tok<Seq<T, NotAlphaNum> > {};
00035   template<typename T> struct ST : Tok<Store<T> > {}; // "Store-Tokenize"
00036 
00037   struct LPAREN : Tok<Char<'('> > {};
00038   struct RPAREN : Tok<Char<')'> > {};
00039 
00040   template<typename R, typename D>
00041   struct DelimitedList : Seq<R, Star<Seq<D, R> > > {};
00042 }
00043 
00044 namespace FilterExpressionGrammar {
00045   using namespace yard;
00046   using namespace text_grammar;
00047   using namespace GrammarUtils;
00048 
00049   struct OptPlusMinus : Opt<Or<Char<'+'>, Char<'-'> > > {};
00050   struct IntValDec : Seq<OptPlusMinus, Plus<Digit>, NotAt<Digit>, NotAt<Or<Char<'x'>, Char<'X'>, Char<'.'> > > > {};
00051   struct IntValHex : Seq<CharSeqIgnoreCase<'0', 'x'>, Plus<HexDigit>, NotAlphaNum> {};
00052   struct IntVal : Or<
00053     IntValDec,
00054     IntValHex
00055     > {};
00056 
00057   struct Quote : CharSetParser<CharSet<'\'', '`'> > {};
00058   struct CharVal : Seq<Quote, AnyChar, Char<'\''> > {};
00059 
00060   struct OptExp : Opt<Seq<Char<'e'>, OptPlusMinus, Plus<Digit> > > {};
00061   struct FloatStartWithDigit : Seq<Plus<Digit>, Opt<Char<'.'> >, Star<Digit> > {};
00062   struct FloatStartWithDot : Seq<Char<'.'>, Plus<Digit> > {};
00063   struct FloatVal : Seq<OptPlusMinus, Or<FloatStartWithDigit, FloatStartWithDot>, OptExp, NotAlphaNum> {};
00064 
00065   struct StrVal : Seq<Quote, Star<AnyCharExcept<CharSet<'\n', '\''> > >, Char<'\''> > {};
00066 
00067   struct ParamVal : Seq<Char<'%'>, Digit, Opt<Digit> > {};
00068 
00069   struct Param : Tok<Or<Store<IntVal>, Store<CharVal>, Store<FloatVal>, Store<StrVal>, Store<ParamVal> > > {}; // EnumVal is parsed as StrVal
00070 
00071   struct AND : Keyword<CharSeqIgnoreCase<'a', 'n', 'd'> > {};
00072   struct OR : Keyword<CharSeqIgnoreCase<'o', 'r'> > {};
00073   struct NOT : Keyword<CharSeqIgnoreCase<'n', 'o', 't'> > {};
00074   struct BETWEEN : Keyword<CharSeqIgnoreCase<'b', 'e', 't', 'w', 'e', 'e', 'n'> > {};
00075   struct NOT_BETWEEN : Seq <NOT, BETWEEN> { };
00076 
00077   struct OP_EQ : Tok<Char<'='> > {};
00078   struct OP_LT : Tok<Seq<Char<'<'>, NotAt<Or<Char<'='>, Char<'>'> > > > > {};
00079   struct OP_GT : Tok<Seq<Char<'>'>, NotAt<Char<'='> > > > {};
00080   struct OP_LTEQ : Tok<Seq<Char<'<'>, Char<'='> > > {};
00081   struct OP_GTEQ : Tok<Seq<Char<'>'>, Char<'='> > > {};
00082   struct OP_NEQ : Tok<Seq<Char<'<'>, Char<'>'> > > {};
00083   struct OP_LIKE : Keyword<CharSeqIgnoreCase<'l', 'i', 'k', 'e'> > {};
00084   struct RelOp : Or<
00085     Store<OP_EQ>,
00086     Store<OP_LT>,
00087     Store<OP_GT>,
00088     Store<OP_LTEQ>,
00089     Store<OP_GTEQ>,
00090     Store<OP_NEQ>,
00091     Store<OP_LIKE>
00092     > {};
00093 
00094   struct FieldName : DelimitedList<Seq<Letter, Star<IdentNextChar> >, Char<'.'> > {};
00095 
00096   struct Primary;
00097   struct CallDef : Seq< ST<FieldName>, Opt<Seq<Tok<Char<'('> >, DelimitedList<Primary, Tok<Char<','> > >,  Tok<Char<')'> > > > > { };
00098   struct Call : Store<CallDef> { };
00099   struct Primary : Or<
00100     Call,
00101     Param
00102     > { };
00103 
00104   struct BetweenPredDef : Seq<ST<FieldName>, Or<Store<BETWEEN>, Store<NOT_BETWEEN> >, Param, AND, Param> {};
00105   struct BetweenPred : Store<BetweenPredDef> { };
00106   struct CompPredDef : Seq<Primary, RelOp, Primary> { };
00107   struct CompPred : Store<CompPredDef> { };
00108   struct Pred : Or<
00109     BetweenPred,
00110     CompPred
00111     > {};
00112 
00113   struct Cond;
00114   struct CondTail : Opt<Seq<Or<Store<AND>, Store<OR> >, Cond, CondTail> > {};
00115   struct CondDef : Or<
00116     Seq<Pred, CondTail>,
00117     Seq<Store<NOT>, Cond, CondTail>,
00118     Seq<LPAREN, Cond, RPAREN, CondTail>
00119     > {};
00120   struct Cond : Store<CondDef> { };
00121   struct FilterCompleteInput : Seq<Cond, EndOfInput> {};
00122 
00123   struct ORDERBY : Keyword<CharSeqIgnoreCase<'o', 'r', 'd', 'e', 'r', ' ', 'b', 'y'> > {};
00124   struct Query : Seq<Opt<Cond>, Opt<Seq<Store<ORDERBY>, DelimitedList<ST<FieldName>, Tok<Char<','> > > > > > {};
00125   struct QueryCompleteInput : Seq<Query, EndOfInput> {};
00126 }
00127 }
00128 }
00129 
00130 OPENDDS_END_VERSIONED_NAMESPACE_DECL
00131 
00132 #endif
00133 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1