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 ExpectResult ExpTokEq = expect(tok_eq);
81 return std::make_shared<Binding>(
85 auto TokEq = std::make_shared<Misc>(ExpTokEq.tok().
range());
89 if (
Token Tok = peek(); Tok.
kind() == tok_semi_colon) {
95 Diagnostic &D = Diags.emplace_back(Diagnostic::DK_Expected,
97 D << std::string(tok::spelling(tok_semi_colon));
100 return std::make_shared<Binding>(
102 std::move(
Expr), std::move(TokEq));
106 Token TokInherit = peek();
107 if (TokInherit.
kind() != tok_kw_inherit)
110 auto SyncSemiColon = withSync(tok_semi_colon);
113 auto SyncID = withSync(tok_id);
114 auto SyncQuote = withSync(tok_dquote);
115 auto SyncDollarCurly = withSync(tok_dollar_curly);
117 assert(LastToken &&
"LastToken should be set after consume()");
118 std::vector<std::shared_ptr<AttrName>> AttrNames;
119 std::shared_ptr<Expr>
Expr =
nullptr;
120 if (
Token Tok = peek(); Tok.
kind() == tok_l_paren) {
125 if (ExpectResult ER = expect(tok_r_paren); ER.ok())
128 ER.diag().note(Note::NK_ToMachThis, Tok.range())
129 << std::string(tok::spelling(tok_l_paren));
133 AttrNames.emplace_back(std::move(
AttrName));
138 ExpectResult ER = expect(tok_semi_colon);
142 ER.diag().
note(Note::NK_ToMachThis, TokInherit.
range())
143 << std::string(tok::spelling(tok_kw_inherit));
146 if (AttrNames.empty()) {
148 Diags.emplace_back(Diagnostic::DK_EmptyInherit, TokInherit.
range());
150 Fix &F = D.
fix(
"remove `inherit` keyword");
157 return std::make_shared<Inherit>(
159 std::move(AttrNames), std::move(
Expr));
165 std::vector<std::shared_ptr<Node>> Bindings;
167 auto SyncID = withSync(tok_id);
168 auto SyncQuote = withSync(tok_dquote);
169 auto SyncDollarCurly = withSync(tok_dollar_curly);
172 auto SyncInherit = withSync(tok_kw_inherit);
175 Bindings.emplace_back(std::move(
Binding));
179 Bindings.emplace_back(std::move(
Inherit));
184 if (removeUnexpected())
188 if (Bindings.empty())
190 assert(LastToken &&
"LastToken should be set after valid binding");
192 std::move(Bindings));
196 std::shared_ptr<Misc> Rec;
198 auto Sync = withSync(tok_r_curly);
202 Token Matcher = peek();
204 if (
Token Tok = peek(); Tok.
kind() == tok_kw_rec) {
206 Rec = std::make_shared<Misc>(Tok.range());
208 if (ExpectResult ER = expect(tok_l_curly); ER.ok()) {
212 assert(LastToken &&
"LastToken should be set after valid { or rec");
214 if (ExpectResult ER = expect(tok_r_curly); ER.ok())
217 ER.diag().note(Note::NK_ToMachThis, Matcher.
range())
218 << std::string(tok::spelling(Matcher.
kind()));
220 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)
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)
Parser for the Nix expression language.