Handler
2 years ago
Shortcut
2 years ago
Tokenizer
2 years ago
Parser.php
2 years ago
ParserInterface.php
2 years ago
Reader.php
2 years ago
Token.php
2 years ago
TokenStream.php
2 years ago
index.php
2 years ago
TokenStream.php
73 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\CssSelector\Parser; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\CssSelector\Exception\InternalErrorException; |
| 5 | use MailPoetVendor\Symfony\Component\CssSelector\Exception\SyntaxErrorException; |
| 6 | class TokenStream |
| 7 | { |
| 8 | private $tokens = []; |
| 9 | private $used = []; |
| 10 | private $cursor = 0; |
| 11 | private $peeked; |
| 12 | private $peeking = \false; |
| 13 | public function push(Token $token) : self |
| 14 | { |
| 15 | $this->tokens[] = $token; |
| 16 | return $this; |
| 17 | } |
| 18 | public function freeze() : self |
| 19 | { |
| 20 | return $this; |
| 21 | } |
| 22 | public function getNext() : Token |
| 23 | { |
| 24 | if ($this->peeking) { |
| 25 | $this->peeking = \false; |
| 26 | $this->used[] = $this->peeked; |
| 27 | return $this->peeked; |
| 28 | } |
| 29 | if (!isset($this->tokens[$this->cursor])) { |
| 30 | throw new InternalErrorException('Unexpected token stream end.'); |
| 31 | } |
| 32 | return $this->tokens[$this->cursor++]; |
| 33 | } |
| 34 | public function getPeek() : Token |
| 35 | { |
| 36 | if (!$this->peeking) { |
| 37 | $this->peeked = $this->getNext(); |
| 38 | $this->peeking = \true; |
| 39 | } |
| 40 | return $this->peeked; |
| 41 | } |
| 42 | public function getUsed() : array |
| 43 | { |
| 44 | return $this->used; |
| 45 | } |
| 46 | public function getNextIdentifier() : string |
| 47 | { |
| 48 | $next = $this->getNext(); |
| 49 | if (!$next->isIdentifier()) { |
| 50 | throw SyntaxErrorException::unexpectedToken('identifier', $next); |
| 51 | } |
| 52 | return $next->getValue(); |
| 53 | } |
| 54 | public function getNextIdentifierOrStar() : ?string |
| 55 | { |
| 56 | $next = $this->getNext(); |
| 57 | if ($next->isIdentifier()) { |
| 58 | return $next->getValue(); |
| 59 | } |
| 60 | if ($next->isDelimiter(['*'])) { |
| 61 | return null; |
| 62 | } |
| 63 | throw SyntaxErrorException::unexpectedToken('identifier or "*"', $next); |
| 64 | } |
| 65 | public function skipWhitespace() |
| 66 | { |
| 67 | $peek = $this->getPeek(); |
| 68 | if ($peek->isWhitespace()) { |
| 69 | $this->getNext(); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 |