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>(
145 Token TokIf = peek();
146 assert(TokIf.
kind() == tok_kw_if &&
"parseExprIf should start with `if`");
148 assert(LastToken &&
"LastToken should be set after consume()");
150 auto SyncThen = withSync(tok_kw_then);
151 auto SyncElse = withSync(tok_kw_else);
157 D.
fix(
"insert dummy condition")
160 if (peek().kind() != tok_kw_then)
162 std::move(Cond),
nullptr,
166 ExpectResult ExpKwThen = expect(tok_kw_then);
167 if (!ExpKwThen.ok()) {
172 std::move(Cond),
nullptr,
184 if (peek().kind() != tok_kw_else)
186 std::move(Cond), std::move(Then),
190 ExpectResult ExpKwElse = expect(tok_kw_else);
193 std::move(Cond), std::move(Then),
206 std::move(Cond), std::move(Then),
212 Token TokAssert = peek();
213 assert(TokAssert.
kind() == tok_kw_assert &&
"should be tok_kw_assert");
215 assert(LastToken &&
"LastToken should be set after consume()");
217 auto SyncSemi = withSync(tok_semi_colon);
222 D.
fix(
"remove `assert` keyword")
225 if (peek().kind() != tok_colon)
226 return std::make_shared<ExprAssert>(
231 ExpectResult ExpSemi = expect(tok_semi_colon);
237 return std::make_shared<ExprAssert>(
249 return std::make_shared<ExprAssert>(
LexerCursorRange{LCur, LastToken->rCur()},
250 std::move(Cond), std::move(Value));
255 Token TokLet = peek();
256 assert(TokLet.
kind() == tok_kw_let &&
257 "first token should be tok_kw_let in parseExprLet()");
259 auto Let = std::make_shared<Misc>(TokLet.
range());
263 auto SyncIn = withSync(tok_kw_in);
265 assert(LastToken &&
"LastToken should be set after consume()");
270 ExpectResult ExpKwIn = expect(tok_kw_in);
275 std::move(Let),
nullptr,
276 nullptr, std::move(Attrs));
279 auto In = std::make_shared<Misc>(ExpKwIn.tok().
range());
288 std::move(Let), std::move(In), std::move(E),
294 Token TokWith = peek();
295 assert(TokWith.
kind() == tok_kw_with &&
"token should be tok_kw_with");
299 auto KwWith = std::make_shared<Misc>(TokWith.
range());
300 assert(LastToken &&
"LastToken should be set after consume()");
302 auto SyncSemi = withSync(tok_semi_colon);
307 diagNullExpr(Diags, LastToken->rCur(),
"with expression");
309 ExpectResult ExpSemi = expect(tok_semi_colon);
311 ExpSemi.diag().
note(Note::NK_ToMachThis, TokWith.
range())
313 return std::make_shared<ExprWith>(
LexerCursorRange{LCur, LastToken->rCur()},
314 std::move(KwWith),
nullptr,
315 std::move(With),
nullptr);
318 auto TokSemi = std::make_shared<Misc>(ExpSemi.tok().
range());
326 return std::make_shared<ExprWith>(
LexerCursorRange{LCur, LastToken->rCur()},
327 std::move(KwWith), std::move(TokSemi),
328 std::move(With), std::move(E));
static TextEdit mkRemoval(LexerCursorRange RemovingRange)
static TextEdit mkInsertion(LexerCursor P, std::string NewText)