private function Parser::parseAttributeNode in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/css-selector/Parser/Parser.php \Symfony\Component\CssSelector\Parser\Parser::parseAttributeNode()
Parses next attribute node.
Parameters
Node\NodeInterface $selector:
TokenStream $stream:
Return value
Node\AttributeNode
Throws
1 call to Parser::parseAttributeNode()
- Parser::parseSimpleSelector in vendor/
symfony/ css-selector/ Parser/ Parser.php - Parses next simple node (hash, class, pseudo, negation).
File
- vendor/
symfony/ css-selector/ Parser/ Parser.php, line 335
Class
- Parser
- CSS selector parser.
Namespace
Symfony\Component\CssSelector\ParserCode
private function parseAttributeNode(Node\NodeInterface $selector, TokenStream $stream) {
$stream
->skipWhitespace();
$attribute = $stream
->getNextIdentifierOrStar();
if (null === $attribute && !$stream
->getPeek()
->isDelimiter(array(
'|',
))) {
throw SyntaxErrorException::unexpectedToken('"|"', $stream
->getPeek());
}
if ($stream
->getPeek()
->isDelimiter(array(
'|',
))) {
$stream
->getNext();
if ($stream
->getPeek()
->isDelimiter(array(
'=',
))) {
$namespace = null;
$stream
->getNext();
$operator = '|=';
}
else {
$namespace = $attribute;
$attribute = $stream
->getNextIdentifier();
$operator = null;
}
}
else {
$namespace = $operator = null;
}
if (null === $operator) {
$stream
->skipWhitespace();
$next = $stream
->getNext();
if ($next
->isDelimiter(array(
']',
))) {
return new Node\AttributeNode($selector, $namespace, $attribute, 'exists', null);
}
elseif ($next
->isDelimiter(array(
'=',
))) {
$operator = '=';
}
elseif ($next
->isDelimiter(array(
'^',
'$',
'*',
'~',
'|',
'!',
)) && $stream
->getPeek()
->isDelimiter(array(
'=',
))) {
$operator = $next
->getValue() . '=';
$stream
->getNext();
}
else {
throw SyntaxErrorException::unexpectedToken('operator', $next);
}
}
$stream
->skipWhitespace();
$value = $stream
->getNext();
if ($value
->isNumber()) {
// if the value is a number, it's casted into a string
$value = new Token(Token::TYPE_STRING, (string) $value
->getValue(), $value
->getPosition());
}
if (!($value
->isIdentifier() || $value
->isString())) {
throw SyntaxErrorException::unexpectedToken('string or identifier', $value);
}
$stream
->skipWhitespace();
$next = $stream
->getNext();
if (!$next
->isDelimiter(array(
']',
))) {
throw SyntaxErrorException::unexpectedToken('"]"', $next);
}
return new Node\AttributeNode($selector, $namespace, $attribute, $operator, $value
->getValue());
}