PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 4.1.20
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v4.1.20
4.1.20 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 All 174 releases
searchpro / BerqWP / vendor-prefixed / vendor / symfony / css-selector / Parser / TokenStream.php

TokenStream.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 4.1.20, at BerqWP/vendor-prefixed/vendor/symfony/css-selector/Parser/TokenStream.php

143 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace BerqWP_Deps\Symfony\Component\CssSelector\Parser;
12
13 use BerqWP_Deps\Symfony\Component\CssSelector\Exception\InternalErrorException;
14 use BerqWP_Deps\Symfony\Component\CssSelector\Exception\SyntaxErrorException;
15 /**
16 * CSS selector token stream.
17 *
18 * This component is a port of the Python cssselect library,
19 * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
20 *
21 * @author Jean-François Simon <[email protected]>
22 *
23 * @internal
24 */
25 class TokenStream
26 {
27 /**
28 * @var Token[]
29 */
30 private $tokens = [];
31 /**
32 * @var Token[]
33 */
34 private $used = [];
35 /**
36 * @var int
37 */
38 private $cursor = 0;
39 /**
40 * @var Token|null
41 */
42 private $peeked;
43 /**
44 * @var bool
45 */
46 private $peeking = \false;
47 /**
48 * Pushes a token.
49 *
50 * @return $this
51 */
52 public function push(Token $token): self
53 {
54 $this->tokens[] = $token;
55 return $this;
56 }
57 /**
58 * Freezes stream.
59 *
60 * @return $this
61 */
62 public function freeze(): self
63 {
64 return $this;
65 }
66 /**
67 * Returns next token.
68 *
69 * @throws InternalErrorException If there is no more token
70 */
71 public function getNext(): Token
72 {
73 if ($this->peeking) {
74 $this->peeking = \false;
75 $this->used[] = $this->peeked;
76 return $this->peeked;
77 }
78 if (!isset($this->tokens[$this->cursor])) {
79 throw new InternalErrorException('Unexpected token stream end.');
80 }
81 return $this->tokens[$this->cursor++];
82 }
83 /**
84 * Returns peeked token.
85 */
86 public function getPeek(): Token
87 {
88 if (!$this->peeking) {
89 $this->peeked = $this->getNext();
90 $this->peeking = \true;
91 }
92 return $this->peeked;
93 }
94 /**
95 * Returns used tokens.
96 *
97 * @return Token[]
98 */
99 public function getUsed(): array
100 {
101 return $this->used;
102 }
103 /**
104 * Returns next identifier token.
105 *
106 * @throws SyntaxErrorException If next token is not an identifier
107 */
108 public function getNextIdentifier(): string
109 {
110 $next = $this->getNext();
111 if (!$next->isIdentifier()) {
112 throw SyntaxErrorException::unexpectedToken('identifier', $next);
113 }
114 return $next->getValue();
115 }
116 /**
117 * Returns next identifier or null if star delimiter token is found.
118 *
119 * @throws SyntaxErrorException If next token is not an identifier or a star delimiter
120 */
121 public function getNextIdentifierOrStar(): ?string
122 {
123 $next = $this->getNext();
124 if ($next->isIdentifier()) {
125 return $next->getValue();
126 }
127 if ($next->isDelimiter(['*'])) {
128 return null;
129 }
130 throw SyntaxErrorException::unexpectedToken('identifier or "*"', $next);
131 }
132 /**
133 * Skips next whitespace if any.
134 */
135 public function skipWhitespace()
136 {
137 $peek = $this->getPeek();
138 if ($peek->isWhitespace()) {
139 $this->getNext();
140 }
141 }
142 }
143