realm-js/parser/parser.hpp

87 lines
1.8 KiB
C++
Raw Normal View History

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 {
2016-01-05 02:13:09 +00:00
class Schema;
2015-11-10 05:12:18 +00:00
2016-01-05 02:13:09 +00:00
namespace parser {
struct Expression
{
enum class Type { None, Number, String, KeyPath, Argument, True, False } type = Type::None;
std::string s;
};
2015-11-09 19:29:57 +00:00
2016-01-05 02:13:09 +00:00
struct Predicate
{
enum class Type
{
Comparison,
Or,
And,
True,
False
} type = Type::And;
2015-11-09 19:29:57 +00:00
2016-01-05 02:13:09 +00:00
enum class Operator
{
None,
Equal,
NotEqual,
LessThan,
LessThanOrEqual,
GreaterThan,
GreaterThanOrEqual,
BeginsWith,
EndsWith,
Contains
};
2015-11-10 17:09:20 +00:00
2016-01-05 02:13:09 +00:00
struct Comparison
{
Operator op = Operator::None;
Expression expr[2];
};
2015-11-10 17:09:20 +00:00
2016-01-05 02:13:09 +00:00
struct Compound
{
std::vector<Predicate> sub_predicates;
};
2015-11-09 19:29:57 +00:00
2016-01-05 02:13:09 +00:00
Comparison cmpr;
Compound cpnd;
2015-11-10 17:09:20 +00:00
2016-01-05 02:13:09 +00:00
bool negate = false;
2015-11-09 20:20:59 +00:00
2016-01-05 02:13:09 +00:00
Predicate(Type t, bool n = false) : type(t), negate(n) {}
};
2015-11-09 19:29:57 +00:00
2016-01-05 02:13:09 +00:00
Predicate parse(const std::string &query);
void analyzeGrammar();
bool testGrammar();
}
2015-11-09 19:29:57 +00:00
}
2015-11-10 20:51:21 +00:00
#endif // REALM_PARSER_HPP