@@ -98,8 +98,8 @@ class RezParser(object):
9898
9999 start = "Start symbol must be set manually"
100100
101- def p_error (self , p ):
102- raise ParseError (p )
101+ def p_error (self , t ):
102+ raise ParseError (t , filename = t . lexer . filename , lineno = t . lineno )
103103
104104 def p_empty (self , p ):
105105 """empty : """
@@ -132,7 +132,11 @@ def p_intlit(self, p):
132132 """
133133
134134 if p [1 ].startswith ("'" ):
135- value = int .from_bytes (_unescape_string (p [1 ][1 :- 1 ]), "big" )
135+ try :
136+ unescaped = _unescape_string (p [1 ][1 :- 1 ])
137+ except ValueError as e :
138+ raise ParseError (str (e ), filename = p [- 1 ].lexer .filename , lineno = p [- 1 ].lineno )
139+ value = int .from_bytes (unescaped , "big" )
136140 elif p [1 ].startswith ("$" ):
137141 value = int (p [1 ][1 :], 16 )
138142 elif p [1 ].startswith ("0X" ) or p [1 ].startswith ("0x" ):
@@ -514,7 +518,11 @@ def p_single_string(self, p):
514518 if p [1 ].startswith ("$" ):
515519 p [0 ] = ast .StringLiteral (value = bytes .fromhex (p [1 ][2 :- 1 ]))
516520 else :
517- p [0 ] = ast .StringLiteral (value = _unescape_string (p [1 ][1 :- 1 ]))
521+ try :
522+ unescaped = _unescape_string (p [1 ][1 :- 1 ])
523+ except ValueError as e :
524+ raise ParseError (str (e ), filename = p [- 1 ].lexer .filename , lineno = p [- 1 ].lineno )
525+ p [0 ] = ast .StringLiteral (value = unescaped )
518526 else :
519527 p [0 ] = p [1 ]
520528
@@ -972,13 +980,13 @@ def p_array_field(self, p):
972980 for mod in p [1 ]:
973981 mod = mod .lower ()
974982 if mod in seen :
975- raise ParseError (f"Duplicate attribute { mod !r} " )
983+ raise ParseError (f"Duplicate attribute { mod !r} " , filename = p [ - 1 ]. lexer . filename , lineno = p [ - 1 ]. lineno )
976984 seen .add (mod )
977985
978986 if mod == "wide" :
979987 wide = True
980988 else :
981- raise ParseError (f"Unsupported modifier { mod !r} for type array" )
989+ raise ParseError (f"Unsupported modifier { mod !r} for type array" , filename = p [ - 1 ]. lexer . filename , lineno = p [ - 1 ]. lineno )
982990
983991 if len (p ) > 9 :
984992 p [0 ] = ast .ArrayField (wide = wide , label = None , count = p [4 ], fields = p [7 ])
@@ -1038,29 +1046,29 @@ def p_field(self, p):
10381046 for mod in modifiers :
10391047 mod = mod .lower ()
10401048 if mod in seen :
1041- raise ParseError (f"Duplicate attribute { mod !r} " )
1049+ raise ParseError (f"Duplicate attribute { mod !r} " , filename = p [ - 1 ]. lexer . filename , lineno = p [ - 1 ]. lineno )
10421050 seen .add (mod )
10431051
10441052 if mod == "key" :
10451053 is_key = True
10461054 elif mod == "unsigned" :
10471055 if typename not in ("bitstring" , "byte" , "integer" , "longint" ):
1048- raise ParseError (f"Unsupported modifier { mod !r} for type { typename !r} " )
1056+ raise ParseError (f"Unsupported modifier { mod !r} for type { typename !r} " , filename = p [ - 1 ]. lexer . filename , lineno = p [ - 1 ]. lineno )
10491057
10501058 signed = False
10511059 elif mod in ("binary" , "octal" , "decimal" , "hex" , "literal" ):
10521060 if mod == "hex" and typename == "string" :
10531061 # Special case: hex is allowed on string
10541062 pass
10551063 elif typename not in ("bitstring" , "byte" , "integer" , "longint" ):
1056- raise ParseError (f"Unsupported modifier { mod !r} for type { typename !r} " )
1064+ raise ParseError (f"Unsupported modifier { mod !r} for type { typename !r} " , filename = p [ - 1 ]. lexer . filename , lineno = p [ - 1 ]. lineno )
10571065
10581066 if base is None :
10591067 base = mod
10601068 else :
1061- raise ParseError (f"Duplicate base modifier { mod !r} (base was previously set to { base !r} " )
1069+ raise ParseError (f"Duplicate base modifier { mod !r} (base was previously set to { base !r} " , filename = p [ - 1 ]. lexer . filename , lineno = p [ - 1 ]. lineno )
10621070 else :
1063- raise ParseError (f"Invalid modifier: { mod !r} " )
1071+ raise ParseError (f"Invalid modifier: { mod !r} " , filename = p [ - 1 ]. lexer . filename , lineno = p [ - 1 ]. lineno )
10641072
10651073 if typename == "int" :
10661074 typename = "integer"
@@ -1087,7 +1095,7 @@ def p_field(self, p):
10871095 elif typename == "rect" :
10881096 fieldtype = ast .RectFieldType ()
10891097 else :
1090- raise ParseError (f"Unknown field type { typename !r} " )
1098+ raise ParseError (f"Unknown field type { typename !r} " , filename = p [ - 1 ]. lexer . filename , lineno = p [ - 1 ]. lineno )
10911099
10921100 if value_or_symconsts is None :
10931101 value = None
0 commit comments