2015-11-09 19:29:57 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright 2015 Realm Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-11-10 20:51:21 +00:00
|
|
|
#ifndef REALM_PARSER_HPP
|
|
|
|
#define REALM_PARSER_HPP
|
2015-11-09 19:29:57 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace realm {
|
2015-11-10 05:12:18 +00:00
|
|
|
class Schema;
|
|
|
|
|
2015-11-09 19:29:57 +00:00
|
|
|
namespace parser {
|
|
|
|
struct Expression
|
|
|
|
{
|
2015-11-10 22:24:30 +00:00
|
|
|
enum class Type { Number, String, KeyPath, Argument, True, False } type;
|
2015-11-09 19:29:57 +00:00
|
|
|
std::string s;
|
2015-11-10 19:26:27 +00:00
|
|
|
Expression() {}
|
|
|
|
Expression(Type t, std::string s) : type(t), s(s) {}
|
2015-11-09 19:29:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Predicate
|
|
|
|
{
|
2015-11-10 17:09:20 +00:00
|
|
|
enum class Type {
|
2015-11-09 19:29:57 +00:00
|
|
|
Comparison,
|
|
|
|
Or,
|
|
|
|
And,
|
|
|
|
True,
|
2015-11-10 17:09:20 +00:00
|
|
|
False
|
|
|
|
} type = Type::And;
|
2015-11-09 19:29:57 +00:00
|
|
|
|
2015-11-10 17:09:20 +00:00
|
|
|
enum class Operator {
|
2015-11-09 19:29:57 +00:00
|
|
|
None,
|
|
|
|
Equal,
|
|
|
|
NotEqual,
|
|
|
|
LessThan,
|
|
|
|
LessThanOrEqual,
|
|
|
|
GreaterThan,
|
|
|
|
GreaterThanOrEqual,
|
|
|
|
BeginsWith,
|
|
|
|
EndsWith,
|
2015-11-10 17:09:20 +00:00
|
|
|
Contains
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Comparison {
|
|
|
|
Operator op = Operator::None;
|
|
|
|
Expression expr[2];
|
|
|
|
~Comparison() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Compound {
|
|
|
|
std::vector<Predicate> sub_predicates;
|
2015-11-09 19:29:57 +00:00
|
|
|
};
|
|
|
|
|
2015-11-10 17:09:20 +00:00
|
|
|
Comparison cmpr;
|
|
|
|
Compound cpnd;
|
|
|
|
|
|
|
|
bool negate = false;
|
2015-11-09 20:20:59 +00:00
|
|
|
|
2015-11-10 17:09:20 +00:00
|
|
|
Predicate(Type t) : type(t) {}
|
2015-11-09 19:29:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Predicate parse(const std::string &query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-10 20:51:21 +00:00
|
|
|
#endif // REALM_PARSER_HPP
|