Skip to content

Commit

Permalink
nixd/Syntax: use Binds for syntax nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Sep 26, 2023
1 parent 699a001 commit 6b01ff0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions nixd/include/nixd/Syntax/Nodes.inc
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ NODE(Braced, {
})

NODE(AttrSet, {
Binds *AttrBinds;
syntax::Binds *Binds;
bool Recursive;
COMMON_METHOD
})

NODE(LegacyLet, {
Binds *AttrBinds;
syntax::Binds *Binds;
COMMON_METHOD
})

Expand Down
14 changes: 7 additions & 7 deletions nixd/lib/Sema/Lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ void ExprAttrsBuilder::addAttrSet(const syntax::AttrSet &AS) {
auto Diag = mkRecDiag(Range, AS.Range, Recursive, AS.Recursive);
LW.Diags.emplace_back(std::move(Diag));
}
assert(AS.AttrBinds && "binds should not be empty! parser error?");
addBinds(*AS.AttrBinds);
assert(AS.Binds && "binds should not be empty! parser error?");
addBinds(*AS.Binds);
}

void ExprAttrsBuilder::addAttr(const syntax::Node *Attr,
Expand Down Expand Up @@ -246,7 +246,7 @@ void ExprAttrsBuilder::addAttr(const syntax::Node *Attr,
const auto *BodyAttrSet = dynamic_cast<const syntax::AttrSet *>(Body);
Nested[Sym] = std::make_unique<ExprAttrsBuilder>(
LW, BodyAttrSet->Range, BodyAttrSet->Recursive, IsLet);
Nested[Sym]->addBinds(*BodyAttrSet->AttrBinds);
Nested[Sym]->addBinds(*BodyAttrSet->Binds);
} else {
nix::ExprAttrs::AttrDef Def(LW.lower(Body), Attr->Range.Begin);
Result->attrs.insert({Sym, Def});
Expand Down Expand Up @@ -640,10 +640,10 @@ nix::Expr *Lowering::lower(const syntax::Node *Root) {
}
case Node::NK_AttrSet: {
const auto *AttrSet = dynamic_cast<const syntax::AttrSet *>(Root);
assert(AttrSet->AttrBinds && "null AttrBinds of the AttrSet!");
assert(AttrSet->Binds && "null Binds of the AttrSet!");
ExprAttrsBuilder Builder(*this, AttrSet->Range, AttrSet->Recursive,
/*IsLet=*/false);
Builder.addBinds(*AttrSet->AttrBinds);
Builder.addBinds(*AttrSet->Binds);
return Builder.finish();
}
case Node::NK_Int: {
Expand Down Expand Up @@ -671,9 +671,9 @@ nix::Expr *Lowering::lower(const syntax::Node *Root) {
case Node::NK_LegacyLet: {
// let { ..., .body = ... } -> rec { ..., body = ... }.body
const auto *LegacyLet = dynamic_cast<const syntax::LegacyLet *>(Root);
ExprAttrsBuilder Builder(*this, LegacyLet->AttrBinds->Range,
ExprAttrsBuilder Builder(*this, LegacyLet->Binds->Range,
/*Recursive=*/true, /*IsLet=*/false);
Builder.addBinds(*LegacyLet->AttrBinds);
Builder.addBinds(*LegacyLet->Binds);
nix::ExprAttrs *Attrs = Builder.finish();
return Ctx.Pool.record(
new nix::ExprSelect(nix::noPos, Attrs, STable.create("body")));
Expand Down
6 changes: 3 additions & 3 deletions nixd/lib/Syntax/Parser/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ expr_simple
}
| LET '{' binds '}' {
auto N = decorateNode(new LegacyLet, *yylocp, *Data);
N->AttrBinds = $3;
N->Binds = $3;
$$ = N;

Diagnostic Diag;
Expand All @@ -299,13 +299,13 @@ expr_simple
}
| REC '{' binds '}' {
auto N = decorateNode(new AttrSet, *yylocp, *Data);
N->AttrBinds = $3;
N->Binds = $3;
N->Recursive = true;
$$ = N;
}
| '{' binds '}' {
auto N = decorateNode(new AttrSet, *yylocp, *Data);
N->AttrBinds = $2;
N->Binds = $2;
N->Recursive = false;
$$ = N;
}
Expand Down

0 comments on commit 6b01ff0

Please sign in to comment.