Skip to content

Commit

Permalink
parser: Remove empty multiline string parts earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
infinisil committed Jul 16, 2024
1 parent 9300f85 commit 0093bf1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/libexpr/parser-state.hh
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ 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);
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")) ])
23 changes: 23 additions & 0 deletions tests/functional/lang/parse-okay-ind-string.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let
string = "str";
in [
/some/path

''${/some/path}''

''
${/some/path}''

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

string

''${string}''

''
${string}''

''${string}
end''
]

0 comments on commit 0093bf1

Please sign in to comment.