aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mensinger <daniel@mensinger-ka.de>2021-07-24 14:14:32 +0200
committerNirbheek Chauhan <nirbheek@centricular.com>2021-08-10 15:28:20 +0530
commite8f8b913195f9bcb1ca1ee501b0597fc7b01f8b6 (patch)
treeab236b7cf395eeef5c462505aad6a6a69b703603
parentca830daba5410227e1c845317a6c1ff98cead65b (diff)
downloadmeson-e8f8b913195f9bcb1ca1ee501b0597fc7b01f8b6.zip
meson-e8f8b913195f9bcb1ca1ee501b0597fc7b01f8b6.tar.gz
meson-e8f8b913195f9bcb1ca1ee501b0597fc7b01f8b6.tar.bz2
ast: Add dummy "support" for fstrings in the ast package
-rw-r--r--mesonbuild/ast/interpreter.py4
-rw-r--r--mesonbuild/ast/printer.py7
-rw-r--r--mesonbuild/ast/visitor.py3
-rwxr-xr-xrun_unittests.py1
-rw-r--r--test cases/unit/57 introspection/meson.build2
5 files changed, 17 insertions, 0 deletions
diff --git a/mesonbuild/ast/interpreter.py b/mesonbuild/ast/interpreter.py
index 99c6979..19b3a1d 100644
--- a/mesonbuild/ast/interpreter.py
+++ b/mesonbuild/ast/interpreter.py
@@ -197,6 +197,10 @@ class AstInterpreter(InterpreterBase):
def method_call(self, node: BaseNode) -> bool:
return True
+ def evaluate_fstring(self, node: mparser.FormatStringNode) -> str:
+ assert(isinstance(node, mparser.FormatStringNode))
+ return node.value
+
def evaluate_arithmeticstatement(self, cur: ArithmeticNode) -> int:
self.evaluate_statement(cur.left)
self.evaluate_statement(cur.right)
diff --git a/mesonbuild/ast/printer.py b/mesonbuild/ast/printer.py
index f535c2f..f185449 100644
--- a/mesonbuild/ast/printer.py
+++ b/mesonbuild/ast/printer.py
@@ -70,6 +70,10 @@ class AstPrinter(AstVisitor):
assert isinstance(node.value, str)
self.append("'" + node.value + "'", node)
+ def visit_FormatStringNode(self, node: mparser.FormatStringNode) -> None:
+ assert isinstance(node.value, str)
+ self.append("f'" + node.value + "'", node)
+
def visit_ContinueNode(self, node: mparser.ContinueNode) -> None:
self.append('continue', node)
@@ -256,6 +260,9 @@ class AstJSONPrinter(AstVisitor):
def visit_StringNode(self, node: mparser.StringNode) -> None:
self.gen_ElementaryNode(node)
+ def visit_FormatStringNode(self, node: mparser.FormatStringNode) -> None:
+ self.gen_ElementaryNode(node)
+
def visit_ArrayNode(self, node: mparser.ArrayNode) -> None:
self._accept('args', node.args)
self.setbase(node)
diff --git a/mesonbuild/ast/visitor.py b/mesonbuild/ast/visitor.py
index 0f2265c..34a76a8 100644
--- a/mesonbuild/ast/visitor.py
+++ b/mesonbuild/ast/visitor.py
@@ -36,6 +36,9 @@ class AstVisitor:
def visit_StringNode(self, node: mparser.StringNode) -> None:
self.visit_default_func(node)
+ def visit_FormatStringNode(self, node: mparser.FormatStringNode) -> None:
+ self.visit_default_func(node)
+
def visit_ContinueNode(self, node: mparser.ContinueNode) -> None:
self.visit_default_func(node)
diff --git a/run_unittests.py b/run_unittests.py
index 200c4ed..a66c608 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -5185,6 +5185,7 @@ class AllPlatformTests(BasePlatformTests):
'IdNode': [('value', None, str)],
'NumberNode': [('value', None, int)],
'StringNode': [('value', None, str)],
+ 'FormatStringNode': [('value', None, str)],
'ContinueNode': [],
'BreakNode': [],
'ArgumentNode': [('positional', accept_node_list), ('kwargs', accept_kwargs)],
diff --git a/test cases/unit/57 introspection/meson.build b/test cases/unit/57 introspection/meson.build
index 2f666f3..568d5cc 100644
--- a/test cases/unit/57 introspection/meson.build
+++ b/test cases/unit/57 introspection/meson.build
@@ -27,6 +27,8 @@ var1 = '1'
var2 = 2.to_string()
var3 = 'test3'
+var4 = f'test @var1@ string' # TODO: Actually implement fstrings
+
cus1 = custom_target('custom target test 1', output: 'file2', input: 'cp.py',
command: [find_program('cp.py'), '@INPUT@', '@OUTPUT@'])
cus2 = custom_target('custom target test 2', output: 'file3', input: cus1,