00001
00002
00003
00004
00005
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 namespace OpenDDS {
00024 namespace DCPS {
00025
00026 namespace GrammarUtils {
00027 using namespace yard;
00028 using namespace text_grammar;
00029
00030 struct WS : CharSetParser<WhiteSpaceCharSet> {};
00031 template<typename T> struct Tok : Seq<T, Star<WS> > {};
00032 template<typename T> struct Keyword : Tok<Seq<T, NotAlphaNum> > {};
00033 template<typename T> struct ST : Tok<Store<T> > {};
00034
00035 struct LPAREN : Tok<Char<'('> > {};
00036 struct RPAREN : Tok<Char<')'> > {};
00037
00038 template<typename R, typename D>
00039 struct DelimitedList : Seq<R, Star<Seq<D, R> > > {};
00040 }
00041
00042 namespace FilterExpressionGrammar {
00043 using namespace yard;
00044 using namespace text_grammar;
00045 using namespace GrammarUtils;
00046
00047 struct OptPlusMinus : Opt<Or<Char<'+'>, Char<'-'> > > {};
00048 struct IntValDec : Seq<OptPlusMinus, Plus<Digit>, NotAt<Digit>, NotAt<Or<Char<'x'>, Char<'X'>, Char<'.'> > > > {};
00049 struct IntValHex : Seq<CharSeqIgnoreCase<'0', 'x'>, Plus<HexDigit>, NotAlphaNum> {};
00050 struct IntVal : Or<
00051 IntValDec,
00052 IntValHex
00053 > {};
00054
00055 struct Quote : CharSetParser<CharSet<'\'', '`'> > {};
00056 struct CharVal : Seq<Quote, AnyChar, Char<'\''> > {};
00057
00058 struct OptExp : Opt<Seq<Char<'e'>, OptPlusMinus, Plus<Digit> > > {};
00059 struct FloatStartWithDigit : Seq<Plus<Digit>, Opt<Char<'.'> >, Star<Digit> > {};
00060 struct FloatStartWithDot : Seq<Char<'.'>, Plus<Digit> > {};
00061 struct FloatVal : Seq<OptPlusMinus, Or<FloatStartWithDigit, FloatStartWithDot>, OptExp, NotAlphaNum> {};
00062
00063 struct StrVal : Seq<Quote, Star<AnyCharExcept<CharSet<'\n', '\''> > >, Char<'\''> > {};
00064
00065 struct ParamVal : Seq<Char<'%'>, Digit, Opt<Digit> > {};
00066
00067 struct Param : Tok<Or<Store<IntVal>, Store<CharVal>, Store<FloatVal>, Store<StrVal>, Store<ParamVal> > > {};
00068
00069 struct AND : Keyword<CharSeqIgnoreCase<'a', 'n', 'd'> > {};
00070 struct OR : Keyword<CharSeqIgnoreCase<'o', 'r'> > {};
00071 struct NOT : Keyword<CharSeqIgnoreCase<'n', 'o', 't'> > {};
00072 struct BETWEEN : Keyword<CharSeqIgnoreCase<'b', 'e', 't', 'w', 'e', 'e', 'n'> > {};
00073 struct NOT_BETWEEN : Seq <NOT, BETWEEN> { };
00074
00075 struct OP_EQ : Tok<Char<'='> > {};
00076 struct OP_LT : Tok<Seq<Char<'<'>, NotAt<Or<Char<'='>, Char<'>'> > > > > {};
00077 struct OP_GT : Tok<Seq<Char<'>'>, NotAt<Char<'='> > > > {};
00078 struct OP_LTEQ : Tok<Seq<Char<'<'>, Char<'='> > > {};
00079 struct OP_GTEQ : Tok<Seq<Char<'>'>, Char<'='> > > {};
00080 struct OP_NEQ : Tok<Seq<Char<'<'>, Char<'>'> > > {};
00081 struct OP_LIKE : Keyword<CharSeqIgnoreCase<'l', 'i', 'k', 'e'> > {};
00082 struct RelOp : Or<
00083 Store<OP_EQ>,
00084 Store<OP_LT>,
00085 Store<OP_GT>,
00086 Store<OP_LTEQ>,
00087 Store<OP_GTEQ>,
00088 Store<OP_NEQ>,
00089 Store<OP_LIKE>
00090 > {};
00091
00092 struct FieldName : DelimitedList<Seq<Letter, Star<IdentNextChar> >, Char<'.'> > {};
00093
00094 struct Primary;
00095 struct CallDef : Seq< ST<FieldName>, Opt<Seq<Tok<Char<'('> >, DelimitedList<Primary, Tok<Char<','> > >, Tok<Char<')'> > > > > { };
00096 struct Call : Store<CallDef> { };
00097 struct Primary : Or<
00098 Call,
00099 Param
00100 > { };
00101
00102 struct BetweenPredDef : Seq<ST<FieldName>, Or<Store<BETWEEN>, Store<NOT_BETWEEN> >, Param, AND, Param> {};
00103 struct BetweenPred : Store<BetweenPredDef> { };
00104 struct CompPredDef : Seq<Primary, RelOp, Primary> { };
00105 struct CompPred : Store<CompPredDef> { };
00106 struct Pred : Or<
00107 BetweenPred,
00108 CompPred
00109 > {};
00110
00111 struct Cond;
00112 struct CondTail : Opt<Seq<Or<Store<AND>, Store<OR> >, Cond, CondTail> > {};
00113 struct CondDef : Or<
00114 Seq<Pred, CondTail>,
00115 Seq<Store<NOT>, Cond, CondTail>,
00116 Seq<LPAREN, Cond, RPAREN, CondTail>
00117 > {};
00118 struct Cond : Store<CondDef> { };
00119 struct FilterCompleteInput : Seq<Cond, EndOfInput> {};
00120
00121 struct ORDERBY : Keyword<CharSeqIgnoreCase<'o', 'r', 'd', 'e', 'r', ' ', 'b', 'y'> > {};
00122 struct Query : Seq<Opt<Cond>, Opt<Seq<Store<ORDERBY>, DelimitedList<ST<FieldName>, Tok<Char<','> > > > > > {};
00123 struct QueryCompleteInput : Seq<Query, EndOfInput> {};
00124 }
00125 }
00126 }
00127 #endif
00128 #endif