10 assert(LastToken &&
"LastToken should be set after valid expr");
14 if (Tok.
kind() != tok_dot) {
21 auto Do = std::make_shared<Dot>(Tok.
range(),
Expr.get(),
nullptr);
27 Diags.emplace_back(Diagnostic::DK_SelectExtraDot, Tok.
range());
29 D.
fix(
"insert dummy attrpath")
34 if (TokOr.
kind() != tok_kw_or) {
36 return std::make_shared<ExprSelect>(
38 std::move(Do), std::move(Path),
nullptr,
49 return std::make_shared<ExprSelect>(
51 std::move(Do), std::move(Path), std::move(Default),
58 if (!Fn || !Fn->maybeLambda())
61 std::vector<std::shared_ptr<Expr>> Args;
66 Args.emplace_back(std::move(Arg));
71 return std::make_shared<ExprCall>(
148 Token TokIf = peek();
149 assert(TokIf.
kind() == tok_kw_if &&
"parseExprIf should start with `if`");
151 assert(LastToken &&
"LastToken should be set after consume()");
153 auto SyncThen = withSync(tok_kw_then);
154 auto SyncElse = withSync(tok_kw_else);
160 D.
fix(
"insert dummy condition")
163 if (peek().kind() != tok_kw_then)
165 std::move(Cond),
nullptr,
169 ExpectResult ExpKwThen = expect(tok_kw_then);
170 if (!ExpKwThen.ok()) {
173 N << std::string(tok::spelling(tok_kw_if));
175 std::move(Cond),
nullptr,
185 N << std::string(tok::spelling(tok_kw_if));
187 if (peek().kind() != tok_kw_else)
189 std::move(Cond), std::move(Then),
193 ExpectResult ExpKwElse = expect(tok_kw_else);
196 std::move(Cond), std::move(Then),
205 N << std::string(tok::spelling(tok_kw_if));
209 std::move(Cond), std::move(Then),
215 Token TokAssert = peek();
216 assert(TokAssert.
kind() == tok_kw_assert &&
"should be tok_kw_assert");
218 assert(LastToken &&
"LastToken should be set after consume()");
220 auto SyncSemi = withSync(tok_semi_colon);
225 D.
fix(
"remove `assert` keyword")
228 if (peek().kind() != tok_colon)
229 return std::make_shared<ExprAssert>(
234 ExpectResult ExpSemi = expect(tok_semi_colon);
239 N << std::string(tok::spelling(tok_kw_assert));
240 return std::make_shared<ExprAssert>(
252 return std::make_shared<ExprAssert>(
LexerCursorRange{LCur, LastToken->rCur()},
253 std::move(Cond), std::move(Value));
258 Token TokLet = peek();
259 assert(TokLet.
kind() == tok_kw_let &&
260 "first token should be tok_kw_let in parseExprLet()");
262 auto Let = std::make_shared<Misc>(TokLet.
range());
266 auto SyncIn = withSync(tok_kw_in);
268 assert(LastToken &&
"LastToken should be set after consume()");
273 ExpectResult ExpKwIn = expect(tok_kw_in);
278 std::move(Let),
nullptr,
279 nullptr, std::move(Attrs));
282 auto In = std::make_shared<Misc>(ExpKwIn.tok().
range());
291 std::move(Let), std::move(In), std::move(E),
297 Token TokWith = peek();
298 assert(TokWith.
kind() == tok_kw_with &&
"token should be tok_kw_with");
302 auto KwWith = std::make_shared<Misc>(TokWith.
range());
303 assert(LastToken &&
"LastToken should be set after consume()");
305 auto SyncSemi = withSync(tok_semi_colon);
310 diagNullExpr(Diags, LastToken->rCur(),
"with expression");
312 ExpectResult ExpSemi = expect(tok_semi_colon);
314 ExpSemi.diag().
note(Note::NK_ToMachThis, TokWith.
range())
315 << std::string(tok::spelling(tok_kw_with));
316 return std::make_shared<ExprWith>(
LexerCursorRange{LCur, LastToken->rCur()},
317 std::move(KwWith),
nullptr,
318 std::move(With),
nullptr);
321 auto TokSemi = std::make_shared<Misc>(ExpSemi.tok().
range());
329 return std::make_shared<ExprWith>(
LexerCursorRange{LCur, LastToken->rCur()},
330 std::move(KwWith), std::move(TokSemi),
331 std::move(With), std::move(E));
static TextEdit mkRemoval(LexerCursorRange RemovingRange)
static TextEdit mkInsertion(LexerCursor P, std::string NewText)