Automattic\WooCommerce\Vendor\GraphQL\Language
Parser::parseValueLiteral
Value[Const] :
- [~Const] Variable
- IntValue
- FloatValue
- StringValue
- BooleanValue
- NullValue
- EnumValue
- ListValue[?Const]
- ObjectValue[?Const].
BooleanValue : one of true false
NullValue : null
EnumValue : Name but not true, false or null
Method of the class: Parser{}
No Hooks.
Returns
BooleanValueNode|EnumValueNode|FloatValueNode|IntValueNode|StringValueNode|VariableNode|ListValueNode|ObjectValueNode|NullValueNode.
Usage
// private - for code of main (parent) class only $result = $this->parseValueLiteral( $isConst ): ValueNode;
- $isConst(true|false) (required)
- .
Parser::parseValueLiteral() Parser::parseValueLiteral code WC 11.1.1
private function parseValueLiteral(bool $isConst): ValueNode
{
$token = $this->lexer->token;
switch ($token->kind) {
case Token::BRACKET_L:
return $this->parseArray($isConst);
case Token::BRACE_L:
return $this->parseObject($isConst);
case Token::INT:
$this->lexer->advance();
return new IntValueNode([
'value' => $token->value,
'loc' => $this->loc($token),
]);
case Token::FLOAT:
$this->lexer->advance();
return new FloatValueNode([
'value' => $token->value,
'loc' => $this->loc($token),
]);
case Token::STRING:
case Token::BLOCK_STRING:
return $this->parseStringLiteral();
case Token::NAME:
if ($token->value === 'true' || $token->value === 'false') {
$this->lexer->advance();
return new BooleanValueNode([
'value' => $token->value === 'true',
'loc' => $this->loc($token),
]);
}
if ($token->value === 'null') {
$this->lexer->advance();
return new NullValueNode([
'loc' => $this->loc($token),
]);
}
$this->lexer->advance();
return new EnumValueNode([
'value' => $token->value,
'loc' => $this->loc($token),
]);
case Token::DOLLAR:
if (! $isConst) {
return $this->parseVariable();
}
break;
}
throw $this->unexpected();
}