1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// expression_parser.h
/**
* Copyright (C) 2013 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "mongo/base/status.h"
#include "mongo/base/status_with.h"
#include "mongo/db/matcher/expression.h"
#include "mongo/db/matcher/expression_leaf.h"
#include "mongo/db/matcher/expression_tree.h"
namespace mongo {
typedef StatusWith<Expression*> StatusWithExpression;
class ExpressionParser {
public:
static StatusWithExpression parse( const BSONObj& obj );
private:
/**
* parses a field in a sub expression
* if the query is { x : { $gt : 5, $lt : 8 } }
* e is { $gt : 5, $lt : 8 }
*/
static Status _parseSub( const char* name,
const BSONObj& obj,
AndExpression* root );
/**
* parses a single field in a sub expression
* if the query is { x : { $gt : 5, $lt : 8 } }
* e is $gt : 5
*/
static StatusWithExpression _parseSubField( const char* name,
const BSONElement& e );
static StatusWithExpression _parseComparison( const char* name,
ComparisonExpression::Type cmp,
const BSONElement& e );
static StatusWithExpression _parseMOD( const char* name,
const BSONElement& e );
static StatusWithExpression _parseRegexElement( const char* name,
const BSONElement& e );
static StatusWithExpression _parseRegexDocument( const char* name,
const BSONObj& doc );
static Status _parseArrayFilterEntries( ArrayFilterEntries* entries,
const BSONObj& theArray );
// arrays
static StatusWithExpression _parseElemMatch( const char* name,
const BSONElement& e );
static StatusWithExpression _parseAll( const char* name,
const BSONElement& e );
// tree
static Status _parseTreeList( const BSONObj& arr, ListOfExpression* out );
static StatusWithExpression _parseNot( const char* name, const BSONElement& e );
};
}
|