aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/Syntax.md3
-rw-r--r--docs/markdown/snippets/more-escape-sequences.md22
-rw-r--r--mesonbuild/mparser.py16
-rw-r--r--test cases/common/32 multiline string/meson.build10
-rw-r--r--test cases/common/42 string operations/meson.build12
5 files changed, 30 insertions, 33 deletions
diff --git a/docs/markdown/Syntax.md b/docs/markdown/Syntax.md
index 01c8c6e..30eedf8 100644
--- a/docs/markdown/Syntax.md
+++ b/docs/markdown/Syntax.md
@@ -131,7 +131,8 @@ int main (int argc, char ** argv) {
}'''
```
-This can also be combined with the string formatting functionality
+These are raw strings that do not support the escape sequences listed above.
+These strings can also be combined with the string formatting functionality
described below.
#### String formatting
diff --git a/docs/markdown/snippets/more-escape-sequences.md b/docs/markdown/snippets/more-escape-sequences.md
index 2894079..ad78ce2 100644
--- a/docs/markdown/snippets/more-escape-sequences.md
+++ b/docs/markdown/snippets/more-escape-sequences.md
@@ -1,17 +1,15 @@
-## String escape character update
+## String escape character sequence update
-The strings (both single-quoted and triple-quoted) in meson has been taught the
-same set of escape sequences as in Python. It is therefore now possible to use
-arbitrary bytes in strings, like for example NUL (`\0`) and other ASCII control
-characters. See the chapter about *Strings* in *Syntax* for more details.
+Single-quoted strings in meson have been taught the same set of escape
+sequences as in Python. It is therefore now possible to use arbitrary bytes in
+strings, like for example `NUL` (`\0`) and other ASCII control characters. See
+the chapter about [*Strings* in *Syntax*](Syntax.md#strings) for more
+details.
Potential backwards compatibility issue: Any valid escape sequence according to
the new rules will be interpreted as an escape sequence instead of the literal
-characters. Previously only single-quote strings supported escape sequences and
-the supported sequences were `\'`, `\\` and `\n`.
+characters. Previously only the following escape sequences were supported in
+single-quote strings: `\'`, `\\` and `\n`.
-The most likely breakage is usage of backslash-n in triple-quoted strings. It
-is now written in the same way as in single-quoted strings: `\\n` instead of
-`\n`. In general it is now recommended to escape any usage of backslash.
-However, backslash-c (`\c`), for example, is still backslash-c because it isn't
-a valid escape sequence.
+Note that the behaviour of triple-quoted (multiline) strings has not changed.
+They behave like raw strings and do not support any escape sequences.
diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py
index 9e43065..8cef377 100644
--- a/mesonbuild/mparser.py
+++ b/mesonbuild/mparser.py
@@ -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
diff --git a/test cases/common/32 multiline string/meson.build b/test cases/common/32 multiline string/meson.build
index 1f952f1..262cb15 100644
--- a/test cases/common/32 multiline string/meson.build
+++ b/test cases/common/32 multiline string/meson.build
@@ -23,3 +23,13 @@ quote2 = '\''
if quote1 != quote2
error('Single quote quoting is broken.')
endif
+
+cc = meson.get_compiler('c')
+prog = '''
+int main(int argc, char **argv) {
+ int num = 1;
+ printf("%d\n", num);
+ return 0;
+}'''
+
+assert(cc.compiles(prog), 'multline test compile failed')
diff --git a/test cases/common/42 string operations/meson.build b/test cases/common/42 string operations/meson.build
index 1c289eb..6596142 100644
--- a/test cases/common/42 string operations/meson.build
+++ b/test cases/common/42 string operations/meson.build
@@ -78,15 +78,17 @@ 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 = '''\\
'''
+bs_bs = '''\\'''
+bs = '''\'''
assert('\c' == bs_c, 'Single backslash broken')
assert('\\c' == bs_c, 'Double backslash broken')
@@ -97,3 +99,5 @@ assert('\\n' == bs_n, 'Double backslash broken before n')
assert('\\\n' == bs_nl, 'Three backslash broken before n')
assert('\\\\n' == bs_bs_n, 'Four backslash broken before n')
assert('\\\\\n' == bs_bs_nl, 'Five backslash broken before n')
+assert('\\\\' == bs_bs, 'Double-backslash broken')
+assert('\\' == bs, 'Backslash broken')