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\Parser\Exception; |
11
|
|
|
|
12
|
|
|
use nicoSWD\Rule\TokenStream\Token\BaseToken; |
13
|
|
|
|
14
|
|
|
class ParserException extends \Exception |
15
|
|
|
{ |
16
|
16 |
|
public static function unexpectedToken(BaseToken $token): self |
17
|
|
|
{ |
18
|
16 |
|
return new self(sprintf('Unexpected "%s" at position %d', $token->getValue(), $token->getOffset())); |
19
|
|
|
} |
20
|
|
|
|
21
|
6 |
|
public static function unknownToken(BaseToken $token): self |
22
|
|
|
{ |
23
|
6 |
|
return new self(sprintf('Unknown token "%s" at position %d', $token->getValue(), $token->getOffset())); |
24
|
|
|
} |
25
|
|
|
|
26
|
2 |
|
public static function incompleteExpression(BaseToken $token): self |
27
|
|
|
{ |
28
|
2 |
|
return new self(sprintf('Incomplete expression for token "%s"', $token->getValue())); |
29
|
|
|
} |
30
|
|
|
|
31
|
4 |
|
public static function undefinedVariable(string $name, BaseToken $token): self |
32
|
|
|
{ |
33
|
4 |
|
return new self(sprintf('Undefined variable "%s" at position %d', $name, $token->getOffset())); |
34
|
|
|
} |
35
|
|
|
|
36
|
4 |
|
public static function undefinedMethod(string $name, BaseToken $token): self |
37
|
|
|
{ |
38
|
4 |
|
return new self(sprintf('Undefined method "%s" at position %d', $name, $token->getOffset())); |
39
|
|
|
} |
40
|
|
|
|
41
|
4 |
|
public static function undefinedFunction(string $name, BaseToken $token): self |
42
|
|
|
{ |
43
|
4 |
|
return new self(sprintf('%s is not defined at position %d', $name, $token->getOffset())); |
44
|
|
|
} |
45
|
|
|
|
46
|
8 |
|
public static function unexpectedComma(BaseToken $token): self |
47
|
|
|
{ |
48
|
8 |
|
return new self(sprintf('Unexpected "," at position %d', $token->getOffset())); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|