Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function lex(Input $in, Lexer $lexer)
 {
     $cur = $in->current();
     if ('+' === $cur || '-' === $cur) {
         $in->next();
     }
     $isHex = false;
     $digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
     // range('0', '9')? lolphp
     if ('0' === $in->current() && in_array($in->peek(), ['x', 'X'])) {
         $in->next();
         $in->next();
         $isHex = true;
         $digits = array_merge($digits, range('a', 'f'), range('A', 'F'));
     }
     $this->consumeDigits($in, $digits);
     $char = $in->current();
     if ($isHex || '.' !== $char) {
         $this->checkNumberFinished($char, $in);
         $lexer->emit(Token::INT_VALUE);
     } elseif ('.' === $char) {
         $in->next();
         $this->consumeDigits($in, $digits);
         $this->checkNumberFinished($in->peek(), $in);
         $lexer->emit(TOKEN::FLOAT_VALUE);
     }
     return $this->previousState();
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function lex(Input $in, Lexer $lexer)
 {
     while (true) {
         $char = $in->current();
         if (null === $char) {
             throw new SyntaxError('Unexpected EOF at ' . $in->context());
         }
         if (!$this->isWhitespace($char)) {
             break;
         }
         $in->next();
     }
     $cur = $in->current();
     switch ($cur) {
         case '(':
             return new OpenList($this);
             break;
         case ')':
             return new CloseList($this->previousState());
             break;
         case '"':
             return new InsideString('"', $this);
             break;
         case "'":
             return new InsideString("'", $this);
             break;
         case '+':
         case '-':
             $next = $in->peek();
             if ($this->isWhitespace($next) || $this->isCloseList($next)) {
                 return new InsideIdent($this);
                 break;
             }
         case '0':
         case '1':
         case '2':
         case '3':
         case '4':
         case '5':
         case '6':
         case '7':
         case '8':
         case '9':
             return new InsideNumber($this);
             break;
         case null:
             throw new SyntaxError('Unexpected EOF at ' . $in->context());
             break;
         default:
             return new InsideIdent($this);
             break;
     }
 }