Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into new-store-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Jul 20, 2024
2 parents a6c6852 + 56757e1 commit d8856f4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/libexpr/nixexpr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ void ExprAttrs::showBindings(const SymbolTable & symbols, std::ostream & str) co
return sa < sb;
});
std::vector<Symbol> inherits;
std::map<ExprInheritFrom *, std::vector<Symbol>> inheritsFrom;
// We can use the displacement as a proxy for the order in which the symbols were parsed.
// The assignment of displacements should be deterministic, so that showBindings is deterministic.
std::map<Displacement, std::vector<Symbol>> inheritsFrom;
for (auto & i : sorted) {
switch (i->second.kind) {
case AttrDef::Kind::Plain:
Expand All @@ -93,7 +95,7 @@ void ExprAttrs::showBindings(const SymbolTable & symbols, std::ostream & str) co
case AttrDef::Kind::InheritedFrom: {
auto & select = dynamic_cast<ExprSelect &>(*i->second.e);
auto & from = dynamic_cast<ExprInheritFrom &>(*select.e);
inheritsFrom[&from].push_back(i->first);
inheritsFrom[from.displ].push_back(i->first);
break;
}
}
Expand All @@ -105,7 +107,7 @@ void ExprAttrs::showBindings(const SymbolTable & symbols, std::ostream & str) co
}
for (const auto & [from, syms] : inheritsFrom) {
str << "inherit (";
(*inheritFromExprs)[from->displ]->show(symbols, str);
(*inheritFromExprs)[from]->show(symbols, str);
str << ")";
for (auto sym : syms) str << " " << symbols[sym];
str << "; ";
Expand Down
13 changes: 12 additions & 1 deletion src/libexpr/parser-state.hh
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,23 @@ inline Expr * ParserState::stripIndentation(const PosIdx pos,
s2 = std::string(s2, 0, p + 1);
}

es2->emplace_back(i->first, new ExprString(std::move(s2)));
// Ignore empty strings for a minor optimisation and AST simplification
if (s2 != "") {
es2->emplace_back(i->first, new ExprString(std::move(s2)));
}
};
for (; i != es.end(); ++i, --n) {
std::visit(overloaded { trimExpr, trimString }, i->second);
}

// If there is nothing at all, return the empty string directly.
// This also ensures that equivalent empty strings result in the same ast, which is helpful when testing formatters.
if (es2->size() == 0) {
auto *const result = new ExprString("");
delete es2;
return result;
}

/* If this is a single string, then don't do a concatenation. */
if (es2->size() == 1 && dynamic_cast<ExprString *>((*es2)[0].second)) {
auto *const result = (*es2)[0].second;
Expand Down
1 change: 1 addition & 0 deletions tests/functional/lang/parse-okay-ind-string.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(let string = "str"; in [ (/some/path) ((/some/path)) ((/some/path)) ((/some/path + "\n end")) (string) ((string)) ((string)) ((string + "\n end")) ("") ("") ("end") ])
31 changes: 31 additions & 0 deletions tests/functional/lang/parse-okay-ind-string.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
let
string = "str";
in [
/some/path

''${/some/path}''

''
${/some/path}''

''${/some/path}
end''

string

''${string}''

''
${string}''

''${string}
end''

''''

''
''

''
end''
]

0 comments on commit d8856f4

Please sign in to comment.