Remove escaping for triple-quoted strings

Fixes #3429
pull/3447/head
Niklas Claesson 7 years ago committed by Jussi Pakkanen
parent 74404db469
commit cb0960a91e
  1. 16
      mesonbuild/mparser.py
  2. 8
      test cases/common/42 string operations/meson.build

@ -28,18 +28,6 @@ ESCAPE_SEQUENCE_SINGLE_RE = re.compile(r'''
| \\[\\'abfnrtv] # Single-character escapes
)''', re.UNICODE | re.VERBOSE)
# This is the regex for the supported escape sequences of a multiline string
# literal, like '''abc\x00'''. The only difference is that single quote (')
# doesn't require escaping.
ESCAPE_SEQUENCE_MULTI_RE = re.compile(r'''
( \\U........ # 8-digit hex escapes
| \\u.... # 4-digit hex escapes
| \\x.. # 2-digit hex escapes
| \\[0-7]{1,3} # Octal escapes
| \\N\{[^}]+\} # Unicode characters by name
| \\[\\abfnrtv] # Single-character escapes
)''', re.UNICODE | re.VERBOSE)
class MesonUnicodeDecodeError(MesonException):
def __init__(self, match):
super().__init__("%s" % match)
@ -187,10 +175,6 @@ This will become a hard error in a future Meson release.""", self.getline(line_s
elif tid == 'multiline_string':
tid = 'string'
value = match_text[3:-3]
try:
value = ESCAPE_SEQUENCE_MULTI_RE.sub(decode_match, value)
except MesonUnicodeDecodeError as err:
raise MesonException("Failed to parse escape sequence: '{}' in string:\n{}".format(err.match, match_text))
lines = match_text.split('\n')
if len(lines) > 1:
lineno += len(lines) - 1

@ -78,14 +78,14 @@ assert('"1.1.20"'.strip('".') == '1.1.20', '". badly stripped')
assert('"1.1.20" '.strip('" ') == '1.1.20', '". badly stripped')
bs_c = '''\c'''
bs_bs_c = '''\\\c'''
bs_bs_c = '''\\c'''
nl = '''
'''
bs_n = '''\\n'''
bs_n = '''\n'''
bs_nl = '''\
'''
bs_bs_n = '''\\\\n'''
bs_bs_nl = '''\\\\
bs_bs_n = '''\\n'''
bs_bs_nl = '''\\
'''
assert('\c' == bs_c, 'Single backslash broken')

Loading…
Cancel
Save