From d59109e8fffa1d0b03234329e12f5d3e578804e8 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 3 May 2022 15:58:15 +0200 Subject: Support recursive show rules --- src/syntax/ast.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/syntax') diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index 42a4235d..fa00fe4b 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -1012,17 +1012,21 @@ node! { impl ShowExpr { /// The binding to assign to. - pub fn binding(&self) -> Ident { - self.0.cast_first_child().expect("show rule is missing binding") + pub fn binding(&self) -> Option { + let mut children = self.0.children(); + children + .find_map(RedRef::cast) + .filter(|_| children.any(|child| child.kind() == &NodeKind::Colon)) } - /// The function to customize with this show rule. - pub fn target(&self) -> Ident { + /// The pattern that this rule matches. + pub fn pattern(&self) -> Expr { self.0 .children() - .filter_map(RedRef::cast) - .nth(1) - .expect("show rule is missing target") + .rev() + .skip_while(|child| child.kind() != &NodeKind::As) + .find_map(RedRef::cast) + .expect("show rule is missing pattern") } /// The expression that realizes the node. -- cgit v1.2.3