realm-js/parser/parser.hpp

87 lines
2.2 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 {
2015-11-10 05:12:18 +00:00
class Schema;
2015-11-09 19:29:57 +00:00
namespace parser {
struct Expression
{
2015-11-26 03:10:59 +00:00
enum class Type { None, Number, String, KeyPath, Argument, True, False } type = Type::None;
2015-11-09 19:29:57 +00:00
std::string s;
};
struct Predicate
{
2015-11-23 16:47:09 +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-23 16:47:09 +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
};
2015-11-23 16:47:09 +00:00
struct Comparison
{
2015-11-10 17:09:20 +00:00
Operator op = Operator::None;
Expression expr[2];
};
2015-11-23 16:47:09 +00:00
struct Compound
{
2015-11-10 17:09:20 +00:00
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
Predicate(Type t, bool n = false) : type(t), negate(n) {}
2015-11-09 19:29:57 +00:00
};
Predicate parse(const std::string &query);
2015-11-20 23:16:35 +00:00
2015-11-23 16:47:09 +00:00
void analyzeGrammar();
2015-11-23 16:56:36 +00:00
bool testGrammar();
2015-11-09 19:29:57 +00:00
}
}
2015-11-10 20:51:21 +00:00
#endif // REALM_PARSER_HPP