3
3
4
4
use Sabberworm \CSS \Comment \Comment ;
5
5
use Sabberworm \CSS \Parsing \UnexpectedTokenException ;
6
+ use Sabberworm \CSS \Parsing \UnexpectedEOFException ;
6
7
use Sabberworm \CSS \Settings ;
7
8
8
9
class ParserState {
10
+ const EOF = null ;
11
+
9
12
private $ oParserSettings ;
10
13
11
14
private $ sText ;
@@ -118,8 +121,7 @@ public function consumeWhiteSpace() {
118
121
if ($ this ->oParserSettings ->bLenientParsing ) {
119
122
try {
120
123
$ oComment = $ this ->consumeComment ();
121
- } catch (UnexpectedTokenException $ e ) {
122
- // When we can’t find the end of a comment, we assume the document is finished.
124
+ } catch (UnexpectedEOFException $ e ) {
123
125
$ this ->iCurrentPosition = $ this ->iLength ;
124
126
return ;
125
127
}
@@ -160,7 +162,7 @@ public function consume($mValue = 1) {
160
162
return $ mValue ;
161
163
} else {
162
164
if ($ this ->iCurrentPosition + $ mValue > $ this ->iLength ) {
163
- throw new UnexpectedTokenException ($ mValue , $ this ->peek (5 ), 'count ' , $ this ->iLineNo );
165
+ throw new UnexpectedEOFException ($ mValue , $ this ->peek (5 ), 'count ' , $ this ->iLineNo );
164
166
}
165
167
$ sResult = $ this ->substr ($ this ->iCurrentPosition , $ mValue );
166
168
$ iLineCount = substr_count ($ sResult , "\n" );
@@ -214,7 +216,8 @@ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, a
214
216
$ out = '' ;
215
217
$ start = $ this ->iCurrentPosition ;
216
218
217
- while (($ char = $ this ->consume (1 )) !== '' ) {
219
+ while (!$ this ->isEnd ()) {
220
+ $ char = $ this ->consume (1 );
218
221
if (in_array ($ char , $ aEnd )) {
219
222
if ($ bIncludeEnd ) {
220
223
$ out .= $ char ;
@@ -229,8 +232,12 @@ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, a
229
232
}
230
233
}
231
234
235
+ if (in_array (self ::EOF , $ aEnd )) {
236
+ return $ out ;
237
+ }
238
+
232
239
$ this ->iCurrentPosition = $ start ;
233
- throw new UnexpectedTokenException ('One of (" ' .implode ('"," ' , $ aEnd ).'") ' , $ this ->peek (5 ), 'search ' , $ this ->iLineNo );
240
+ throw new UnexpectedEOFException ('One of (" ' .implode ('"," ' , $ aEnd ).'") ' , $ this ->peek (5 ), 'search ' , $ this ->iLineNo );
234
241
}
235
242
236
243
private function inputLeft () {
@@ -309,4 +316,4 @@ private function strpos($sString, $sNeedle, $iOffset) {
309
316
return strpos ($ sString , $ sNeedle , $ iOffset );
310
317
}
311
318
}
312
- }
319
+ }
0 commit comments