diff options
author | Laurin-Luis Lehning <65224843+e820@users.noreply.github.com> | 2021-03-07 21:02:32 +0100 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2021-03-10 08:55:22 -0500 |
commit | 07f467d0573d00a47e7d21a9a5cdf88ad813d1fc (patch) | |
tree | 33f0520b2d34d35d54387aacdf4998b2296750a8 | |
parent | 130adef77880fc99ee0a06cf3fba7696c7e7c7bc (diff) | |
download | meson-07f467d0573d00a47e7d21a9a5cdf88ad813d1fc.zip meson-07f467d0573d00a47e7d21a9a5cdf88ad813d1fc.tar.gz meson-07f467d0573d00a47e7d21a9a5cdf88ad813d1fc.tar.bz2 |
Switch fstring syntax to @..@ & limit fstring captures to int, str, float and bool
-rw-r--r-- | mesonbuild/interpreterbase.py | 8 | ||||
-rw-r--r-- | test cases/common/238 fstrings/meson.build | 6 |
2 files changed, 8 insertions, 6 deletions
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py index d486b89..93cd1c6 100644 --- a/mesonbuild/interpreterbase.py +++ b/mesonbuild/interpreterbase.py @@ -934,11 +934,15 @@ The result of this is undefined and will become a hard error in a future Meson r def replace(match: T.Match[str]) -> str: var = str(match.group(1)) try: - return str(self.variables[var]) + val = self.variables[var] + if not isinstance(val, (str, int, float, bool)): + raise mesonlib.MesonException(f'Identifier {var} does not name a formattable variable.') + + return str(val) except KeyError: raise mesonlib.MesonException(f'Identifier "{var}" does not name a variable.') - return re.sub(r'{([_a-zA-Z][_0-9a-zA-Z]*)}', replace, node.value) + return re.sub(r'@([_a-zA-Z][_0-9a-zA-Z]*)@', replace, node.value) def evaluate_foreach(self, node: mparser.ForeachClauseNode) -> None: assert(isinstance(node, mparser.ForeachClauseNode)) diff --git a/test cases/common/238 fstrings/meson.build b/test cases/common/238 fstrings/meson.build index ffee053..2db2649 100644 --- a/test cases/common/238 fstrings/meson.build +++ b/test cases/common/238 fstrings/meson.build @@ -2,8 +2,6 @@ project('meson-test', 'c') n = 10 m = 'bar' -s = f'test {n} string ({n}): {m}' +s = f'test @n@ string (@@n@@): @m@' -if s != 'test 10 string (10): bar' - error('Incorrect string formatting') -endif +assert(s == 'test 10 string (@10@): bar', 'Incorrect string formatting') |