summaryrefslogtreecommitdiff
path: root/src/syntax
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-05-03 15:58:15 +0200
committerLaurenz <laurmaedje@gmail.com>2022-05-03 15:58:15 +0200
commitd59109e8fffa1d0b03234329e12f5d3e578804e8 (patch)
treefe7453da6f2ae327993e5ca6436ddc6a448a2c41 /src/syntax
parentf77f1f61bf05ae506689be3c40252c5807276280 (diff)
Support recursive show rules
Diffstat (limited to 'src/syntax')
-rw-r--r--src/syntax/ast.rs18
1 files changed, 11 insertions, 7 deletions
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<Ident> {
+ 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.