From d48d5b8b6ca59b462b3a84dad9868daff2eddb6d Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Thu, 17 Jan 2019 13:08:18 +0100 Subject: Add initial (flawed) implementation of binding annotations --- crates/ra_syntax/src/ast.rs | 10 ++++++++++ crates/ra_syntax/src/ast/generated.rs | 6 +++++- crates/ra_syntax/src/grammar.ron | 5 ++++- 3 files changed, 19 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 4b7edbbe7..0ee9ef199 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -713,6 +713,16 @@ impl FieldPatList { } } +impl BindPat { + pub fn is_mutable(&self) -> bool { + self.syntax().children().any(|n| n.kind() == MUT_KW) + } + + pub fn is_ref(&self) -> bool { + self.syntax().children().any(|n| n.kind() == REF_KW) + } +} + #[test] fn test_doc_comment_of_items() { let file = SourceFile::parse( diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 251d53bdf..ead0f1293 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -180,7 +180,11 @@ impl AstNode for BindPat { impl ast::NameOwner for BindPat {} -impl BindPat {} +impl BindPat { + pub fn pat(&self) -> Option<&Pat> { + super::child_opt(self) + } +} // Block #[derive(Debug, PartialEq, Eq, Hash)] diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 33080f664..d58e0dd35 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -488,7 +488,10 @@ Grammar( ), "RefPat": ( options: [ "Pat" ]), - "BindPat": ( traits: ["NameOwner"] ), + "BindPat": ( + options: [ "Pat" ], + traits: ["NameOwner"] + ), "PlaceholderPat": (), "PathPat": ( options: [ "Path" ] ), "StructPat": ( options: ["FieldPatList", "Path"] ), -- cgit v1.2.3