Closed darichey closed 2 years ago
The typed api gives the same node for both the argument and body of a lambda like x: x.
x: x
fn main() { let nix_expr = "x: x"; if let rnix::ast::Expr::Lambda(lambda) = rnix::Root::parse(&nix_expr).ok().unwrap().expr().unwrap() { println!("{:?}", lambda.param()); println!("{:?}", lambda.body()); } }
Some(Ident(Ident(NODE_IDENT@0..1))) Some(Ident(Ident(NODE_IDENT@0..1)))
I think this is because both getters are using nth(0) here: https://github.com/nix-community/rnix-parser/blob/38c0f687c08b0f6eb1f5b9c7bf565a36c2911b20/src/ast/nodes.rs#L283-L287 since a NODE_IDENT is both a Param and Expr.
nth(0)
NODE_IDENT
Param
Expr
Changing the body getter to use nth(1) just shifts the problem such that expressions like { x }: x aren't handled properly, since here the param is a Pattern and there isn't a 1th Expr.
body
nth(1)
{ x }: x
Pattern
This needs to be handled in the parser be creating a new node, maybe NODE_PARAM instead of NODE_IDENT
NODE_PARAM
Ah ok that makes sense. I'll give that a shot
The typed api gives the same node for both the argument and body of a lambda like
x: x
.I think this is because both getters are using
nth(0)
here: https://github.com/nix-community/rnix-parser/blob/38c0f687c08b0f6eb1f5b9c7bf565a36c2911b20/src/ast/nodes.rs#L283-L287 since aNODE_IDENT
is both aParam
andExpr
.Changing the
body
getter to usenth(1)
just shifts the problem such that expressions like{ x }: x
aren't handled properly, since here the param is aPattern
and there isn't a 1thExpr
.