diff --git a/nixd/lib/Sema/Lowering.cpp b/nixd/lib/Sema/Lowering.cpp index acd620233..134117e38 100644 --- a/nixd/lib/Sema/Lowering.cpp +++ b/nixd/lib/Sema/Lowering.cpp @@ -615,6 +615,29 @@ nix::Expr *Lowering::lower(const syntax::Node *Root) { return Ctx.Pool.record(Ret); } + case Node::NK_String: { + const auto *String = dynamic_cast(Root); + auto *NixString = new nix::ExprString(std::string(String->S)); + return Ctx.Pool.record(NixString); + } + + case Node::NK_ConcatStrings: { + const auto &CS = dynamic_cast(Root); + nix::PosIdx P = CS->Range.Begin; + auto *ES = Ctx.ESPool.record(new EvalContext::ES); + for (Node *SubStr : CS->SubStrings) { + auto *NixSubStr = lower(SubStr); + ES->emplace_back(std::pair{SubStr->Range.Begin, NixSubStr}); + } + auto *NixConcatStrings = new nix::ExprConcatStrings(P, CS->ForceString, ES); + return Ctx.Pool.record(NixConcatStrings); + } + + case Node::NK_InterpExpr: { + const auto &IE = dynamic_cast(Root); + return lower(IE->Body); + } + } // switch return nullptr; diff --git a/nixd/tools/nixd-lint/test/lowering-string.nix b/nixd/tools/nixd-lint/test/lowering-string.nix new file mode 100644 index 000000000..5930a872f --- /dev/null +++ b/nixd/tools/nixd-lint/test/lowering-string.nix @@ -0,0 +1,8 @@ +# RUN: nixd-lint -dump-nix-ast %s | FileCheck %s +{ + # CHECK: ExprConcatStrings: (aa + "bbb" + cc) + s1 = "${aa}bbb${cc}"; + + # CHECK: ExprString: "aabbcc" + s2 = "aabbcc"; +}