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\Parser\Exception\ParserException; |
11
|
|
|
use nicoSWD\Rule\TokenStream\TokenStream; |
12
|
|
|
|
13
|
|
|
abstract class BaseToken |
14
|
|
|
{ |
15
|
|
|
abstract public function getType(): int; |
16
|
|
|
|
17
|
|
|
public function __construct( |
18
|
|
|
private mixed $value, |
|
|
|
|
19
|
|
|
private int $offset = 0 |
|
|
|
|
20
|
|
|
) { |
21
|
|
|
} |
22
|
336 |
|
|
23
|
|
|
public function getValue(): mixed |
24
|
336 |
|
{ |
25
|
336 |
|
return $this->value; |
|
|
|
|
26
|
336 |
|
} |
27
|
|
|
|
28
|
286 |
|
final public function getOriginalValue(): mixed |
29
|
|
|
{ |
30
|
286 |
|
return $this->value; |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
154 |
|
public function getOffset(): int |
34
|
|
|
{ |
35
|
154 |
|
return $this->offset; |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
90 |
|
/** @throws ParserException */ |
39
|
|
|
public function createNode(TokenStream $tokenStream): self |
|
|
|
|
40
|
90 |
|
{ |
41
|
|
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
238 |
|
public function isOfType(int $type): bool |
45
|
|
|
{ |
46
|
238 |
|
return ($this->getType() | $type) === $type; |
47
|
|
|
} |
48
|
|
|
|
49
|
270 |
|
public function isValue(): bool |
50
|
|
|
{ |
51
|
270 |
|
return $this->isOfType(TokenType::VALUE | TokenType::INT_VALUE); |
52
|
|
|
} |
53
|
|
|
|
54
|
174 |
|
public function isWhitespace(): bool |
55
|
|
|
{ |
56
|
174 |
|
return $this->isOfType(TokenType::SPACE | TokenType::COMMENT); |
57
|
|
|
} |
58
|
|
|
|
59
|
252 |
|
public function isMethod(): bool |
60
|
|
|
{ |
61
|
252 |
|
return $this->isOfType(TokenType::METHOD); |
62
|
|
|
} |
63
|
|
|
|
64
|
248 |
|
public function isComma(): bool |
65
|
|
|
{ |
66
|
248 |
|
return $this->isOfType(TokenType::COMMA); |
67
|
|
|
} |
68
|
|
|
|
69
|
174 |
|
public function isOperator(): bool |
70
|
|
|
{ |
71
|
174 |
|
return $this->isOfType(TokenType::OPERATOR); |
72
|
|
|
} |
73
|
|
|
|
74
|
2 |
|
public function isLogical(): bool |
75
|
|
|
{ |
76
|
2 |
|
return $this->isOfType(TokenType::LOGICAL); |
77
|
|
|
} |
78
|
|
|
|
79
|
2 |
|
public function isParenthesis(): bool |
80
|
|
|
{ |
81
|
2 |
|
return $this->isOfType(TokenType::PARENTHESIS); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.