Skip to content

Commit

Permalink
libnixf: assert & use LastToken for attrs error recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Jan 23, 2024
1 parent d54209f commit 4d6abe9
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions libnixf/src/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,25 +445,24 @@ class Parser {
consume();
} else {
// expected "{" for attrset
Point InsertPoint = LastToken ? LastToken->end() : peek().begin();
Diagnostic &D =
Diags.emplace_back(Diagnostic::DK_Expected, RangeTy(InsertPoint));
assert(LastToken && "LastToken should be set after valid rec");
Diagnostic &D = Diags.emplace_back(Diagnostic::DK_Expected,
RangeTy(LastToken->range()));
D << std::string(tok::spelling(tok_l_curly));
D.fix("insert {").edit(TextEdit::mkInsertion(InsertPoint, "{"));
D.fix("insert {").edit(TextEdit::mkInsertion(LastToken->end(), "{"));
}
assert(LastToken && "LastToken should be set after valid { or rec");
auto Binds = parseBinds();
if (Token Tok = peek(); Tok.kind() == tok_r_curly) {
consume();
} else {
// expected "}" for attrset
Point InsertPoint = LastToken ? LastToken->end() : peek().begin();
Diagnostic &D =
Diags.emplace_back(Diagnostic::DK_Expected, RangeTy(InsertPoint));
Diagnostic &D = Diags.emplace_back(Diagnostic::DK_Expected,
RangeTy(LastToken->range()));
D << std::string(tok::spelling(tok_r_curly));
D.note(Note::NK_ToMachThis, Matcher.range())
<< std::string(tok::spelling(Matcher.kind()));
D.fix("insert }").edit(TextEdit::mkInsertion(InsertPoint, "}"));
D.fix("insert }").edit(TextEdit::mkInsertion(LastToken->end(), "}"));
}
return std::make_shared<ExprAttrs>(RangeTy{Begin, LastToken->end()},
std::move(Binds), std::move(Rec));
Expand Down

0 comments on commit 4d6abe9

Please sign in to comment.