1 ////////////////////////////////////////////////////////////////////////////
3 // Copyright 2015 Realm Inc.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 ////////////////////////////////////////////////////////////////////////////
19 #ifndef REALM_PARSER_HPP
20 #define REALM_PARSER_HPP
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;
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) {}
66 enum class OperatorOption
74 Operator op = Operator::None;
75 OperatorOption option = OperatorOption::None;
76 Expression expr[2] = {{Expression::Type::None, ""}, {Expression::Type::None, ""}};
81 std::vector<Predicate> sub_predicates;
89 Predicate(Type t, bool n = false) : type(t), negate(n) {}
92 Predicate parse(const std::string &query);
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();
100 #endif // REALM_PARSER_HPP