@@ -632,8 +632,6 @@ public function store()
632632 */
633633 public function throwException ($ message , $ code = 0 , TokenInterface $ relatedToken = null , $ previous = null )
634634 {
635- $ pattern = "Failed to parse: %s \nNear: %s \nLine: %s \nOffset: %s " ;
636-
637635 $ lexer = $ this ->parser ->getLexer ();
638636 //This will basically check for a source location for this Node. The process is like:
639637 //- If there's a related token, we use the cloned token's source location
@@ -648,24 +646,15 @@ public function throwException($message, $code = 0, TokenInterface $relatedToken
648646 : new SourceLocation (null , 0 , 0 )
649647 );
650648
651- $ near = $ lexer ->hasState ()
652- ? $ lexer ->getState ()->getReader ()->peek (20 )
653- : '[No clue] ' ;
654-
655- //We know where it occured!
656- $ path = $ location ->getPath ();
657-
658- if ($ path ) {
659- $ pattern .= "\nPath: $ path " ;
660- }
661-
662649 throw new ParserException (
663650 $ location ,
664- vsprintf ($ pattern , [
665- $ message ,
666- $ near ,
667- $ location ->getLine (),
668- $ location ->getOffset (),
651+ ParserException::message ($ message , [
652+ 'path ' => $ location ->getPath (),
653+ 'near ' => $ lexer ->hasState ()
654+ ? $ lexer ->getState ()->getReader ()->peek (20 )
655+ : '[No clue] ' ,
656+ 'line ' => $ location ->getLine (),
657+ 'offset ' => $ location ->getOffset (),
669658 ]),
670659 $ code ,
671660 $ relatedToken ,
0 commit comments