File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -170,8 +170,8 @@ def _parse_define(self) -> None:
170170 if value [- 1 ] != quote :
171171 raise self ._error ("unterminated string literal" , token = token )
172172
173- # Remove the surrounding and any duplicate quotes
174- value = "" . join ( ch for ch in value if ch != quote )
173+ # Remove the surrounding quotes and flatten escape sequences
174+ value = value [ 1 : - 1 ]. encode (). decode ( "unicode_escape" )
175175 elif value [:2 ].lower () in ("b'" , 'b"' ):
176176 quote = value [1 ]
177177 if value [- 1 ] != quote :
Original file line number Diff line number Diff line change @@ -228,6 +228,8 @@ def test_define(cs: cstruct) -> None:
228228 #define MULTILINE (1 + \
229229 2 + \
230230 3)
231+ #define QUOTES "\' \" a'b\" "
232+ #define ESCAPE "\\ '\\ "a'b\\ "\\ n"
231233 #define FUNC(x) ( x == 0 )
232234 #define TERNARY(x) ( x ? 1 : 0 )
233235 """
@@ -243,6 +245,8 @@ def test_define(cs: cstruct) -> None:
243245 assert cs .consts ["NULLBYTES" ] == b"ADCRYPT\00 "
244246 assert cs .consts ["ARBITRARYBYTES" ] == b"\x00 \x01 \x02 "
245247 assert cs .consts ["MULTILINE" ] == 6
248+ assert cs .consts ["QUOTES" ] == "'\" a'b\" "
249+ assert cs .consts ["ESCAPE" ] == "'\" a'b\" \n "
246250 # We don't evaluate function-like macros yet, so they should be stored as their raw string representation
247251 assert cs .consts ["FUNC" ] == "(x) ( x == 0 )"
248252 assert cs .consts ["TERNARY" ] == "(x) ( x ? 1 : 0 )"
You can’t perform that action at this time.
0 commit comments