@@ -190,7 +190,8 @@ def parse(self, stream: TokenStream) -> Iterable[JSONPathSelector]:
190190
191191 if stream .current .kind not in (TOKEN_EOF , TOKEN_INTERSECTION , TOKEN_UNION ):
192192 raise JSONPathSyntaxError (
193- f"unexpected token { stream .current !r} " ,
193+ f"unexpected token { stream .current .value !r} " ,
194+ token = stream .current ,
194195 )
195196
196197 def parse_path (
@@ -291,7 +292,10 @@ def parse_selector_list(self, stream: TokenStream) -> ListSelector:
291292 elif stream .current .kind == TOKEN_SLICE_START :
292293 list_items .append (self .parse_slice (stream ))
293294 elif stream .current .kind == TOKEN_EOF :
294- raise JSONPathSyntaxError ("unexpected end of selector list" )
295+ raise JSONPathSyntaxError (
296+ "unexpected end of selector list" ,
297+ token = stream .current ,
298+ )
295299
296300 if stream .peek .kind != TOKEN_LIST_END :
297301 stream .expect_peek (TOKEN_COMMA )
@@ -306,7 +310,7 @@ def parse_filter(self, stream: TokenStream) -> Filter:
306310 expr = BooleanExpression (self .parse_filter_selector (stream ))
307311
308312 if stream .peek .kind == TOKEN_RPAREN :
309- raise JSONPathSyntaxError ("unmatched ')'" )
313+ raise JSONPathSyntaxError ("unbalanced ')'" , token = stream . current )
310314
311315 stream .next_token ()
312316 stream .expect (TOKEN_FILTER_END )
@@ -358,7 +362,9 @@ def parse_grouped_expression(self, stream: TokenStream) -> FilterExpression:
358362
359363 while stream .current .kind != TOKEN_RPAREN :
360364 if stream .current .kind in (TOKEN_EOF , TOKEN_FILTER_END ):
361- raise JSONPathSyntaxError ("unbalanced parentheses" )
365+ raise JSONPathSyntaxError (
366+ "unbalanced parentheses" , token = stream .current
367+ )
362368 expr = self .parse_infix_expression (stream , expr )
363369
364370 stream .expect (TOKEN_RPAREN )
@@ -389,8 +395,10 @@ def parse_list_literal(self, stream: TokenStream) -> FilterExpression:
389395 try :
390396 list_items .append (self .list_item_map [stream .current .kind ](stream ))
391397 except KeyError as err :
392- # TODO: line number etc.
393- raise JSONPathSyntaxError (f"unexpected { stream .current } " ) from err
398+ raise JSONPathSyntaxError (
399+ f"unexpected { stream .current .value !r} " ,
400+ token = stream .current ,
401+ ) from err
394402
395403 if stream .peek .kind != TOKEN_LIST_END :
396404 stream .expect_peek (TOKEN_COMMA )
@@ -410,7 +418,9 @@ def parse_filter_selector(
410418 msg = "end of expression"
411419 else :
412420 msg = repr (stream .current .value )
413- raise JSONPathSyntaxError (f"unexpected { msg } " ) from err
421+ raise JSONPathSyntaxError (
422+ f"unexpected { msg } " , token = stream .current
423+ ) from err
414424
415425 while True :
416426 peek_kind = stream .peek .kind
0 commit comments