| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\JmesPath; |
| 4 |
|
| 5 |
/** |
| 6 |
* Syntax errors raise this exception that gives context |
| 7 |
*/ |
| 8 |
class SyntaxErrorException extends \InvalidArgumentException |
| 9 |
{ |
| 10 |
/** |
| 11 |
* @param string $expectedTypesOrMessage Expected array of tokens or message |
| 12 |
* @param array $token Current token |
| 13 |
* @param string $expression Expression input |
| 14 |
*/ |
| 15 |
public function __construct($expectedTypesOrMessage, array $token, $expression) |
| 16 |
{ |
| 17 |
$message = "Syntax error at character {$token['pos']}\n" . $expression . "\n" . \str_repeat(' ', \max($token['pos'], 0)) . "^\n"; |
| 18 |
$message .= !\is_array($expectedTypesOrMessage) ? $expectedTypesOrMessage : $this->createTokenMessage($token, $expectedTypesOrMessage); |
| 19 |
parent::__construct($message); |
| 20 |
} |
| 21 |
private function createTokenMessage(array $token, array $valid) |
| 22 |
{ |
| 23 |
return \sprintf('Expected one of the following: %s; found %s "%s"', \implode(', ', \array_keys($valid)), $token['type'], $token['value']); |
| 24 |
} |
| 25 |
} |
| 26 |
|