1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File containing the {@see Mailcode_Parser_Statement_Tokenizer_Token_Operand} class. |
4
|
|
|
* |
5
|
|
|
* @package Mailcode |
6
|
|
|
* @subpackage Parser |
7
|
|
|
* @see Mailcode_Parser_Statement_Tokenizer_Token_Operand |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Mailcode; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Token representing an operand sign. |
16
|
|
|
* |
17
|
|
|
* @package Mailcode |
18
|
|
|
* @subpackage Parser |
19
|
|
|
* @author Sebastian Mordziol <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Mailcode_Parser_Statement_Tokenizer_Token_Operand extends Mailcode_Parser_Statement_Tokenizer_Token |
22
|
|
|
{ |
23
|
|
|
public function getSign() : string |
24
|
|
|
{ |
25
|
|
|
return $this->matchedText; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getNormalized() : string |
29
|
|
|
{ |
30
|
|
|
return $this->getSign(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Retrieves all known comparison operator signs. |
35
|
|
|
* @return string[] |
36
|
|
|
*/ |
37
|
|
|
public static function getComparisonSigns() : array |
38
|
|
|
{ |
39
|
|
|
return array( |
40
|
|
|
'==', |
41
|
|
|
'>', |
42
|
|
|
'<', |
43
|
|
|
'>=', |
44
|
|
|
'<=', |
45
|
|
|
'!=' |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public static function getArithmeticSigns() : array |
50
|
|
|
{ |
51
|
|
|
return array( |
52
|
|
|
'+', |
53
|
|
|
'-', |
54
|
|
|
'/', |
55
|
|
|
'*' |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Whether the operator is comparison related (equals, not equals, smaller, greater...). |
61
|
|
|
* |
62
|
|
|
* @return bool |
63
|
|
|
*/ |
64
|
|
|
public function isComparator() : bool |
65
|
|
|
{ |
66
|
|
|
return |
67
|
|
|
$this->isEquals() || |
68
|
|
|
$this->isNotEquals() || |
69
|
|
|
$this->isGreaterThan() || |
70
|
|
|
$this->isGreaterOrEquals() || |
71
|
|
|
$this->isSmallerThan() || |
72
|
|
|
$this->isSmallerOrEquals(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Whether the operator is calculation related (minus, plus, divide, multiply). |
77
|
|
|
* |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
|
|
public function isCalculator() : bool |
81
|
|
|
{ |
82
|
|
|
return |
83
|
|
|
$this->isPlus() || |
84
|
|
|
$this->isDivide() || |
85
|
|
|
$this->isMinus() || |
86
|
|
|
$this->isMultiply(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function isAssignment() : bool |
90
|
|
|
{ |
91
|
|
|
return $this->getSign() === '='; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function isEquals() : bool |
95
|
|
|
{ |
96
|
|
|
return $this->getSign() === '=='; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function isGreaterThan() : bool |
100
|
|
|
{ |
101
|
|
|
return $this->getSign() === '>'; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function isSmallerThan() : bool |
105
|
|
|
{ |
106
|
|
|
return $this->getSign() === '<'; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function isGreaterOrEquals() : bool |
110
|
|
|
{ |
111
|
|
|
return $this->getSign() === '>='; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function isSmallerOrEquals() : bool |
115
|
|
|
{ |
116
|
|
|
return $this->getSign() === '<='; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function isNotEquals() : bool |
120
|
|
|
{ |
121
|
|
|
return $this->getSign() === '!='; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function isMinus() : bool |
125
|
|
|
{ |
126
|
|
|
return $this->getSign() === '-'; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function isMultiply() : bool |
130
|
|
|
{ |
131
|
|
|
return $this->getSign() === '*'; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function isDivide() : bool |
135
|
|
|
{ |
136
|
|
|
return $this->getSign() === '/'; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function isPlus() : bool |
140
|
|
|
{ |
141
|
|
|
return $this->getSign() === '+'; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|