@@ -51,7 +51,7 @@ def __init__(self, text: str) -> None:
5151 _ , name , value = line .strip ().split (maxsplit = 2 )
5252 DEFINES [name ] = c_eval (value )
5353 except Exception :
54- raise ParserError (f"Parsing line { line } " )
54+ raise ParserError (f"Parsing line ` { line } ` " )
5555 else :
5656 lines .append (line )
5757 text = "\n " .join (lines )
@@ -124,7 +124,7 @@ def parse_type(tokens: Tokens, __cls__: Type['AbstractCStruct'], byte_order: Opt
124124 if "[" in next_token :
125125 t = next_token .split ("[" )
126126 if len (t ) != 2 :
127- raise ParserError ("Error parsing: " + next_token )
127+ raise ParserError (f "Error parsing: ` { next_token } `" )
128128 next_token = t [0 ].strip ()
129129 vlen_part = t [1 ]
130130 vlen_expr = []
@@ -163,7 +163,7 @@ def parse_type(tokens: Tokens, __cls__: Type['AbstractCStruct'], byte_order: Opt
163163 try :
164164 ref = STRUCTS [tail ]
165165 except KeyError :
166- raise ParserError (f"Unknown ' { c_type } ' ' { tail } ' " )
166+ raise ParserError (f"Unknown ` { c_type } { tail } ` " )
167167 elif c_type .startswith ('enum' ):
168168 from .cenum import CEnum
169169
@@ -181,7 +181,7 @@ def parse_type(tokens: Tokens, __cls__: Type['AbstractCStruct'], byte_order: Opt
181181 try :
182182 ref = ENUMS [tail ]
183183 except KeyError :
184- raise ParserError (f"Unknown ' { c_type } ' ' { tail } ' " )
184+ raise ParserError (f"Unknown ` { c_type } { tail } ` " )
185185 else : # other types
186186 kind = Kind .NATIVE
187187 ref = None
@@ -201,7 +201,7 @@ def parse_typedef(tokens: Tokens, __cls__: Type['AbstractCStruct'], byte_order:
201201 TYPEDEFS [vname ] = f"struct { field_type .ref .__name__ } "
202202 t = tokens .pop ()
203203 if t != ';' :
204- raise ParserError (f"; expected but { t } found" )
204+ raise ParserError (f"`;` expected but ` { t } ` found" )
205205
206206
207207def parse_struct_def (
@@ -242,7 +242,7 @@ def parse_struct_def(
242242 elif name == '{' : # unnamed enum
243243 result = parse_enum (tokens , native_format = native_format )
244244 else :
245- raise ParserError (f"{ name } definition expected" )
245+ raise ParserError (f"` { name } ` definition expected" )
246246
247247 elif kind in ['struct' , 'union' ]:
248248 if result :
@@ -257,10 +257,10 @@ def parse_struct_def(
257257 tokens , __cls__ = __cls__ , __is_union__ = __is_union__ , __byte_order__ = __byte_order__ , __name__ = name
258258 )
259259 else :
260- raise ParserError (f"{ name } definition expected" )
260+ raise ParserError (f"` { name } ` definition expected" )
261261
262262 else :
263- raise ParserError (f"struct, union, or enum expected - { kind } " )
263+ raise ParserError (f"struct, union, or enum expected - ` { kind } ` found " )
264264 return result
265265
266266
@@ -274,7 +274,7 @@ def parse_enum_def(__def__: Union[str, Tokens], **kargs: Any) -> Optional[Dict[s
274274 return None
275275 kind = tokens .pop ()
276276 if kind not in ['enum' ]:
277- raise ParserError (f"enum expected - { kind } " )
277+ raise ParserError (f"enum expected - ` { kind } ` found " )
278278
279279 name = tokens .pop ()
280280 native_format = None
@@ -288,7 +288,7 @@ def parse_enum_def(__def__: Union[str, Tokens], **kargs: Any) -> Optional[Dict[s
288288 elif name == '{' : # unnamed enum
289289 return parse_enum (tokens )
290290 else :
291- raise ParserError (f"{ name } definition expected" )
291+ raise ParserError (f"` { name } ` definition expected" )
292292
293293
294294def parse_enum (
@@ -348,10 +348,10 @@ def parse_enum(
348348 except (ValueError , TypeError ):
349349 value = int (int_expr )
350350 else :
351- raise ParserError (f"{ __enum__ } is not a valid enum expression" )
351+ raise ParserError (f"` { __enum__ } ` is not a valid enum expression" )
352352
353353 if name in constants :
354- raise ParserError (f"duplicate enum name { name } " )
354+ raise ParserError (f"duplicate enum name ` { name } ` " )
355355 constants [name ] = value
356356
357357 if next_token == "}" :
@@ -416,15 +416,15 @@ def parse_struct(
416416 field_type = parse_type (tokens , __cls__ , __byte_order__ , offset )
417417 vname = tokens .pop ()
418418 if vname in fields_types :
419- raise ParserError (f"Duplicate member ' { vname } ' " )
419+ raise ParserError (f"Duplicate member ` { vname } ` " )
420420 if vname in dir (__cls__ ):
421- raise ParserError (f"Invalid reserved member name ' { vname } ' " )
421+ raise ParserError (f"Invalid reserved member name ` { vname } ` " )
422422 # anonymous nested union
423423 if vname == ';' and field_type .ref is not None and (__is_union__ or field_type .ref .__is_union__ ):
424424 # add the anonymous struct fields to the parent
425425 for nested_field_name , nested_field_type in field_type .ref .__fields_types__ .items ():
426426 if nested_field_name in fields_types :
427- raise ParserError (f"Duplicate member ' { nested_field_name } ' " )
427+ raise ParserError (f"Duplicate member ` { nested_field_name } ` " )
428428 fields_types [nested_field_name ] = nested_field_type
429429 vname = f"__anonymous{ anonymous } "
430430 anonymous += 1
@@ -438,7 +438,7 @@ def parse_struct(
438438 offset = field_type .offset + field_type .vsize
439439 t = tokens .pop ()
440440 if t != ';' :
441- raise ParserError (f"; expected but { t } found" )
441+ raise ParserError (f"`;` expected but ` { t } ` found" )
442442
443443 if __is_union__ : # C union
444444 # Calculate the sizeof union as size of its largest element
0 commit comments