function Parser::parseIdentifier
Parses an identifier
Parameters
int $mode Parsing mode, one of the id parsing mode: constants
string $after If a string is passed in this parameter, the: identifier is parsed only if precedes this string
Return value
Node\Identifier|null
22 calls to Parser::parseIdentifier()
- Parser::parseArrowParameters in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses parameters in an arrow function. If the parameters are wrapped in round brackets, the returned value is an array where the first element is the parameters list and the second element is the open round brackets, this is needed to know the start…
- Parser::parseBindingRestElement in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses a rest element
- Parser::parseBreakStatement in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses a break statement
- Parser::parseCatchParameter in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses the catch parameter of a catch block in a try-catch statement
- Parser::parseClassDeclaration in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses a class declaration
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php, line 3753
Class
- Parser
- Parser class
Namespace
Peast\SyntaxCode
protected function parseIdentifier($mode, $after = null) {
$token = $this->scanner
->getToken();
if (!$token) {
return null;
}
if ($after !== null) {
$next = $this->scanner
->getNextToken();
if (!$next || $next->value !== $after) {
return null;
}
}
$type = $token->type;
switch ($type) {
case Token::TYPE_BOOLEAN_LITERAL:
case Token::TYPE_NULL_LITERAL:
if ($mode !== self::ID_ALLOW_ALL) {
return null;
}
break;
case Token::TYPE_KEYWORD:
if ($mode === self::ID_ALLOW_NOTHING) {
return null;
}
elseif ($mode === self::ID_MIXED && $this->scanner
->isStrictModeKeyword($token)) {
return null;
}
break;
default:
if ($type !== Token::TYPE_IDENTIFIER) {
return null;
}
break;
}
//Exclude keywords that depend on parser context
$value = $token->value;
if ($mode === self::ID_MIXED && isset($this->contextKeywords[$value]) && $this->context->{$this->contextKeywords[$value]}) {
return null;
}
$this->scanner
->consumeToken();
$node = $this->createNode("Identifier", $token);
$node->setRawName($value);
return $this->completeNode($node);
}