function Scanner::scanPunctuator
Punctuator scanning method
Return value
Token|null
1 call to Scanner::scanPunctuator()
- Scanner::getToken in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Scanner.php - Returns the current token
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Scanner.php, line 1581
Class
- Scanner
- Base class for scanners.
Namespace
Peast\SyntaxCode
protected function scanPunctuator() {
$token = null;
$char = $this->charAt();
//Check if the next char is a bracket
if (isset($this->brackets[$char])) {
//Check if it is a closing bracket
if ($this->brackets[$char]) {
$openBracket = $this->brackets[$char];
//Check if there is a corresponding open bracket
if (!isset($this->openBrackets[$openBracket]) || !$this->openBrackets[$openBracket]) {
if (!$this->isAfterSlash($this->getPosition(true))) {
$this->error();
}
}
else {
$this->openBrackets[$openBracket]--;
}
}
else {
if (!isset($this->openBrackets[$char])) {
$this->openBrackets[$char] = 0;
}
$this->openBrackets[$char]++;
}
$this->index++;
$this->column++;
$token = new Token(Token::TYPE_PUNCTUATOR, $char);
}
elseif ($match = $this->punctuatorsLSM
->match($this, $this->index, $char)) {
//Optional chaining punctuator cannot appear before a number, in this
//case only the question mark must be consumed
if ($match[1] === "?." && ($nextChar = $this->charAt($this->index + $match[0])) !== null && $nextChar >= "0" && $nextChar <= "9") {
$match = array(
1,
"?",
);
}
$this->index += $match[0];
$this->column += $match[0];
$token = new Token(Token::TYPE_PUNCTUATOR, $match[1]);
}
return $token;
}