33
44use Sabberworm \CSS \Comment \Comment ;
55use Sabberworm \CSS \Parsing \UnexpectedTokenException ;
6+ use Sabberworm \CSS \Parsing \UnexpectedEOFException ;
67use Sabberworm \CSS \Settings ;
78
89class ParserState {
10+ const EOF = null ;
11+
912 private $ oParserSettings ;
1013
1114 private $ sText ;
@@ -118,8 +121,7 @@ public function consumeWhiteSpace() {
118121 if ($ this ->oParserSettings ->bLenientParsing ) {
119122 try {
120123 $ 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 ) {
123125 $ this ->iCurrentPosition = $ this ->iLength ;
124126 return ;
125127 }
@@ -160,7 +162,7 @@ public function consume($mValue = 1) {
160162 return $ mValue ;
161163 } else {
162164 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 );
164166 }
165167 $ sResult = $ this ->substr ($ this ->iCurrentPosition , $ mValue );
166168 $ iLineCount = substr_count ($ sResult , "\n" );
@@ -214,7 +216,8 @@ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, a
214216 $ out = '' ;
215217 $ start = $ this ->iCurrentPosition ;
216218
217- while (($ char = $ this ->consume (1 )) !== '' ) {
219+ while (!$ this ->isEnd ()) {
220+ $ char = $ this ->consume (1 );
218221 if (in_array ($ char , $ aEnd )) {
219222 if ($ bIncludeEnd ) {
220223 $ out .= $ char ;
@@ -229,8 +232,12 @@ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, a
229232 }
230233 }
231234
235+ if (in_array (self ::EOF , $ aEnd )) {
236+ return $ out ;
237+ }
238+
232239 $ 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 );
234241 }
235242
236243 private function inputLeft () {
@@ -309,4 +316,4 @@ private function strpos($sString, $sNeedle, $iOffset) {
309316 return strpos ($ sString , $ sNeedle , $ iOffset );
310317 }
311318 }
312- }
319+ }
0 commit comments