10 assert(LastToken &&
"LastToken should be set after valid expr");
14 if (Tok.
kind() != tok_dot) {
26 Diags.emplace_back(Diagnostic::DK_SelectExtraDot, Tok.
range());
28 D.
fix(
"insert dummy attrpath")
33 if (TokOr.
kind() != tok_kw_or) {
35 return std::make_shared<ExprSelect>(
37 std::move(Path),
nullptr);
47 return std::make_shared<ExprSelect>(
49 std::move(Path), std::move(Default));
55 if (!Fn || !Fn->maybeLambda())
58 std::vector<std::shared_ptr<Expr>> Args;
63 Args.emplace_back(std::move(Arg));
68 return std::make_shared<ExprCall>(
138 Token TokIf = peek();
139 assert(TokIf.
kind() == tok_kw_if &&
"parseExprIf should start with `if`");
141 assert(LastToken &&
"LastToken should be set after consume()");
143 auto SyncThen = withSync(tok_kw_then);
144 auto SyncElse = withSync(tok_kw_else);
150 D.
fix(
"insert dummy condition")
153 if (peek().kind() != tok_kw_then)
155 std::move(Cond),
nullptr,
159 ExpectResult ExpKwThen = expect(tok_kw_then);
160 if (!ExpKwThen.ok()) {
165 std::move(Cond),
nullptr,
177 if (peek().kind() != tok_kw_else)
179 std::move(Cond), std::move(Then),
183 ExpectResult ExpKwElse = expect(tok_kw_else);
186 std::move(Cond), std::move(Then),
199 std::move(Cond), std::move(Then),
205 Token TokAssert = peek();
206 assert(TokAssert.
kind() == tok_kw_assert &&
"should be tok_kw_assert");
208 assert(LastToken &&
"LastToken should be set after consume()");
210 auto SyncSemi = withSync(tok_semi_colon);
215 D.
fix(
"remove `assert` keyword")
218 if (peek().kind() != tok_colon)
219 return std::make_shared<ExprAssert>(
224 ExpectResult ExpSemi = expect(tok_semi_colon);
230 return std::make_shared<ExprAssert>(
242 return std::make_shared<ExprAssert>(
LexerCursorRange{LCur, LastToken->rCur()},
243 std::move(Cond), std::move(Value));
248 Token TokLet = peek();
249 assert(TokLet.
kind() == tok_kw_let &&
250 "first token should be tok_kw_let in parseExprLet()");
252 auto Let = std::make_shared<Misc>(TokLet.
range());
256 auto SyncIn = withSync(tok_kw_in);
258 assert(LastToken &&
"LastToken should be set after consume()");
263 ExpectResult ExpKwIn = expect(tok_kw_in);
268 std::move(Let),
nullptr,
269 nullptr, std::move(Attrs));
272 auto In = std::make_shared<Misc>(ExpKwIn.tok().
range());
281 std::move(Let), std::move(In), std::move(E),
287 Token TokWith = peek();
288 assert(TokWith.
kind() == tok_kw_with &&
"token should be tok_kw_with");
292 auto KwWith = std::make_shared<Misc>(TokWith.
range());
293 assert(LastToken &&
"LastToken should be set after consume()");
295 auto SyncSemi = withSync(tok_semi_colon);
300 diagNullExpr(Diags, LastToken->rCur(),
"with expression");
302 ExpectResult ExpSemi = expect(tok_semi_colon);
304 ExpSemi.diag().
note(Note::NK_ToMachThis, TokWith.
range())
306 return std::make_shared<ExprWith>(
LexerCursorRange{LCur, LastToken->rCur()},
307 std::move(KwWith),
nullptr,
308 std::move(With),
nullptr);
311 auto TokSemi = std::make_shared<Misc>(ExpSemi.tok().
range());
319 return std::make_shared<ExprWith>(
LexerCursorRange{LCur, LastToken->rCur()},
320 std::move(KwWith), std::move(TokSemi),
321 std::move(With), std::move(E));
static TextEdit mkRemoval(LexerCursorRange RemovingRange)
static TextEdit mkInsertion(LexerCursor P, std::string NewText)