/** * {@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(); }
/** * {@inheritdoc} */ public function lex(Input $in, Lexer $lexer) { do { $char = $in->next(); } while ($this->isWhitespace($char) && null !== $char); if (null === $char) { $lexer->emit(Token::EOF); return self::STOP_TOKENIZING; } if (!$this->isOpenList($char)) { throw new SyntaxError(sprintf('Unexpected "%s" at %s, expected (', $char, $in->context())); } $lexer->emit(Token::OPEN_LIST); return new InsideList($this->previousState()); }
/** * {@inheritdoc} */ public function lex(Input $in, Lexer $lexer) { if (!$this->isCloseList($in->next())) { throw new SyntaxError(sprintf('Unexpected "%s" at %s, expected (', $in->current(), $in->context())); } $lexer->emit(Token::CLOSE_LIST); return $this->previousState() ?: new OpenList(); }
/** * {@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) || $this->isCloseList($char)) { break; } $in->next(); } $lexer->emit(Token::IDENTIFIER); return $this->previousState(); }
/** * {@inheritdoc} */ public function lex(Input $in, Lexer $lexer) { $this->expectedSurround($in); while (true) { $cur = $in->current(); if (null === $cur) { throw new SyntaxError('Unexpected EOF at ' . $in->context()); } if ($this->isSurroundChar($cur) && '\\' !== $in->lookbehind()) { break; } $in->next(); } $this->expectedSurround($in); $lexer->emit(Token::STRING_VALUE); return $this->previousState(); }