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 /mesonbuild/interpreterbase.py | |
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
Diffstat (limited to 'mesonbuild/interpreterbase.py')
-rw-r--r-- | mesonbuild/interpreterbase.py | 8 |
1 files changed, 6 insertions, 2 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)) |