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);
48 return std::make_shared<ExprSelect>(
50 std::move(Do), std::move(Path), std::move(Default));
56 if (!Fn || !Fn->maybeLambda())
59 std::vector<std::shared_ptr<Expr>> Args;
64 Args.emplace_back(std::move(Arg));
69 return std::make_shared<ExprCall>(
146 Token TokIf = peek();
147 assert(TokIf.
kind() == tok_kw_if &&
"parseExprIf should start with `if`");
149 assert(LastToken &&
"LastToken should be set after consume()");
151 auto SyncThen = withSync(tok_kw_then);
152 auto SyncElse = withSync(tok_kw_else);
158 D.
fix(
"insert dummy condition")
161 if (peek().kind() != tok_kw_then)
163 std::move(Cond),
nullptr,
167 ExpectResult ExpKwThen = expect(tok_kw_then);
168 if (!ExpKwThen.ok()) {
171 N << std::string(tok::spelling(tok_kw_if));
173 std::move(Cond),
nullptr,
183 N << std::string(tok::spelling(tok_kw_if));
185 if (peek().kind() != tok_kw_else)
187 std::move(Cond), std::move(Then),
191 ExpectResult ExpKwElse = expect(tok_kw_else);
194 std::move(Cond), std::move(Then),
203 N << std::string(tok::spelling(tok_kw_if));
207 std::move(Cond), std::move(Then),
213 Token TokAssert = peek();
214 assert(TokAssert.
kind() == tok_kw_assert &&
"should be tok_kw_assert");
216 assert(LastToken &&
"LastToken should be set after consume()");
218 auto SyncSemi = withSync(tok_semi_colon);
223 D.
fix(
"remove `assert` keyword")
226 if (peek().kind() != tok_colon)
227 return std::make_shared<ExprAssert>(
232 ExpectResult ExpSemi = expect(tok_semi_colon);
237 N << std::string(tok::spelling(tok_kw_assert));
238 return std::make_shared<ExprAssert>(
250 return std::make_shared<ExprAssert>(
LexerCursorRange{LCur, LastToken->rCur()},
251 std::move(Cond), std::move(Value));
256 Token TokLet = peek();
257 assert(TokLet.
kind() == tok_kw_let &&
258 "first token should be tok_kw_let in parseExprLet()");
260 auto Let = std::make_shared<Misc>(TokLet.
range());
264 auto SyncIn = withSync(tok_kw_in);
266 assert(LastToken &&
"LastToken should be set after consume()");
271 ExpectResult ExpKwIn = expect(tok_kw_in);
276 std::move(Let),
nullptr,
277 nullptr, std::move(Attrs));
280 auto In = std::make_shared<Misc>(ExpKwIn.tok().
range());
289 std::move(Let), std::move(In), std::move(E),
295 Token TokWith = peek();
296 assert(TokWith.
kind() == tok_kw_with &&
"token should be tok_kw_with");
300 auto KwWith = std::make_shared<Misc>(TokWith.
range());
301 assert(LastToken &&
"LastToken should be set after consume()");
303 auto SyncSemi = withSync(tok_semi_colon);
308 diagNullExpr(Diags, LastToken->rCur(),
"with expression");
310 ExpectResult ExpSemi = expect(tok_semi_colon);
312 ExpSemi.diag().
note(Note::NK_ToMachThis, TokWith.
range())
313 << std::string(tok::spelling(tok_kw_with));
314 return std::make_shared<ExprWith>(
LexerCursorRange{LCur, LastToken->rCur()},
315 std::move(KwWith),
nullptr,
316 std::move(With),
nullptr);
319 auto TokSemi = std::make_shared<Misc>(ExpSemi.tok().
range());
327 return std::make_shared<ExprWith>(
LexerCursorRange{LCur, LastToken->rCur()},
328 std::move(KwWith), std::move(TokSemi),
329 std::move(With), std::move(E));
static TextEdit mkRemoval(LexerCursorRange RemovingRange)
static TextEdit mkInsertion(LexerCursor P, std::string NewText)