12 std::shared_ptr<Misc> Comma =
nullptr;
13 if (
Token Tok = peek(); Tok.
kind() == tok_comma) {
15 Comma = std::make_shared<Misc>(Tok.range());
17 if (
Token Tok = peek(); Tok.
kind() == tok_id) {
19 assert(LastToken &&
"LastToken should be set after consume()");
21 std::make_shared<Identifier>(Tok.range(), std::string(Tok.view()));
22 if (peek().kind() != tok_question)
24 std::move(Comma), std::move(ID),
nullptr);
26 std::shared_ptr<Expr> Default =
parseExpr();
30 std::move(Comma), std::move(ID),
33 if (
Token Tok = peek(); Tok.
kind() == tok_ellipsis) {
35 assert(LastToken &&
"LastToken should be set after consume()");
36 std::shared_ptr<Misc> Ellipsis = std::make_shared<Misc>(Tok.range());
38 std::move(Comma), std::move(Ellipsis));
42 assert(LastToken &&
"LastToken should be set after consume()");
44 std::move(Comma),
nullptr,
51 ExpectResult ER = expect(tok_l_curly);
54 Token TokLCurly = ER.tok();
56 assert(LastToken &&
"LastToken should be set after consume()");
57 auto SyncRCurly = withSync(tok_r_curly);
58 auto SyncComma = withSync(tok_comma);
59 auto SyncQuestion = withSync(tok_question);
60 auto SyncID = withSync(tok_id);
62 std::vector<std::shared_ptr<Formal>> Members;
64 if (
Token Tok = peek(); Tok.
kind() == tok_r_curly)
68 Members.emplace_back(std::move(
Formal));
71 if (removeUnexpected())
75 if (ExpectResult ER = expect(tok_r_curly); ER.ok())
78 ER.diag().
note(Note::NK_ToMachThis, TokLCurly.
range())
86 if (
Token TokID = peek(); TokID.
kind() == tok_id) {
88 assert(LastToken &&
"LastToken should be set after consume()");
90 std::make_shared<Identifier>(TokID.range(), std::string(TokID.view()));
91 if (peek().kind() != tok_at)
93 std::move(ID),
nullptr);
100 Diags.emplace_back(Diagnostic::DK_LambdaArgExtraAt, TokID.range());
102 D.
fix(
"insert dummy formals")
106 std::move(ID), std::move(
Formals));
112 assert(LastToken &&
"LastToken should be set after valid formals");
113 Token TokAt = peek();
114 if (TokAt.
kind() != tok_at)
118 ExpectResult ER = expect(tok_id);
120 ER.diag().
note(Note::NK_ToMachThis, TokAt.
range())
126 auto ID = std::make_shared<Identifier>(ER.tok().
range(),
127 std::string(ER.tok().
view()));
129 std::move(ID), std::move(
Formals));
136 assert(LastToken &&
"LastToken should be set after parseLambdaArg");
139 if (ExpectResult ER = expect(tok_colon); ER.ok())
142 std::shared_ptr<Expr> Body =
parseExpr();
145 return std::make_shared<ExprLambda>(
LexerCursorRange{LCur, LastToken->rCur()},
146 std::move(Arg), std::move(Body));
static TextEdit mkRemoval(LexerCursorRange RemovingRange)
static TextEdit mkInsertion(LexerCursor P, std::string NewText)