aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase/interpreterbase.py
diff options
context:
space:
mode:
authorCharles Brunet <charles.brunet@optelgroup.com>2023-08-23 09:24:05 -0400
committerCharles Brunet <charles.brunet@optelgroup.com>2023-09-11 07:51:18 -0400
commit35936283d24ed5a0aa76b184a7489d637d3e49c4 (patch)
treee6a0d7e95eca06437c15ddb9f89cfaa99c5f43fb /mesonbuild/interpreterbase/interpreterbase.py
parenta730a2fe215ae45c928370b5e28d2a844c082f38 (diff)
downloadmeson-35936283d24ed5a0aa76b184a7489d637d3e49c4.zip
meson-35936283d24ed5a0aa76b184a7489d637d3e49c4.tar.gz
meson-35936283d24ed5a0aa76b184a7489d637d3e49c4.tar.bz2
parser: preserve escape chars in strings
use separate Node for multiline strings
Diffstat (limited to 'mesonbuild/interpreterbase/interpreterbase.py')
-rw-r--r--mesonbuild/interpreterbase/interpreterbase.py20
1 files changed, 9 insertions, 11 deletions
diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py
index f35da33..eab96ef 100644
--- a/mesonbuild/interpreterbase/interpreterbase.py
+++ b/mesonbuild/interpreterbase/interpreterbase.py
@@ -196,8 +196,13 @@ class InterpreterBase:
self.assignment(cur)
elif isinstance(cur, mparser.MethodNode):
return self.method_call(cur)
- elif isinstance(cur, mparser.StringNode):
- return self._holderify(cur.value)
+ elif isinstance(cur, mparser.BaseStringNode):
+ if isinstance(cur, mparser.MultilineFormatStringNode):
+ return self.evaluate_multiline_fstring(cur)
+ elif isinstance(cur, mparser.FormatStringNode):
+ return self.evaluate_fstring(cur)
+ else:
+ return self._holderify(cur.value)
elif isinstance(cur, mparser.BooleanNode):
return self._holderify(cur.value)
elif isinstance(cur, mparser.IfClauseNode):
@@ -230,11 +235,6 @@ class InterpreterBase:
return self.evaluate_indexing(cur)
elif isinstance(cur, mparser.TernaryNode):
return self.evaluate_ternary(cur)
- elif isinstance(cur, mparser.FormatStringNode):
- if isinstance(cur, mparser.MultilineFormatStringNode):
- return self.evaluate_multiline_fstring(cur)
- else:
- return self.evaluate_fstring(cur)
elif isinstance(cur, mparser.ContinueNode):
raise ContinueRequest()
elif isinstance(cur, mparser.BreakNode):
@@ -256,7 +256,7 @@ class InterpreterBase:
@FeatureNew('dict', '0.47.0')
def evaluate_dictstatement(self, cur: mparser.DictNode) -> InterpreterObject:
def resolve_key(key: mparser.BaseNode) -> str:
- if not isinstance(key, mparser.StringNode):
+ if not isinstance(key, mparser.BaseStringNode):
FeatureNew.single_use('Dictionary entry using non literal key', '0.53.0', self.subproject)
key_holder = self.evaluate_statement(key)
if key_holder is None:
@@ -428,9 +428,7 @@ class InterpreterBase:
return self.evaluate_fstring(node)
@FeatureNew('format strings', '0.58.0')
- def evaluate_fstring(self, node: mparser.FormatStringNode) -> InterpreterObject:
- assert isinstance(node, mparser.FormatStringNode)
-
+ def evaluate_fstring(self, node: T.Union[mparser.FormatStringNode, mparser.MultilineFormatStringNode]) -> InterpreterObject:
def replace(match: T.Match[str]) -> str:
var = str(match.group(1))
try: