@@ -290,7 +290,9 @@ def __new__(cls, *args, **kwargs):
290
290
291
291
292
292
class CppParseError (Exception ):
293
- pass
293
+ def __init__ (self , msg , tok = None ):
294
+ Exception .__init__ (self , msg )
295
+ self .tok = tok
294
296
295
297
296
298
class CppTemplateParam (dict ):
@@ -2815,15 +2817,21 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
2815
2817
except Exception as e :
2816
2818
if debug :
2817
2819
raise
2820
+ context = ""
2821
+ if isinstance (e , CppParseError ):
2822
+ context = ": " + str (e )
2823
+ if e .tok :
2824
+ tok = e .tok
2825
+
2818
2826
if tok :
2819
- filename , lineno = tok .value . location
2827
+ filename , lineno = tok .location
2820
2828
msg = (
2821
- ' Not able to parse %s on line %d evaluating "%s" \n Error around: %s'
2822
- % (filename , lineno , tok .value , " " .join (self .nameStack ))
2829
+ " Not able to parse %s on line %d evaluating '%s'%s \n Error around: %s"
2830
+ % (filename , lineno , tok .value , context , " " .join (self .nameStack ))
2823
2831
)
2824
2832
else :
2825
- msg = "Error parsing %s\n Error around: %s" % (
2826
- self .headerFileName ,
2833
+ msg = "Error parsing %s%s \n Error around: %s" % (
2834
+ self .headerFileName , context ,
2827
2835
" " .join (self .nameStack ),
2828
2836
)
2829
2837
@@ -2872,12 +2880,12 @@ def _parse_error(self, tokens, expected):
2872
2880
else :
2873
2881
errtok = tokens [- 1 ]
2874
2882
if expected :
2875
- expected = ", expected " + expected
2883
+ expected = ", expected ' " + expected + "'"
2876
2884
2877
- msg = "unexpected %s %s" % (errtok .value , expected )
2885
+ msg = "unexpected '%s' %s" % (errtok .value , expected )
2878
2886
2879
2887
# TODO: better error message
2880
- return CppParseError (msg )
2888
+ return CppParseError (msg , errtok )
2881
2889
2882
2890
def _next_token_must_be (self , * tokenTypes ):
2883
2891
tok = self .lex .token ()
0 commit comments