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 ;
@@ -141,10 +149,12 @@ public function setPosition($iPosition)
141149    public  function  parseIdentifier ($ bIgnoreCasetrue )
142150    {
143151        if  ($ this isEnd ()) {
152+             $ this logger ->error ('Unexpected end of file while parsing identifier at line {line} ' , ['line '  => $ this iLineNo ]);
144153            throw  new  UnexpectedEOFException ('' , '' , 'identifier ' , $ this iLineNo );
145154        }
146155        $ sResult$ this parseCharacter (true );
147156        if  ($ sResultnull ) {
157+             $ this logger ->error ('Unexpected token while parsing identifier at line {line} ' , ['line '  => $ this iLineNo ]);
148158            throw  new  UnexpectedTokenException ($ sResult$ this peek (5 ), 'identifier ' , $ this iLineNo );
149159        }
150160        $ sCharacternull ;
@@ -291,13 +301,15 @@ public function consume($mValue = 1): string
291301            $ iLineCountsubstr_count ($ mValue"\n" );
292302            $ iLength$ this strlen ($ mValue
293303            if  (!$ this streql ($ this substr ($ this iCurrentPosition , $ iLength$ mValue
304+                 $ this logger ->error ('Unexpected token "{token}" at line {line} ' , ['token '  => $ mValue'line '  => $ this iLineNo ]);
294305                throw  new  UnexpectedTokenException ($ mValue$ this peek (max ($ iLength5 )), $ this iLineNo );
295306            }
296307            $ this iLineNo  += $ iLineCount
297308            $ this iCurrentPosition  += $ this strlen ($ mValue
298309            return  $ mValue
299310        } else  {
300311            if  ($ this iCurrentPosition  + $ mValue$ this iLength ) {
312+                 $ this logger ->error ('Unexpected end of file while consuming {count} chars at line {line} ' , ['count '  => $ mValue'line '  => $ this iLineNo ]);
301313                throw  new  UnexpectedEOFException ($ mValue$ this peek (5 ), 'count ' , $ this iLineNo );
302314            }
303315            $ sResult$ this substr ($ this iCurrentPosition , $ mValue
@@ -324,6 +336,14 @@ public function consumeExpression($mExpression, $iMaxLength = null)
324336        if  (preg_match ($ mExpression$ sInput$ aMatchesPREG_OFFSET_CAPTURE ) === 1 ) {
325337            return  $ this consume ($ aMatches0 ][0 ]);
326338        }
339+         $ this logger ->error (
340+             'Unexpected expression "{token}" instead of {expression} at line {line} ' ,
341+             [
342+                 'token '  => $ this peek (5 ),
343+                 'expression '  => $ mExpression
344+                 'line '  => $ this iLineNo ,
345+                 ]
346+         );
327347        throw  new  UnexpectedTokenException ($ mExpression$ this peek (5 ), 'expression ' , $ this iLineNo );
328348    }
329349
@@ -397,6 +417,10 @@ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, a
397417        }
398418
399419        $ this iCurrentPosition  = $ start
420+         $ this logger ->error (
421+             'Unexpected end of file while searching for one of "{end}" at line {line} ' ,
422+             ['end '  => implode ('"," ' , $ aEnd'line '  => $ this iLineNo ]
423+         );
400424        throw  new  UnexpectedEOFException (
401425            'One of (" '  . implode ('"," ' , $ aEnd'") ' ,
402426            $ this peek (5 ),
0 commit comments