Пример #1
0
 /**
  * Parses an attribute from a selector contained in $stream and returns
  * the resulting AttribNode object.
  *
  * @throws SyntaxError When encountered unexpected selector
  *
  * @param  Node\NodeInterface $selector The selector object whose attribute
  *                                      is to be parsed.
  * @param  TokenStream        $stream    The container token stream.
  *
  * @return Node\AttribNode
  */
 protected function parseAttrib($selector, $stream)
 {
     $attrib = $stream->next();
     if ($stream->peek() == '|') {
         $namespace = $attrib;
         $stream->next();
         $attrib = $stream->next();
     } else {
         $namespace = '*';
     }
     if ($stream->peek() == ']') {
         return new Node\AttribNode($selector, $namespace, $attrib, 'exists', null);
     }
     $op = $stream->next();
     if (!in_array($op, array('^=', '$=', '*=', '=', '~=', '|=', '!='))) {
         throw new SyntaxError(sprintf("Operator expected, got '%s'", $op));
     }
     $value = $stream->next();
     if (!$value->isType('Symbol') && !$value->isType('String')) {
         throw new SyntaxError(sprintf("Expected string or symbol, got '%s'", $value));
     }
     return new Node\AttribNode($selector, $namespace, $attrib, $op, $value);
 }