|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace POData\UriProcessor\QueryProcessor\ExpressionParser; |
|
4
|
|
|
|
|
5
|
|
|
use POData\Common\ODataConstants; |
|
6
|
|
|
use POData\Common\ODataException; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class ExpressionToken. |
|
10
|
|
|
*/ |
|
11
|
|
|
class ExpressionToken |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var ExpressionTokenId |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $Id; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
public $Text; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var int |
|
25
|
|
|
*/ |
|
26
|
|
|
public $Position; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Checks whether this token is a comparison operator. |
|
30
|
|
|
* |
|
31
|
|
|
* @return bool True if this token represent a comparison operator |
|
32
|
|
|
* False otherwise |
|
33
|
|
|
*/ |
|
34
|
|
|
public function isComparisonOperator() |
|
35
|
|
|
{ |
|
36
|
|
|
return |
|
37
|
|
|
$this->Id == ExpressionTokenId::IDENTIFIER() && |
|
38
|
|
|
is_string($this->Text) && |
|
39
|
|
|
(strcmp($this->Text, ODataConstants::KEYWORD_EQUAL) == 0 || |
|
40
|
|
|
strcmp($this->Text, ODataConstants::KEYWORD_NOT_EQUAL) == 0 || |
|
41
|
|
|
strcmp($this->Text, ODataConstants::KEYWORD_LESSTHAN) == 0 || |
|
42
|
|
|
strcmp($this->Text, ODataConstants::KEYWORD_GREATERTHAN) == 0 || |
|
43
|
|
|
strcmp($this->Text, ODataConstants::KEYWORD_LESSTHAN_OR_EQUAL) == 0 || |
|
44
|
|
|
strcmp($this->Text, ODataConstants::KEYWORD_GREATERTHAN_OR_EQUAL) == 0); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Checks whether this token is an equality operator. |
|
49
|
|
|
* |
|
50
|
|
|
* @return bool True if this token represent a equality operator |
|
51
|
|
|
* False otherwise |
|
52
|
|
|
*/ |
|
53
|
|
|
public function isEqualityOperator() |
|
54
|
|
|
{ |
|
55
|
|
|
return |
|
56
|
|
|
$this->Id == ExpressionTokenId::IDENTIFIER() && |
|
57
|
|
|
is_string($this->Text) && |
|
58
|
|
|
(strcmp($this->Text, ODataConstants::KEYWORD_EQUAL) === 0 || |
|
59
|
|
|
strcmp($this->Text, ODataConstants::KEYWORD_NOT_EQUAL) === 0); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Checks whether this token is a valid token for a key value. |
|
64
|
|
|
* |
|
65
|
|
|
* @return bool True if this token represent valid key value |
|
66
|
|
|
* False otherwise |
|
67
|
|
|
*/ |
|
68
|
|
|
public function isKeyValueToken() |
|
69
|
|
|
{ |
|
70
|
|
|
return |
|
71
|
|
|
$this->Id == ExpressionTokenId::BINARY_LITERAL() || |
|
72
|
|
|
$this->Id == ExpressionTokenId::BOOLEAN_LITERAL() || |
|
73
|
|
|
$this->Id == ExpressionTokenId::DATETIME_LITERAL() || |
|
74
|
|
|
$this->Id == ExpressionTokenId::GUID_LITERAL() || |
|
75
|
|
|
$this->Id == ExpressionTokenId::STRING_LITERAL() || |
|
76
|
|
|
ExpressionLexer::isNumeric($this->Id); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Gets the current identifier text. |
|
81
|
|
|
* |
|
82
|
|
|
* @throws ODataException |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getIdentifier() |
|
86
|
|
|
{ |
|
87
|
|
|
if ($this->Id != ExpressionTokenId::IDENTIFIER()) { |
|
88
|
|
|
throw ODataException::createSyntaxError( |
|
89
|
|
|
'Identifier expected at position ' . $this->Position |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return $this->Text; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Checks that this token has the specified identifier. |
|
98
|
|
|
* |
|
99
|
|
|
* @param ExpressionTokenId $id Identifier to check |
|
100
|
|
|
* |
|
101
|
|
|
* @return bool true if this is an identifier with the specified text |
|
102
|
|
|
*/ |
|
103
|
|
|
public function identifierIs($id) |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->Id == ExpressionTokenId::IDENTIFIER() |
|
106
|
|
|
&& strcmp($this->Text, $id) == 0; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return ExpressionTokenId |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getId() |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->Id; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param ExpressionTokenId $Id |
|
119
|
|
|
*/ |
|
120
|
|
|
public function setId(ExpressionTokenId $Id) |
|
121
|
|
|
{ |
|
122
|
|
|
$this->Id = $Id; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|