Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions src/Parsing/UnexpectedTokenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,20 @@
*/
class UnexpectedTokenException extends SourceException
{
/**
* @var string
*/
private $expected;

/**
* @var string
*/
private $found;

/**
* @var 'literal'|'identifier'|'count'|'expression'|'search'|'custom'
*/
private $matchType;

/**
* @param 'literal'|'identifier'|'count'|'expression'|'search'|'custom' $matchType
* @param int<0, max> $lineNumber
*/
public function __construct(string $expected, string $found, string $matchType = 'literal', int $lineNumber = 0)
{
$this->expected = $expected;
$this->found = $found;
$this->matchType = $matchType;
$message = "Token “{$expected}” ({$matchType}) not found. Got “{$found}”.";
if ($this->matchType === 'search') {
if ($matchType === 'search') {
$message = "Search for “{$expected}” returned no results. Context: “{$found}”.";
} elseif ($this->matchType === 'count') {
} elseif ($matchType === 'count') {
$message = "Next token was expected to have {$expected} chars. Context: “{$found}”.";
} elseif ($this->matchType === 'identifier') {
} elseif ($matchType === 'identifier') {
$message = "Identifier expected. Got “{$found}”";
} elseif ($this->matchType === 'custom') {
} elseif ($matchType === 'custom') {
$message = \trim("$expected $found");
}

Expand Down