From bf41d56597349a7047f2034e3e3e00d4502220cc Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sat, 24 Jul 2021 14:14:32 +0200 Subject: ast: Add dummy "support" for fstrings in the ast package --- mesonbuild/ast/interpreter.py | 4 ++++ mesonbuild/ast/printer.py | 7 +++++++ mesonbuild/ast/visitor.py | 3 +++ 3 files changed, 14 insertions(+) (limited to 'mesonbuild/ast') 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) -- cgit v1.1