diff options
author | piegames <git@piegames.de> | 2024-10-15 12:55:29 +0200 |
---|---|---|
committer | piegames <git@piegames.de> | 2024-10-18 11:40:04 +0000 |
commit | 878e18188215ad52784027c3489c7b4f6f0bcba3 (patch) | |
tree | f69527e37f4b457cf5ffe3dcf4389a39856b8239 /src/libexpr | |
parent | c852ae60da16b890f77e9e1b274d31dced73ae66 (diff) |
libexpr: Print interpolations more accurately in `show`
This is only a minor semantical distinction, but we should be able to
properly test it, and the parser tests rely on show for that.
Change-Id: I25e868cf9544e30cdff17deb5fd50a434e0f367e
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/nixexpr.cc | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 4b659b71a..0c1a1ec0e 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -247,9 +247,24 @@ void ExprConcatStrings::show(const SymbolTable & symbols, std::ostream & str) co { bool first = true; str << "("; - for (auto & i : es) { - if (first) first = false; else str << " + "; - i.second->show(symbols, str); + for (auto & [_pos, part] : es) { + if (first) + first = false; + else + str << " + "; + + if (forceString && !dynamic_cast<ExprString *>(part.get())) { + /* Print as a string with an interpolation, to preserve the + * semantics of the value having to be a string. + * Interpolations are weird and someone should eventually + * move them out into their own AST node please. + */ + str << "\"${"; + part->show(symbols, str); + str << "}\""; + } else { + part->show(symbols, str); + } } str << ")"; } |