1
1
mirror of https://github.com/oxalica/nil.git synced 2024-11-23 03:57:06 +03:00

Optimize searching let and rec in Attrset

This commit is contained in:
oxalica 2022-11-16 21:39:24 +08:00
parent 1ac520b784
commit 4087d3acde
2 changed files with 17 additions and 3 deletions

View File

@ -151,7 +151,6 @@ impl LowerCtx<'_> {
self.alloc_expr(Expr::LetIn(bindings, body), ptr)
}
ast::Expr::AttrSet(e) => {
// RecAttrset is popular than LetAttrset, and is preferred.
let ctor = if e.rec_token().is_some() {
Expr::RecAttrset
} else if e.let_token().is_some() {

View File

@ -286,10 +286,25 @@ asts! {
value: Expr,
},
ATTR_SET = AttrSet [HasBindings] {
rec_token: T![rec],
let_token: T![let],
l_curly_token: T!['{'],
r_curly_token: T!['}'],
// These two are exclusive and can only be the first non-white token.
// Don't scan all children.
pub fn let_token(&self) -> Option<SyntaxToken> {
self.0
.children_with_tokens()
.filter_map(|it| it.into_token())
.find(|it| !it.kind().is_whitespace())
.filter(|tok| tok.kind() == T![let])
}
pub fn rec_token(&self) -> Option<SyntaxToken> {
self.0
.children_with_tokens()
.filter_map(|it| it.into_token())
.find(|it| !it.kind().is_whitespace())
.filter(|tok| tok.kind() == T![rec])
}
},
BINARY_OP = BinaryOp {
lhs: Expr,