Revert "Exit meson with an error if an invalid escape sequence is found in a"

This reverts commit 348248f0a1.

The rules were relaxed in commit ccc4ce28cc
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 465ef856ac, and still this useless
try/except persisted.
pull/11466/head
Eli Schwartz 2 years ago
parent f0dc61a764
commit 774212e738
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 15
      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.

Loading…
Cancel
Save