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