66use  Sabberworm \CSS \Parsing \Anchor ;
77use  Sabberworm \CSS \Settings ;
88
9- class  ParserState
9+ use  Psr \Log \LoggerAwareInterface ;
10+ use  Psr \Log \LoggerAwareTrait ;
11+ use  Psr \Log \NullLogger ;
12+ 
13+ class  ParserState implements  LoggerAwareInterface
1014{
15+     use  LoggerAwareTrait;
16+ 
1117    /** 
1218     * @var null 
1319     * 
@@ -58,6 +64,8 @@ class ParserState
5864     */ 
5965    public  function  __construct ($ sTextSettings $ oParserSettings$ iLineNo1 )
6066    {
67+         $ this logger  = new  NullLogger ();
68+ 
6169        $ this oParserSettings  = $ oParserSettings
6270        $ this sText  = $ sText
6371        $ this iCurrentPosition  = 0 ;
@@ -137,10 +145,12 @@ public function setPosition($iPosition): void
137145    public  function  parseIdentifier ($ bIgnoreCasetrue )
138146    {
139147        if  ($ this isEnd ()) {
148+             $ this logger ->error ('Unexpected end of file while parsing identifier at line {line} ' , ['line '  => $ this iLineNo ]);
140149            throw  new  UnexpectedEOFException ('' , '' , 'identifier ' , $ this iLineNo );
141150        }
142151        $ sResult$ this parseCharacter (true );
143152        if  ($ sResultnull ) {
153+             $ this logger ->error ('Unexpected token while parsing identifier at line {line} ' , ['line '  => $ this iLineNo ]);
144154            throw  new  UnexpectedTokenException ($ sResult$ this peek (5 ), 'identifier ' , $ this iLineNo );
145155        }
146156        $ sCharacternull ;
@@ -287,13 +297,15 @@ public function consume($mValue = 1): string
287297            $ iLineCountsubstr_count ($ mValue"\n" );
288298            $ iLength$ this strlen ($ mValue
289299            if  (!$ this streql ($ this substr ($ this iCurrentPosition , $ iLength$ mValue
300+                 $ this logger ->error ('Unexpected token "{token}" at line {line} ' , ['token '  => $ mValue'line '  => $ this iLineNo ]);
290301                throw  new  UnexpectedTokenException ($ mValue$ this peek (max ($ iLength5 )), $ this iLineNo );
291302            }
292303            $ this iLineNo  += $ iLineCount
293304            $ this iCurrentPosition  += $ this strlen ($ mValue
294305            return  $ mValue
295306        } else  {
296307            if  ($ this iCurrentPosition  + $ mValue$ this iLength ) {
308+                 $ this logger ->error ('Unexpected end of file while consuming {count} chars at line {line} ' , ['count '  => $ mValue'line '  => $ this iLineNo ]);
297309                throw  new  UnexpectedEOFException ($ mValue$ this peek (5 ), 'count ' , $ this iLineNo );
298310            }
299311            $ sResult$ this substr ($ this iCurrentPosition , $ mValue
@@ -318,6 +330,14 @@ public function consumeExpression($mExpression, $iMaxLength = null): string
318330        if  (preg_match ($ mExpression$ sInput$ aMatchesPREG_OFFSET_CAPTURE ) === 1 ) {
319331            return  $ this consume ($ aMatches0 ][0 ]);
320332        }
333+         $ this logger ->error (
334+             'Unexpected expression "{token}" instead of {expression} at line {line} ' ,
335+             [
336+                 'token '  => $ this peek (5 ),
337+                 'expression '  => $ mExpression
338+                 'line '  => $ this iLineNo ,
339+                 ]
340+         );
321341        throw  new  UnexpectedTokenException ($ mExpression$ this peek (5 ), 'expression ' , $ this iLineNo );
322342    }
323343
@@ -391,6 +411,10 @@ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, a
391411        }
392412
393413        $ this iCurrentPosition  = $ start
414+         $ this logger ->error (
415+             'Unexpected end of file while searching for one of "{end}" at line {line} ' ,
416+             ['end '  => implode ('"," ' , $ aEnd'line '  => $ this iLineNo ]
417+         );
394418        throw  new  UnexpectedEOFException (
395419            'One of (" '  . implode ('"," ' , $ aEnd'") ' ,
396420            $ this peek (5 ),
0 commit comments