diff options
Diffstat (limited to 'crates/ra_mbe/src')
-rw-r--r-- | crates/ra_mbe/src/lib.rs | 12 | ||||
-rw-r--r-- | crates/ra_mbe/src/mbe_expander.rs | 5 | ||||
-rw-r--r-- | crates/ra_mbe/src/subtree_parser.rs | 4 | ||||
-rw-r--r-- | crates/ra_mbe/src/tt_cursor.rs | 5 |
4 files changed, 26 insertions, 0 deletions
diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index 9d4744838..8e3167e55 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs | |||
@@ -731,4 +731,16 @@ MACRO_ITEMS@[0; 40) | |||
731 | } | 731 | } |
732 | "#, r#"extern crate a ; mod b ; mod c {} use d ; const E : i32 = 0 ; static F : i32 = 0 ; impl G {} struct H ; enum I {Foo} trait J {} fn h () {} extern {} type T = u8 ;"#); | 732 | "#, r#"extern crate a ; mod b ; mod c {} use d ; const E : i32 = 0 ; static F : i32 = 0 ; impl G {} struct H ; enum I {Foo} trait J {} fn h () {} extern {} type T = u8 ;"#); |
733 | } | 733 | } |
734 | |||
735 | #[test] | ||
736 | fn test_block() { | ||
737 | let rules = create_rules( | ||
738 | r#" | ||
739 | macro_rules! foo { | ||
740 | ($ i:block) => { fn foo() $ i } | ||
741 | } | ||
742 | "#, | ||
743 | ); | ||
744 | assert_expansion(&rules, "foo! { { 1; } }", "fn foo () {1 ;}"); | ||
745 | } | ||
734 | } | 746 | } |
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index acba42809..a74e477d6 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs | |||
@@ -161,6 +161,11 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings, | |||
161 | let pat = input.eat_stmt().ok_or(ExpandError::UnexpectedToken)?.clone(); | 161 | let pat = input.eat_stmt().ok_or(ExpandError::UnexpectedToken)?.clone(); |
162 | res.inner.insert(text.clone(), Binding::Simple(pat.into())); | 162 | res.inner.insert(text.clone(), Binding::Simple(pat.into())); |
163 | } | 163 | } |
164 | "block" => { | ||
165 | let block = | ||
166 | input.eat_block().ok_or(ExpandError::UnexpectedToken)?.clone(); | ||
167 | res.inner.insert(text.clone(), Binding::Simple(block.into())); | ||
168 | } | ||
164 | "item" => { | 169 | "item" => { |
165 | let item = | 170 | let item = |
166 | input.eat_item().ok_or(ExpandError::UnexpectedToken)?.clone(); | 171 | input.eat_item().ok_or(ExpandError::UnexpectedToken)?.clone(); |
diff --git a/crates/ra_mbe/src/subtree_parser.rs b/crates/ra_mbe/src/subtree_parser.rs index 195e4c3ac..2b11186c4 100644 --- a/crates/ra_mbe/src/subtree_parser.rs +++ b/crates/ra_mbe/src/subtree_parser.rs | |||
@@ -46,6 +46,10 @@ impl<'a> Parser<'a> { | |||
46 | self.parse(|src, sink| ra_parser::parse_stmt(src, sink, false)) | 46 | self.parse(|src, sink| ra_parser::parse_stmt(src, sink, false)) |
47 | } | 47 | } |
48 | 48 | ||
49 | pub fn parse_block(self) -> Option<tt::TokenTree> { | ||
50 | self.parse(ra_parser::parse_block) | ||
51 | } | ||
52 | |||
49 | pub fn parse_item(self) -> Option<tt::TokenTree> { | 53 | pub fn parse_item(self) -> Option<tt::TokenTree> { |
50 | self.parse(ra_parser::parse_item) | 54 | self.parse(ra_parser::parse_item) |
51 | } | 55 | } |
diff --git a/crates/ra_mbe/src/tt_cursor.rs b/crates/ra_mbe/src/tt_cursor.rs index 484437b0e..d700aad69 100644 --- a/crates/ra_mbe/src/tt_cursor.rs +++ b/crates/ra_mbe/src/tt_cursor.rs | |||
@@ -104,6 +104,11 @@ impl<'a> TtCursor<'a> { | |||
104 | parser.parse_stmt() | 104 | parser.parse_stmt() |
105 | } | 105 | } |
106 | 106 | ||
107 | pub(crate) fn eat_block(&mut self) -> Option<tt::TokenTree> { | ||
108 | let parser = Parser::new(&mut self.pos, self.subtree); | ||
109 | parser.parse_block() | ||
110 | } | ||
111 | |||
107 | pub(crate) fn eat_item(&mut self) -> Option<tt::TokenTree> { | 112 | pub(crate) fn eat_item(&mut self) -> Option<tt::TokenTree> { |
108 | let parser = Parser::new(&mut self.pos, self.subtree); | 113 | let parser = Parser::new(&mut self.pos, self.subtree); |
109 | parser.parse_item() | 114 | parser.parse_item() |