summaryrefslogtreecommitdiff
path: root/src/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax')
-rw-r--r--src/syntax/expr.rs11
-rw-r--r--src/syntax/visit.rs24
2 files changed, 27 insertions, 8 deletions
diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs
index cf9aff4a..9292d5b6 100644
--- a/src/syntax/expr.rs
+++ b/src/syntax/expr.rs
@@ -437,11 +437,20 @@ pub struct ClosureExpr {
/// This only exists if you use the function syntax sugar: `let f(x) = y`.
pub name: Option<Ident>,
/// The parameter bindings.
- pub params: Rc<Vec<Ident>>,
+ pub params: Vec<ClosureParam>,
/// The body of the closure.
pub body: Rc<Expr>,
}
+/// An parameter to a closure: `x` or `draw: false`.
+#[derive(Debug, Clone, PartialEq)]
+pub enum ClosureParam {
+ /// A positional parameter.
+ Pos(Ident),
+ /// A named parameter with a default value.
+ Named(Named),
+}
+
/// A with expression: `f with (x, y: 1)`.
///
/// Applies arguments to a function.
diff --git a/src/syntax/visit.rs b/src/syntax/visit.rs
index 81cba5c7..bc9359b3 100644
--- a/src/syntax/visit.rs
+++ b/src/syntax/visit.rs
@@ -192,13 +192,6 @@ impl_visitors! {
v.visit_args(r!(call.args));
}
- visit_closure(v, closure: ClosureExpr) {
- for param in r!(rc: closure.params) {
- v.visit_binding(param);
- }
- v.visit_expr(r!(rc: closure.body));
- }
-
visit_args(v, args: CallArgs) {
for arg in r!(args.items) {
v.visit_arg(arg);
@@ -212,6 +205,23 @@ impl_visitors! {
}
}
+ visit_closure(v, closure: ClosureExpr) {
+ for param in r!(closure.params) {
+ v.visit_param(param);
+ }
+ v.visit_expr(r!(rc: closure.body));
+ }
+
+ visit_param(v, param: ClosureParam) {
+ match param {
+ ClosureParam::Pos(binding) => v.visit_binding(binding),
+ ClosureParam::Named(named) => {
+ v.visit_binding(r!(named.name));
+ v.visit_expr(r!(named.expr));
+ }
+ }
+ }
+
visit_with(v, with_expr: WithExpr) {
v.visit_expr(r!(with_expr.callee));
v.visit_args(r!(with_expr.args));