diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/libeditor/src/scope/fn_scope.rs | 41 | ||||
-rw-r--r-- | crates/libsyntax2/src/ast/generated.rs | 26 | ||||
-rw-r--r-- | crates/libsyntax2/src/grammar.ron | 16 |
3 files changed, 63 insertions, 20 deletions
diff --git a/crates/libeditor/src/scope/fn_scope.rs b/crates/libeditor/src/scope/fn_scope.rs index 78e9c061c..42cd71eb5 100644 --- a/crates/libeditor/src/scope/fn_scope.rs +++ b/crates/libeditor/src/scope/fn_scope.rs | |||
@@ -189,7 +189,20 @@ fn compute_expr_scopes(expr: ast::Expr, scopes: &mut FnScopes, scope: ScopeId) { | |||
189 | .chain(e.expr()) | 189 | .chain(e.expr()) |
190 | .for_each(|expr| compute_expr_scopes(expr, scopes, scope)); | 190 | .for_each(|expr| compute_expr_scopes(expr, scopes, scope)); |
191 | } | 191 | } |
192 | 192 | ast::Expr::MatchExpr(e) => { | |
193 | if let Some(expr) = e.expr() { | ||
194 | compute_expr_scopes(expr, scopes, scope); | ||
195 | } | ||
196 | for arm in e.match_arm_list().into_iter().flat_map(|it| it.arms()) { | ||
197 | let scope = scopes.new_scope(scope); | ||
198 | for pat in arm.pats() { | ||
199 | scopes.add_bindings(scope, pat); | ||
200 | } | ||
201 | if let Some(expr) = arm.expr() { | ||
202 | compute_expr_scopes(expr, scopes, scope); | ||
203 | } | ||
204 | } | ||
205 | } | ||
193 | _ => { | 206 | _ => { |
194 | expr.syntax().children() | 207 | expr.syntax().children() |
195 | .filter_map(ast::Expr::cast) | 208 | .filter_map(ast::Expr::cast) |
@@ -279,17 +292,17 @@ mod tests { | |||
279 | ); | 292 | ); |
280 | } | 293 | } |
281 | 294 | ||
282 | // #[test] | 295 | #[test] |
283 | // fn test_match() { | 296 | fn test_match() { |
284 | // do_check(r" | 297 | do_check(r" |
285 | // fn quux() { | 298 | fn quux() { |
286 | // match () { | 299 | match () { |
287 | // Some(x) => { | 300 | Some(x) => { |
288 | // <|> | 301 | <|> |
289 | // } | 302 | } |
290 | // }; | 303 | }; |
291 | // }", | 304 | }", |
292 | // &["x"], | 305 | &["x"], |
293 | // ); | 306 | ); |
294 | // } | 307 | } |
295 | } | 308 | } |
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index f21e49437..bdee635ae 100644 --- a/crates/libsyntax2/src/ast/generated.rs +++ b/crates/libsyntax2/src/ast/generated.rs | |||
@@ -842,7 +842,17 @@ impl<'a> AstNode<'a> for MatchArm<'a> { | |||
842 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 842 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
843 | } | 843 | } |
844 | 844 | ||
845 | impl<'a> MatchArm<'a> {} | 845 | impl<'a> MatchArm<'a> { |
846 | pub fn pats(self) -> impl Iterator<Item = Pat<'a>> + 'a { | ||
847 | super::children(self) | ||
848 | } | ||
849 | pub fn guard(self) -> Option<MatchGuard<'a>> { | ||
850 | super::child_opt(self) | ||
851 | } | ||
852 | pub fn expr(self) -> Option<Expr<'a>> { | ||
853 | super::child_opt(self) | ||
854 | } | ||
855 | } | ||
846 | 856 | ||
847 | // MatchArmList | 857 | // MatchArmList |
848 | #[derive(Debug, Clone, Copy)] | 858 | #[derive(Debug, Clone, Copy)] |
@@ -860,7 +870,11 @@ impl<'a> AstNode<'a> for MatchArmList<'a> { | |||
860 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 870 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
861 | } | 871 | } |
862 | 872 | ||
863 | impl<'a> MatchArmList<'a> {} | 873 | impl<'a> MatchArmList<'a> { |
874 | pub fn arms(self) -> impl Iterator<Item = MatchArm<'a>> + 'a { | ||
875 | super::children(self) | ||
876 | } | ||
877 | } | ||
864 | 878 | ||
865 | // MatchExpr | 879 | // MatchExpr |
866 | #[derive(Debug, Clone, Copy)] | 880 | #[derive(Debug, Clone, Copy)] |
@@ -878,7 +892,13 @@ impl<'a> AstNode<'a> for MatchExpr<'a> { | |||
878 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 892 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
879 | } | 893 | } |
880 | 894 | ||
881 | impl<'a> MatchExpr<'a> {} | 895 | impl<'a> MatchExpr<'a> {pub fn expr(self) -> Option<Expr<'a>> { |
896 | super::child_opt(self) | ||
897 | } | ||
898 | pub fn match_arm_list(self) -> Option<MatchArmList<'a>> { | ||
899 | super::child_opt(self) | ||
900 | } | ||
901 | } | ||
882 | 902 | ||
883 | // MatchGuard | 903 | // MatchGuard |
884 | #[derive(Debug, Clone, Copy)] | 904 | #[derive(Debug, Clone, Copy)] |
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron index fbe8397d8..798725f7e 100644 --- a/crates/libsyntax2/src/grammar.ron +++ b/crates/libsyntax2/src/grammar.ron | |||
@@ -370,9 +370,19 @@ Grammar( | |||
370 | options: [ "Block" ] | 370 | options: [ "Block" ] |
371 | ), | 371 | ), |
372 | "ReturnExpr": (), | 372 | "ReturnExpr": (), |
373 | "MatchExpr": (), | 373 | "MatchExpr": ( |
374 | "MatchArmList": (), | 374 | options: [ "Expr", "MatchArmList" ], |
375 | "MatchArm": (), | 375 | ), |
376 | "MatchArmList": ( | ||
377 | collections: [ ["arms", "MatchArm"] ], | ||
378 | ), | ||
379 | "MatchArm": ( | ||
380 | options: [ | ||
381 | [ "guard", "MatchGuard" ], | ||
382 | "Expr", | ||
383 | ], | ||
384 | collections: [ [ "pats", "Pat" ] ] | ||
385 | ), | ||
376 | "MatchGuard": (), | 386 | "MatchGuard": (), |
377 | "StructLit": (), | 387 | "StructLit": (), |
378 | "NamedFieldList": (), | 388 | "NamedFieldList": (), |