From 774212e73834bf44a7b093799543d13ce739717a Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Wed, 1 Mar 2023 20:46:39 -0500 Subject: [PATCH] Revert "Exit meson with an error if an invalid escape sequence is found in a" This reverts commit 348248f0a19bdc80e8a184befb2faaa1d5e66f40. The rules were relaxed in commit ccc4ce28cc9077d77a0bc9e72b1177eba1be7186 to permit this, so it's never possible to raise this exception anymore. But that commit was incomplete, and didn't remove the now-useless infrastructure for exception handling. The test needed to test this was always broken, and then removed in commit 465ef856ac9b978f13414db4aff649c66f2e6be5, and still this useless try/except persisted. --- mesonbuild/mparser.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py index 9840f9fdb..e4440302e 100644 --- a/mesonbuild/mparser.py +++ b/mesonbuild/mparser.py @@ -37,16 +37,8 @@ ESCAPE_SEQUENCE_SINGLE_RE = re.compile(r''' | \\[\\'abfnrtv] # Single-character escapes )''', re.UNICODE | re.VERBOSE) -class MesonUnicodeDecodeError(MesonException): - def __init__(self, match: str) -> None: - super().__init__(match) - self.match = match - def decode_match(match: T.Match[str]) -> str: - try: - return codecs.decode(match.group(0).encode(), 'unicode_escape') - except UnicodeDecodeError: - raise MesonUnicodeDecodeError(match.group(0)) + return codecs.decode(match.group(0).encode(), 'unicode_escape') class ParseException(MesonException): def __init__(self, text: str, line: str, lineno: int, colno: int) -> None: @@ -205,10 +197,7 @@ class Lexer: "This will become a hard error in a future Meson release.") mlog.warning(mlog.code_line(msg, self.getline(line_start), col), location=BaseNode(lineno, col, filename)) value = match_text[2 if tid == 'fstring' else 1:-1] - try: - value = ESCAPE_SEQUENCE_SINGLE_RE.sub(decode_match, value) - except MesonUnicodeDecodeError as err: - raise MesonException(f"Failed to parse escape sequence: '{err.match}' in string:\n {match_text}") + value = ESCAPE_SEQUENCE_SINGLE_RE.sub(decode_match, value) elif tid in {'multiline_string', 'multiline_fstring'}: # For multiline strings, parse out the value and pass # through the normal string logic.