You are here

final class CssScanner in QueryPath 6

Same name and namespace in other branches
  1. 7.3 QueryPath/CssParser.php \CssScanner
  2. 7.2 QueryPath/CssParser.php \CssScanner

Hierarchy

Expanded class hierarchy of CssScanner

File

QueryPath/CssParser.php, line 527

View source
final class CssScanner {
  var $is = NULL;
  public $value = NULL;
  public $token = NULL;
  var $recurse = FALSE;
  var $it = 0;
  public function __construct(CssInputStream $in) {
    $this->is = $in;
  }
  public function position() {
    return $this->is->position;
  }
  public function peek() {
    return $this->is
      ->peek();
  }
  public function nextToken() {
    $tok = -1;
    ++$this->it;
    if ($this->is
      ->isEmpty()) {
      if ($this->recurse) {
        throw new Exception("Recursion error detected at iteration " . $this->it . '.');
        exit;
      }
      $this->recurse = TRUE;
      $this->token = FALSE;
      return FALSE;
    }
    $ch = $this->is
      ->consume();
    if (ctype_space($ch)) {
      $this->value = ' ';
      $this->token = $tok = CssToken::white;
      return $tok;
    }
    if (ctype_alnum($ch) || $ch == '-' || $ch == '_') {
      $this->value = $ch;
      $this->token = $tok = CssToken::char;
      return $tok;
    }
    $this->value = $ch;
    switch ($ch) {
      case '*':
        $tok = CssToken::star;
        break;
      case chr(ord('>')):
        $tok = CssToken::rangle;
        break;
      case '.':
        $tok = CssToken::dot;
        break;
      case '#':
        $tok = CssToken::octo;
        break;
      case '[':
        $tok = CssToken::lsquare;
        break;
      case ']':
        $tok = CssToken::rsquare;
        break;
      case ':':
        $tok = CssToken::colon;
        break;
      case '(':
        $tok = CssToken::lparen;
        break;
      case ')':
        $tok = CssToken::rparen;
        break;
      case '+':
        $tok = CssToken::plus;
        break;
      case '~':
        $tok = CssToken::tilde;
        break;
      case '=':
        $tok = CssToken::eq;
        break;
      case '|':
        $tok = CssToken::pipe;
        break;
      case ',':
        $tok = CssToken::comma;
        break;
      case chr(34):
        $tok = CssToken::quote;
        break;
      case "'":
        $tok = CssToken::squote;
        break;
      case '\\':
        $tok = CssToken::bslash;
        break;
      case '^':
        $tok = CssToken::carat;
        break;
      case '$':
        $tok = CssToken::dollar;
        break;
      case '@':
        $tok = CssToken::at;
        break;
    }
    if ($tok == -1) {
      $ord = ord($ch);
      if ($ord >= 32 && $ord <= 126 || $ord >= 128 && $ord <= 255) {
        $tok = CssToken::stringLegal;
      }
      else {
        throw new Exception('Illegal character found in stream: ' . $ord);
      }
    }
    $this->token = $tok;
    return $tok;
  }
  public function getNameString() {
    $buf = '';
    while ($this->token === CssToken::char) {
      $buf .= $this->value;
      $this
        ->nextToken();
    }
    return $buf;
  }
  public function getQuotedString() {
    if ($this->token == CssToken::quote || $this->token == CssToken::squote || $this->token == CssToken::lparen) {
      $end = $this->token == CssToken::lparen ? CssToken::rparen : $this->token;
      $buf = '';
      $escape = FALSE;
      $this
        ->nextToken();
      while ($this->token !== FALSE && $this->token > -1) {
        if ($this->token == CssToken::bslash && !$escape) {
          $escape = TRUE;
        }
        elseif ($escape) {
          $buf .= $this->value;
          $escape = FALSE;
        }
        elseif ($this->token === $end) {
          $this
            ->nextToken();
          break;
        }
        else {
          $buf .= $this->value;
        }
        $this
          ->nextToken();
      }
      return $buf;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CssScanner::$is property
CssScanner::$it property
CssScanner::$recurse property
CssScanner::$token public property
CssScanner::$value public property
CssScanner::getNameString public function
CssScanner::getQuotedString public function
CssScanner::nextToken public function
CssScanner::peek public function
CssScanner::position public function
CssScanner::__construct public function