You are here

public function CssScanner::nextToken in QueryPath 6

Same name and namespace in other branches
  1. 7.3 QueryPath/CssParser.php \CssScanner::nextToken()
  2. 7.2 QueryPath/CssParser.php \CssScanner::nextToken()
2 calls to CssScanner::nextToken()
CssScanner::getNameString in QueryPath/CssParser.php
CssScanner::getQuotedString in QueryPath/CssParser.php

File

QueryPath/CssParser.php, line 551

Class

CssScanner

Code

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;
}