|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @license http://opensource.org/licenses/mit-license.php MIT |
|
7
|
|
|
* @link https://github.com/nicoSWD |
|
8
|
|
|
* @author Nicolas Oelgart <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace nicoSWD\Rule\TokenStream\Token; |
|
11
|
|
|
|
|
12
|
|
|
use nicoSWD\Rule\TokenStream\TokenStream; |
|
13
|
|
|
|
|
14
|
|
|
abstract class BaseToken |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var mixed */ |
|
17
|
|
|
private $value; |
|
18
|
|
|
/** @var int */ |
|
19
|
|
|
private $offset = 0; |
|
20
|
|
|
|
|
21
|
|
|
abstract public function getType(): int; |
|
22
|
|
|
|
|
23
|
228 |
|
public function __construct($value, int $offset = 0) |
|
24
|
|
|
{ |
|
25
|
228 |
|
$this->value = $value; |
|
26
|
228 |
|
$this->offset = $offset; |
|
27
|
228 |
|
} |
|
28
|
|
|
|
|
29
|
212 |
|
public function getValue() |
|
30
|
|
|
{ |
|
31
|
212 |
|
return $this->value; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
94 |
|
final public function getOriginalValue() |
|
35
|
|
|
{ |
|
36
|
94 |
|
return $this->value; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
144 |
|
public function getOffset(): int |
|
40
|
|
|
{ |
|
41
|
144 |
|
return $this->offset; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
208 |
|
public function createNode(TokenStream $tokenStream): self |
|
45
|
|
|
{ |
|
46
|
208 |
|
return $this; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
190 |
|
public function isOfType(int $type): bool |
|
50
|
|
|
{ |
|
51
|
190 |
|
return ($this->getType() | $type) === $type; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
144 |
|
public function isValue(): bool |
|
55
|
|
|
{ |
|
56
|
144 |
|
return $this->isOfType(TokenType::VALUE | TokenType::INT_VALUE); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
186 |
|
public function isWhitespace(): bool |
|
60
|
|
|
{ |
|
61
|
186 |
|
return $this->isOfType(TokenType::SPACE | TokenType::COMMENT); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
186 |
|
public function isMethod(): bool |
|
65
|
|
|
{ |
|
66
|
186 |
|
return $this->isOfType(TokenType::METHOD); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
144 |
|
public function isComma(): bool |
|
70
|
|
|
{ |
|
71
|
144 |
|
return $this->isOfType(TokenType::COMMA); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function isOperator(): bool |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->isOfType(TokenType::OPERATOR); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function isLogical(): bool |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->isOfType(TokenType::LOGICAL); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function isParenthesis(): bool |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->isOfType(TokenType::PARENTHESIS); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|