aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase.py
diff options
context:
space:
mode:
authorDaniel Mensinger <daniel@mensinger-ka.de>2019-04-20 23:02:03 +0200
committerDaniel Mensinger <daniel@mensinger-ka.de>2019-04-23 09:10:47 +0200
commit75b7a856cd7a5fc8af697584aec453c82c7c923d (patch)
tree7d1563770c95e6dc75fb21f4715053a26d98c067 /mesonbuild/interpreterbase.py
parentfeff2630ae151f4a89f12f5b19babce605e64d58 (diff)
downloadmeson-75b7a856cd7a5fc8af697584aec453c82c7c923d.zip
meson-75b7a856cd7a5fc8af697584aec453c82c7c923d.tar.gz
meson-75b7a856cd7a5fc8af697584aec453c82c7c923d.tar.bz2
ast: support elementary object methods
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)