aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2019-04-24 22:50:23 +0300
committerGitHub <noreply@github.com>2019-04-24 22:50:23 +0300
commit8018ef6ac6dead04f9a9f37bed3b47237b90ebad (patch)
tree0cedc11158920ec074edc8b08a6fa118f27d30f9 /mesonbuild/interpreterbase.py
parent26e205293a590aa700711198fc4ec16727e567b2 (diff)
parent8e587dfeba48f4f659d702ccecf890eea471627a (diff)
downloadmeson-8018ef6ac6dead04f9a9f37bed3b47237b90ebad.zip
meson-8018ef6ac6dead04f9a9f37bed3b47237b90ebad.tar.gz
meson-8018ef6ac6dead04f9a9f37bed3b47237b90ebad.tar.bz2
Merge pull request #5292 from mensinda/introInterpFix
ast: Add basic string operation support for AstInterpreter (fixes #5286)
Diffstat (limited to 'mesonbuild/interpreterbase.py')
-rw-r--r--mesonbuild/interpreterbase.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py
index 650d1e0..c148cbd 100644
--- a/mesonbuild/interpreterbase.py
+++ b/mesonbuild/interpreterbase.py
@@ -920,6 +920,24 @@ The result of this is undefined and will become a hard error in a future Meson r
return mesonlib.version_compare(obj, cmpr)
raise InterpreterException('Unknown method "%s" for a string.' % method_name)
+ def format_string(self, templ, args):
+ if isinstance(args, mparser.ArgumentNode):
+ args = args.arguments
+ arg_strings = []
+ for arg in args:
+ arg = self.evaluate_statement(arg)
+ if isinstance(arg, bool): # Python boolean is upper case.
+ arg = str(arg).lower()
+ arg_strings.append(str(arg))
+
+ def arg_replace(match):
+ idx = int(match.group(1))
+ if idx >= len(arg_strings):
+ raise InterpreterException('Format placeholder @{}@ out of range.'.format(idx))
+ return arg_strings[idx]
+
+ return re.sub(r'@(\d+)@', arg_replace, templ)
+
def unknown_function_called(self, func_name):
raise InvalidCode('Unknown function "%s".' % func_name)