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\Parser\Exception; |
9
|
|
|
|
10
|
|
|
use nicoSWD\Rule\TokenStream\Token\BaseToken; |
11
|
|
|
use nicoSWD\Rule\TokenStream\Token\Type\Operator; |
12
|
|
|
|
13
|
|
|
final class ParserException extends \Exception |
14
|
16 |
|
{ |
15
|
|
|
public static function unexpectedToken(BaseToken $token): self |
16
|
16 |
|
{ |
17
|
|
|
return new self(sprintf('Unexpected "%s" at position %d', $token->getValue(), $token->getOffset())); |
18
|
|
|
} |
19
|
6 |
|
|
20
|
|
|
public static function unknownToken(BaseToken $token): self |
21
|
6 |
|
{ |
22
|
|
|
return new self(sprintf('Unknown token "%s" at position %d', $token->getValue(), $token->getOffset())); |
23
|
|
|
} |
24
|
2 |
|
|
25
|
|
|
public static function incompleteExpression(BaseToken $token): self |
26
|
2 |
|
{ |
27
|
|
|
return new self(sprintf('Incomplete expression for token "%s"', $token->getValue())); |
28
|
|
|
} |
29
|
6 |
|
|
30
|
|
|
public static function undefinedVariable(string $name, BaseToken $token): self |
31
|
6 |
|
{ |
32
|
|
|
return new self(sprintf('Undefined variable "%s" at position %d', $name, $token->getOffset())); |
33
|
|
|
} |
34
|
10 |
|
|
35
|
|
|
public static function undefinedMethod(string $name, BaseToken $token): self |
36
|
10 |
|
{ |
37
|
|
|
return new self(sprintf('Undefined method "%s" at position %d', $name, $token->getOffset())); |
38
|
|
|
} |
39
|
30 |
|
|
40
|
|
|
public static function forbiddenMethod(string $name, BaseToken $token): self |
41
|
30 |
|
{ |
42
|
|
|
return new self(sprintf('Forbidden method "%s" at position %d', $name, $token->getOffset())); |
43
|
|
|
} |
44
|
6 |
|
|
45
|
|
|
public static function undefinedFunction(string $name, BaseToken $token): self |
46
|
6 |
|
{ |
47
|
|
|
return new self(sprintf('%s is not defined at position %d', $name, $token->getOffset())); |
48
|
|
|
} |
49
|
8 |
|
|
50
|
|
|
public static function unexpectedComma(BaseToken $token): self |
51
|
8 |
|
{ |
52
|
|
|
return new self(sprintf('Unexpected "," at position %d', $token->getOffset())); |
53
|
|
|
} |
54
|
4 |
|
|
55
|
|
|
public static function unexpectedEndOfString(): self |
56
|
4 |
|
{ |
57
|
|
|
return new self('Unexpected end of string'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public static function unsupportedType(string $type): self |
61
|
|
|
{ |
62
|
|
|
return new self(sprintf('Unsupported PHP type: "%s"', $type)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public static function unknownOperator(BaseToken & Operator $token): self |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
return new self( |
68
|
|
|
sprintf('Unexpected operator %s at position %d', $token->getOriginalValue(), $token->getOffset()) |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|