You are here

private function CssParser::attribute in QueryPath 6

Same name and namespace in other branches
  1. 7.3 QueryPath/CssParser.php \CssParser::attribute()
  2. 7.2 QueryPath/CssParser.php \CssParser::attribute()
1 call to CssParser::attribute()
CssParser::simpleSelectors in QueryPath/CssParser.php

File

QueryPath/CssParser.php, line 390

Class

CssParser

Code

private function attribute() {
  if ($this->scanner->token == CssToken::lsquare) {
    $attrVal = $op = $ns = NULL;
    $this->scanner
      ->nextToken();
    $this
      ->consumeWhitespace();
    if ($this->scanner->token === CssToken::at) {
      if ($this->strict) {
        throw new CssParseException('The @ is illegal in attributes.');
      }
      else {
        $this->scanner
          ->nextToken();
        $this
          ->consumeWhitespace();
      }
    }
    if ($this->scanner->token === CssToken::star) {
      $ns = '*';
      $this->scanner
        ->nextToken();
    }
    if ($this->scanner->token === CssToken::pipe) {
      $this->scanner
        ->nextToken();
      $this
        ->consumeWhitespace();
    }
    $attrName = $this->scanner
      ->getNameString();
    $this
      ->consumeWhitespace();
    if ($this->scanner->token === CssToken::pipe && $this->scanner
      ->peek() !== '=') {
      $ns = $attrName;
      $this->scanner
        ->nextToken();
      $attrName = $this->scanner
        ->getNameString();
      $this
        ->consumeWhitespace();
    }
    switch ($this->scanner->token) {
      case CssToken::eq:
        $this
          ->consumeWhitespace();
        $op = CssEventHandler::isExactly;
        break;
      case CssToken::tilde:
        if ($this->scanner
          ->nextToken() !== CssToken::eq) {
          $this
            ->throwError(CssToken::eq, $this->scanner->token);
        }
        $op = CssEventHandler::containsWithSpace;
        break;
      case CssToken::pipe:
        if ($this->scanner
          ->nextToken() !== CssToken::eq) {
          $this
            ->throwError(CssToken::eq, $this->scanner->token);
        }
        $op = CssEventHandler::containsWithHyphen;
        break;
      case CssToken::star:
        if ($this->scanner
          ->nextToken() !== CssToken::eq) {
          $this
            ->throwError(CssToken::eq, $this->scanner->token);
        }
        $op = CssEventHandler::containsInString;
        break;
      case CssToken::dollar:
        if ($this->scanner
          ->nextToken() !== CssToken::eq) {
          $this
            ->throwError(CssToken::eq, $this->scanner->token);
        }
        $op = CssEventHandler::endsWith;
        break;
      case CssToken::carat:
        if ($this->scanner
          ->nextToken() !== CssToken::eq) {
          $this
            ->throwError(CssToken::eq, $this->scanner->token);
        }
        $op = CssEventHandler::beginsWith;
        break;
    }
    if (isset($op)) {
      $this->scanner
        ->nextToken();
      $this
        ->consumeWhitespace();
      if ($this->scanner->token === CssToken::quote || $this->scanner->token === CssToken::squote) {
        $attrVal = $this->scanner
          ->getQuotedString();
      }
      else {
        $attrVal = $this->scanner
          ->getNameString();
      }
      if ($this->DEBUG) {
        print "ATTR: {$attrVal} AND OP: {$op}\n";
      }
    }
    $this
      ->consumeWhitespace();
    if ($this->scanner->token != CssToken::rsquare) {
      $this
        ->throwError(CssToken::rsquare, $this->scanner->token);
    }
    if (isset($ns)) {
      $this->handler
        ->attributeNS($attrName, $ns, $attrVal, $op);
    }
    elseif (isset($attrVal)) {
      $this->handler
        ->attribute($attrName, $attrVal, $op);
    }
    else {
      $this->handler
        ->attribute($attrName);
    }
    $this->scanner
      ->nextToken();
  }
}