added iOS source code
[wl-app.git] / iOS / Pods / Realm / include / core / realm / parser / parser.hpp
1 ////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright 2015 Realm Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 ////////////////////////////////////////////////////////////////////////////
18
19 #ifndef REALM_PARSER_HPP
20 #define REALM_PARSER_HPP
21
22 #include <vector>
23 #include <string>
24
25 namespace realm {
26
27 namespace parser {
28 struct Expression
29 {
30     enum class Type { None, Number, String, KeyPath, Argument, True, False, Null, Timestamp, Base64 } type;
31     enum class KeyPathOp { None, Min, Max, Avg, Sum, Count, Size } collection_op;
32     std::string s;
33     std::vector<std::string> time_inputs;
34     std::string op_suffix;
35     Expression(Type t = Type::None, std::string input = "") : type(t), collection_op(KeyPathOp::None), s(input) {}
36     Expression(std::vector<std::string>&& timestamp) : type(Type::Timestamp), collection_op(KeyPathOp::None), time_inputs(timestamp) {}
37     Expression(std::string prefix, KeyPathOp op, std::string suffix) : type(Type::KeyPath), collection_op(op), s(prefix), op_suffix(suffix) {}
38 };
39
40 struct Predicate
41 {
42     enum class Type
43     {
44         Comparison,
45         Or,
46         And,
47         True,
48         False
49     } type = Type::And;
50
51     enum class Operator
52     {
53         None,
54         Equal,
55         NotEqual,
56         LessThan,
57         LessThanOrEqual,
58         GreaterThan,
59         GreaterThanOrEqual,
60         BeginsWith,
61         EndsWith,
62         Contains,
63         Like
64     };
65
66     enum class OperatorOption
67     {
68         None,
69         CaseInsensitive,
70     };
71
72     struct Comparison
73     {
74         Operator op = Operator::None;
75         OperatorOption option = OperatorOption::None;
76         Expression expr[2] = {{Expression::Type::None, ""}, {Expression::Type::None, ""}};
77     };
78
79     struct Compound
80     {
81         std::vector<Predicate> sub_predicates;
82     };
83
84     Comparison cmpr;
85     Compound   cpnd;
86
87     bool negate = false;
88
89     Predicate(Type t, bool n = false) : type(t), negate(n) {}
90 };
91
92 Predicate parse(const std::string &query);
93
94 // run the analysis tool to check for cycles in the grammar
95 // returns the number of problems found and prints some info to std::cout
96 size_t analyze_grammar();
97 }
98 }
99
100 #endif // REALM_PARSER_HPP