private function expectedSurround(Input $in) { if (!$this->isSurroundChar($in->current())) { throw new SyntaxError(sprintf('Unexpected "%s" at %s, expected %s', $in->current(), $in->context(), $this->surroundChar)); } $in->next(); }
/** * {@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) { 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) { 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; } }
private function checkNumberFinished($char, Input $in) { if (!$this->isWhitespace($char) && !$this->isCloseList($char)) { throw new SyntaxError(sprintf('Unexpected "%s" at %s, expected whitespace or )', $char, $in->context())); } }