9 Diags.emplace_back(Diagnostic::DK_OrIdentifier, Tok.range());
14 std::make_shared<Identifier>(Tok.range(), std::string(Tok.view()));
15 return std::make_shared<AttrName>(std::move(ID), Tok.range());
18 std::shared_ptr<ExprString> String =
parseString(
false);
19 return std::make_shared<AttrName>(std::move(String));
21 case tok_dollar_curly: {
23 return std::make_shared<AttrName>(std::move(
Expr));
35 assert(LastToken &&
"LastToken should be set after valid attrname");
36 std::vector<std::shared_ptr<AttrName>> AttrNames;
37 const AttrName *PrevName = First.get();
39 AttrNames.emplace_back(std::move(First));
40 std::vector<std::shared_ptr<Dot>> Dots;
41 auto SyncDot = withSync(tok_dot);
43 if (
Token Tok = peek(); Tok.
kind() == tok_dot) {
46 NextName = Next.get();
48 auto Do = std::make_shared<Dot>(Tok.range(), PrevName, NextName);
53 Dots.emplace_back(std::move(Do));
57 Diags.emplace_back(Diagnostic::DK_AttrPathExtraDot, Tok.range());
59 D.
fix(
"insert dummy attrname")
63 AttrNames.emplace_back(std::move(Next));
68 return std::make_shared<AttrPath>(
LexerCursorRange{Begin, LastToken->rCur()},
69 std::move(AttrNames), std::move(Dots));
76 assert(LastToken &&
"LastToken should be set after valid attrpath");
77 auto SyncEq = withSync(tok_eq);
78 auto SyncSemi = withSync(tok_semi_colon);
79 if (ExpectResult ER = expect(tok_eq); !ER.ok())
80 return std::make_shared<Binding>(
87 if (
Token Tok = peek(); Tok.
kind() == tok_semi_colon) {
93 Diagnostic &D = Diags.emplace_back(Diagnostic::DK_Expected,
98 return std::make_shared<Binding>(
104 Token TokInherit = peek();
105 if (TokInherit.
kind() != tok_kw_inherit)
108 auto SyncSemiColon = withSync(tok_semi_colon);
111 auto SyncID = withSync(tok_id);
112 auto SyncQuote = withSync(tok_dquote);
113 auto SyncDollarCurly = withSync(tok_dollar_curly);
115 assert(LastToken &&
"LastToken should be set after consume()");
116 std::vector<std::shared_ptr<AttrName>> AttrNames;
117 std::shared_ptr<Expr>
Expr =
nullptr;
118 if (
Token Tok = peek(); Tok.
kind() == tok_l_paren) {
123 if (ExpectResult ER = expect(tok_r_paren); ER.ok())
126 ER.diag().note(Note::NK_ToMachThis, Tok.range())
131 AttrNames.emplace_back(std::move(
AttrName));
136 ExpectResult ER = expect(tok_semi_colon);
140 ER.diag().
note(Note::NK_ToMachThis, TokInherit.
range())
144 if (AttrNames.empty()) {
146 Diags.emplace_back(Diagnostic::DK_EmptyInherit, TokInherit.
range());
148 Fix &F = D.
fix(
"remove `inherit` keyword");
155 return std::make_shared<Inherit>(
157 std::move(AttrNames), std::move(
Expr));
163 std::vector<std::shared_ptr<Node>> Bindings;
165 auto SyncID = withSync(tok_id);
166 auto SyncQuote = withSync(tok_dquote);
167 auto SyncDollarCurly = withSync(tok_dollar_curly);
170 auto SyncInherit = withSync(tok_kw_inherit);
173 Bindings.emplace_back(std::move(
Binding));
177 Bindings.emplace_back(std::move(
Inherit));
182 if (removeUnexpected())
186 if (Bindings.empty())
188 assert(LastToken &&
"LastToken should be set after valid binding");
190 std::move(Bindings));
194 std::shared_ptr<Misc> Rec;
196 auto Sync = withSync(tok_r_curly);
200 Token Matcher = peek();
202 if (
Token Tok = peek(); Tok.
kind() == tok_kw_rec) {
204 Rec = std::make_shared<Misc>(Tok.range());
206 if (ExpectResult ER = expect(tok_l_curly); ER.ok()) {
210 assert(LastToken &&
"LastToken should be set after valid { or rec");
212 if (ExpectResult ER = expect(tok_r_curly); ER.ok())
215 ER.diag().note(Note::NK_ToMachThis, Matcher.
range())
218 std::move(
Binds), std::move(Rec));
Note & note(Note::NoteKind Kind, LexerCursorRange Range)
Fix & fix(std::string Message)
Fix & edit(TextEdit Edit)
A point in the source file.
std::shared_ptr< Interpolation > parseInterpolation()
Parse interpolations.
std::shared_ptr< Expr > parseExpr()
std::shared_ptr< Inherit > parseInherit()
std::shared_ptr< AttrName > parseAttrName()
std::shared_ptr< ExprString > parseString(bool IsIndented)
std::shared_ptr< AttrPath > parseAttrPath()
std::shared_ptr< ExprAttrs > parseExprAttrs()
std::shared_ptr< Binds > parseBinds()
std::shared_ptr< Binding > parseBinding()
void tag(DiagnosticTag Tag)
std::shared_ptr< ExprAttrs > onExprAttrs(LexerCursorRange Range, std::shared_ptr< Binds > Binds, std::shared_ptr< Misc > Rec)
static TextEdit mkRemoval(LexerCursorRange RemovingRange)
static TextEdit mkInsertion(LexerCursor P, std::string NewText)
A token. With it's kind, and the range in source code.
tok::TokenKind kind() const
LexerCursorRange range() const
Diagnostic & diagNullExpr(std::vector< Diagnostic > &Diags, LexerCursor Loc, std::string As)
constexpr std::string_view spelling(TokenKind Kind)
Parser for the Nix expression language.