From 8092b6487f301bf9219c55fc714744fa2616fb9a Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 19 Apr 2019 18:30:43 +0800 Subject: Add block matcher --- crates/ra_mbe/src/lib.rs | 12 ++++++++++++ crates/ra_mbe/src/mbe_expander.rs | 5 +++++ crates/ra_mbe/src/subtree_parser.rs | 4 ++++ crates/ra_mbe/src/tt_cursor.rs | 5 +++++ crates/ra_parser/src/grammar.rs | 4 ++++ crates/ra_parser/src/lib.rs | 5 +++++ 6 files changed, 35 insertions(+) (limited to 'crates') 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) } "#, 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 ;"#); } + + #[test] + fn test_block() { + let rules = create_rules( + r#" + macro_rules! foo { + ($ i:block) => { fn foo() $ i } + } +"#, + ); + assert_expansion(&rules, "foo! { { 1; } }", "fn foo () {1 ;}"); + } } 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 { + let block = + input.eat_block().ok_or(ExpandError::UnexpectedToken)?.clone(); + res.inner.insert(text.clone(), Binding::Simple(block.into())); + } "item" => { let item = 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> { self.parse(|src, sink| ra_parser::parse_stmt(src, sink, false)) } + pub fn parse_block(self) -> Option { + self.parse(ra_parser::parse_block) + } + pub fn parse_item(self) -> Option { self.parse(ra_parser::parse_item) } 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> { parser.parse_stmt() } + pub(crate) fn eat_block(&mut self) -> Option { + let parser = Parser::new(&mut self.pos, self.subtree); + parser.parse_block() + } + pub(crate) fn eat_item(&mut self) -> Option { let parser = Parser::new(&mut self.pos, self.subtree); parser.parse_item() diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index e1762633e..7bae0bc7b 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -95,6 +95,10 @@ pub(crate) fn stmt(p: &mut Parser, with_semi: bool) { expressions::stmt(p, with_semi) } +pub(crate) fn block(p: &mut Parser) { + expressions::block(p); +} + pub(crate) fn item(p: &mut Parser) { items::item_or_macro(p, true, items::ItemFlavor::Mod) } diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs index 0ea942b6e..1e6a00642 100644 --- a/crates/ra_parser/src/lib.rs +++ b/crates/ra_parser/src/lib.rs @@ -93,6 +93,11 @@ pub fn parse_stmt(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink, parse_from_tokens(token_source, tree_sink, |p| grammar::stmt(p, with_semi)); } +/// Parse given tokens into the given sink as a block +pub fn parse_block(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) { + parse_from_tokens(token_source, tree_sink, grammar::block); +} + /// Parse given tokens into the given sink as an item pub fn parse_item(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) { parse_from_tokens(token_source, tree_sink, grammar::item); -- cgit v1.2.3 From 762819864fd78f2e8904a6bde6181b80895db360 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 19 Apr 2019 19:33:29 +0800 Subject: add block matcher --- crates/ra_mbe/src/lib.rs | 19 +++++++++++++++++++ crates/ra_mbe/src/mbe_expander.rs | 5 +++++ crates/ra_mbe/src/subtree_parser.rs | 4 ++++ crates/ra_mbe/src/tt_cursor.rs | 5 +++++ crates/ra_parser/src/grammar.rs | 27 +++++++++++++++++++++++++++ crates/ra_parser/src/lib.rs | 4 ++++ 6 files changed, 64 insertions(+) (limited to 'crates') diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index 8e3167e55..d7462d09d 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs @@ -743,4 +743,23 @@ MACRO_ITEMS@[0; 40) ); assert_expansion(&rules, "foo! { { 1; } }", "fn foo () {1 ;}"); } + + #[test] + fn test_meta() { + let rules = create_rules( + r#" + macro_rules! foo { + ($ i:meta) => ( + #[$ i] + fn bar() {} + ) + } +"#, + ); + assert_expansion( + &rules, + r#"foo! { cfg(target_os = "windows") }"#, + r#"# [cfg (target_os = "windows")] fn bar () {}"#, + ); + } } diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index a74e477d6..6ada580cc 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs @@ -166,6 +166,11 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result { + let meta = + input.eat_meta().ok_or(ExpandError::UnexpectedToken)?.clone(); + res.inner.insert(text.clone(), Binding::Simple(meta.into())); + } "item" => { let item = 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 2b11186c4..5d5557113 100644 --- a/crates/ra_mbe/src/subtree_parser.rs +++ b/crates/ra_mbe/src/subtree_parser.rs @@ -50,6 +50,10 @@ impl<'a> Parser<'a> { self.parse(ra_parser::parse_block) } + pub fn parse_meta(self) -> Option { + self.parse(ra_parser::parse_meta) + } + pub fn parse_item(self) -> Option { self.parse(ra_parser::parse_item) } diff --git a/crates/ra_mbe/src/tt_cursor.rs b/crates/ra_mbe/src/tt_cursor.rs index d700aad69..04bb6b563 100644 --- a/crates/ra_mbe/src/tt_cursor.rs +++ b/crates/ra_mbe/src/tt_cursor.rs @@ -109,6 +109,11 @@ impl<'a> TtCursor<'a> { parser.parse_block() } + pub(crate) fn eat_meta(&mut self) -> Option { + let parser = Parser::new(&mut self.pos, self.subtree); + parser.parse_meta() + } + pub(crate) fn eat_item(&mut self) -> Option { let parser = Parser::new(&mut self.pos, self.subtree); parser.parse_item() diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index 7bae0bc7b..13c50c79c 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -99,6 +99,33 @@ pub(crate) fn block(p: &mut Parser) { expressions::block(p); } +// Parse a meta item , which excluded [], e.g : #[ MetaItem ] +pub(crate) fn meta_item(p: &mut Parser) { + fn is_delimiter(p: &mut Parser) -> bool { + match p.current() { + L_CURLY | L_PAREN | L_BRACK => true, + _ => false, + } + } + + if is_delimiter(p) { + items::token_tree(p); + return; + } + + let m = p.start(); + while !p.at(EOF) { + if is_delimiter(p) { + items::token_tree(p); + break; + } else { + p.bump(); + } + } + + m.complete(p, TOKEN_TREE); +} + pub(crate) fn item(p: &mut Parser) { items::item_or_macro(p, true, items::ItemFlavor::Mod) } diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs index 1e6a00642..4787b5b9e 100644 --- a/crates/ra_parser/src/lib.rs +++ b/crates/ra_parser/src/lib.rs @@ -98,6 +98,10 @@ pub fn parse_block(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) parse_from_tokens(token_source, tree_sink, grammar::block); } +pub fn parse_meta(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) { + parse_from_tokens(token_source, tree_sink, grammar::meta_item); +} + /// Parse given tokens into the given sink as an item pub fn parse_item(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) { parse_from_tokens(token_source, tree_sink, grammar::item); -- cgit v1.2.3 From 59b6cc780b4be6b3706099410ac56f348df46b71 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 19 Apr 2019 19:41:59 +0800 Subject: add tt matcher --- crates/ra_mbe/src/lib.rs | 24 ++++++++++++++++++++++++ crates/ra_mbe/src/mbe_expander.rs | 4 ++++ 2 files changed, 28 insertions(+) (limited to 'crates') diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index d7462d09d..ae8a62036 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs @@ -762,4 +762,28 @@ MACRO_ITEMS@[0; 40) r#"# [cfg (target_os = "windows")] fn bar () {}"#, ); } + + #[test] + fn test_tt_block() { + let rules = create_rules( + r#" + macro_rules! foo { + ($ i:tt) => { fn foo() $ i } + } +"#, + ); + assert_expansion(&rules, r#"foo! { { 1; } }"#, r#"fn foo () {1 ;}"#); + } + + #[test] + fn test_tt_group() { + let rules = create_rules( + r#" + macro_rules! foo { + ($($ i:tt)*) => { $($ i)* } + } +"#, + ); + assert_expansion(&rules, r#"foo! { fn foo() {} }"#, r#"fn foo () {}"#); + } } diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index 6ada580cc..4261dee8d 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs @@ -171,6 +171,10 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result { + let token = input.eat().ok_or(ExpandError::UnexpectedToken)?.clone(); + res.inner.insert(text.clone(), Binding::Simple(token.into())); + } "item" => { let item = input.eat_item().ok_or(ExpandError::UnexpectedToken)?.clone(); -- cgit v1.2.3 From 313854c728c45ce236f23ff7a8834690e06d8306 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 19 Apr 2019 21:15:19 +0800 Subject: Add lifetime matcher --- crates/ra_mbe/src/lib.rs | 13 ++++++++++++- crates/ra_mbe/src/mbe_expander.rs | 5 +++++ crates/ra_mbe/src/syntax_bridge.rs | 5 ++++- crates/ra_mbe/src/tt_cursor.rs | 4 ++++ 4 files changed, 25 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index ae8a62036..a143eaa36 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs @@ -209,7 +209,6 @@ impl_froms!(TokenTree: Leaf, Subtree); pub(crate) fn assert_expansion(rules: &MacroRules, invocation: &str, expansion: &str) { let expanded = expand(rules, invocation); - assert_eq!(expanded.to_string(), expansion); let tree = token_tree_to_macro_items(&expanded); @@ -786,4 +785,16 @@ MACRO_ITEMS@[0; 40) ); assert_expansion(&rules, r#"foo! { fn foo() {} }"#, r#"fn foo () {}"#); } + + #[test] + fn test_lifetime() { + let rules = create_rules( + r#" + macro_rules! foo { + ($ lt:lifetime) => { struct Ref<$ lt>{ s: &$ lt str } } + } +"#, + ); + assert_expansion(&rules, r#"foo!{'a}"#, r#"struct Ref < 'a > {s : & 'a str}"#); + } } diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index 4261dee8d..cacc3da19 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs @@ -180,6 +180,11 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result { + let lifetime = + input.eat_lifetime().ok_or(ExpandError::UnexpectedToken)?.clone(); + res.inner.insert(text.clone(), Binding::Simple(lifetime.into())); + } _ => return Err(ExpandError::UnexpectedToken), } } diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 5844d3f12..38a481029 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs @@ -157,7 +157,10 @@ fn convert_tt( ); } } else { - let child = if token.kind().is_keyword() || token.kind() == IDENT { + let child: tt::TokenTree = if token.kind().is_keyword() + || token.kind() == IDENT + || token.kind() == LIFETIME + { let relative_range = token.range() - global_offset; let id = token_map.alloc(relative_range); let text = token.text().clone(); diff --git a/crates/ra_mbe/src/tt_cursor.rs b/crates/ra_mbe/src/tt_cursor.rs index 04bb6b563..9c49648fa 100644 --- a/crates/ra_mbe/src/tt_cursor.rs +++ b/crates/ra_mbe/src/tt_cursor.rs @@ -119,6 +119,10 @@ impl<'a> TtCursor<'a> { parser.parse_item() } + pub(crate) fn eat_lifetime(&mut self) -> Option { + self.eat_ident().cloned().map(|ident| tt::Leaf::from(ident).into()) + } + pub(crate) fn expect_char(&mut self, char: char) -> Result<(), ParseError> { if self.at_char(char) { self.bump(); -- cgit v1.2.3 From c5983b85fc9e520208684a8c625cdb96bb219b31 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 19 Apr 2019 21:21:47 +0800 Subject: Add literal matcher --- crates/ra_mbe/src/lib.rs | 12 ++++++++++++ crates/ra_mbe/src/mbe_expander.rs | 9 +++++++++ crates/ra_mbe/src/tt_cursor.rs | 14 ++++++++++++++ 3 files changed, 35 insertions(+) (limited to 'crates') diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index a143eaa36..b9dd22dc9 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs @@ -797,4 +797,16 @@ MACRO_ITEMS@[0; 40) ); assert_expansion(&rules, r#"foo!{'a}"#, r#"struct Ref < 'a > {s : & 'a str}"#); } + + #[test] + fn test_literal() { + let rules = create_rules( + r#" + macro_rules! foo { + ($ type:ty $ lit:literal) => { const VALUE: $ type = $ lit;}; + } +"#, + ); + assert_expansion(&rules, r#"foo!(u8 0)"#, r#"const VALUE: u8 = 0;"#); + } } diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index cacc3da19..548b15535 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs @@ -185,6 +185,15 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result { + let literal = + input.eat_literal().ok_or(ExpandError::UnexpectedToken)?.clone(); + res.inner.insert( + text.clone(), + Binding::Simple(tt::Leaf::from(literal).into()), + ); + } + _ => return Err(ExpandError::UnexpectedToken), } } diff --git a/crates/ra_mbe/src/tt_cursor.rs b/crates/ra_mbe/src/tt_cursor.rs index 9c49648fa..6184fb31f 100644 --- a/crates/ra_mbe/src/tt_cursor.rs +++ b/crates/ra_mbe/src/tt_cursor.rs @@ -41,6 +41,13 @@ impl<'a> TtCursor<'a> { } } + pub(crate) fn at_literal(&mut self) -> Option<&'a tt::Literal> { + match self.current() { + Some(tt::TokenTree::Leaf(tt::Leaf::Literal(i))) => Some(i), + _ => None, + } + } + pub(crate) fn bump(&mut self) { self.pos += 1; } @@ -79,6 +86,13 @@ impl<'a> TtCursor<'a> { }) } + pub(crate) fn eat_literal(&mut self) -> Option<&'a tt::Literal> { + self.at_literal().map(|i| { + self.bump(); + i + }) + } + pub(crate) fn eat_path(&mut self) -> Option { let parser = Parser::new(&mut self.pos, self.subtree); parser.parse_path() -- cgit v1.2.3 From 87ff908135a28115593f8cf895d176aef331347c Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 19 Apr 2019 21:38:26 +0800 Subject: Add vis matcher --- crates/ra_mbe/src/lib.rs | 12 ++++++++++++ crates/ra_mbe/src/mbe_expander.rs | 4 ++++ crates/ra_mbe/src/subtree_parser.rs | 4 ++++ crates/ra_mbe/src/tt_cursor.rs | 5 +++++ crates/ra_parser/src/grammar.rs | 2 +- crates/ra_parser/src/lib.rs | 7 +++++++ 6 files changed, 33 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index b9dd22dc9..074be9043 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs @@ -809,4 +809,16 @@ MACRO_ITEMS@[0; 40) ); assert_expansion(&rules, r#"foo!(u8 0)"#, r#"const VALUE: u8 = 0;"#); } + + #[test] + fn test_vis() { + let rules = create_rules( + r#" + macro_rules! foo { + ($ vis:vis $ name:ident) => { $ vis fn $ name() {}}; + } +"#, + ); + assert_expansion(&rules, r#"foo!(pub foo);"#, r#"pub fn foo() {}"#); + } } diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index 548b15535..01e29b556 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs @@ -193,6 +193,10 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result { + let vis = input.eat_vis().ok_or(ExpandError::UnexpectedToken)?.clone(); + res.inner.insert(text.clone(), Binding::Simple(vis.into())); + } _ => return Err(ExpandError::UnexpectedToken), } diff --git a/crates/ra_mbe/src/subtree_parser.rs b/crates/ra_mbe/src/subtree_parser.rs index 5d5557113..528aa0f8a 100644 --- a/crates/ra_mbe/src/subtree_parser.rs +++ b/crates/ra_mbe/src/subtree_parser.rs @@ -58,6 +58,10 @@ impl<'a> Parser<'a> { self.parse(ra_parser::parse_item) } + pub fn parse_vis(self) -> Option { + self.parse(ra_parser::parse_vis) + } + fn parse(self, f: F) -> Option where F: FnOnce(&dyn TokenSource, &mut dyn TreeSink), diff --git a/crates/ra_mbe/src/tt_cursor.rs b/crates/ra_mbe/src/tt_cursor.rs index 6184fb31f..818c412a0 100644 --- a/crates/ra_mbe/src/tt_cursor.rs +++ b/crates/ra_mbe/src/tt_cursor.rs @@ -137,6 +137,11 @@ impl<'a> TtCursor<'a> { self.eat_ident().cloned().map(|ident| tt::Leaf::from(ident).into()) } + pub(crate) fn eat_vis(&mut self) -> Option { + let parser = Parser::new(&mut self.pos, self.subtree); + parser.parse_vis() + } + pub(crate) fn expect_char(&mut self, char: char) -> Result<(), ParseError> { if self.at_char(char) { self.bump(); diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index 13c50c79c..67eae749d 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -167,7 +167,7 @@ impl BlockLike { } } -fn opt_visibility(p: &mut Parser) -> bool { +pub(crate) fn opt_visibility(p: &mut Parser) -> bool { match p.current() { PUB_KW => { let m = p.start(); diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs index 4787b5b9e..970d699c0 100644 --- a/crates/ra_parser/src/lib.rs +++ b/crates/ra_parser/src/lib.rs @@ -107,6 +107,13 @@ pub fn parse_item(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) parse_from_tokens(token_source, tree_sink, grammar::item); } +/// Parse given tokens into the given sink as an visibility qualifier +pub fn parse_vis(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) { + parse_from_tokens(token_source, tree_sink, |p| { + grammar::opt_visibility(p); + }); +} + pub fn parse_macro_items(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) { parse_from_tokens(token_source, tree_sink, grammar::macro_items); } -- cgit v1.2.3 From 763569017a61f5294750cdd0d4aee02d0bf76166 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 19 Apr 2019 21:43:41 +0800 Subject: Fix bug for ident to lifetime --- crates/ra_mbe/src/tt_cursor.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'crates') diff --git a/crates/ra_mbe/src/tt_cursor.rs b/crates/ra_mbe/src/tt_cursor.rs index 818c412a0..741b5ea1c 100644 --- a/crates/ra_mbe/src/tt_cursor.rs +++ b/crates/ra_mbe/src/tt_cursor.rs @@ -134,6 +134,13 @@ impl<'a> TtCursor<'a> { } pub(crate) fn eat_lifetime(&mut self) -> Option { + // check if it start from "`" + if let Some(ident) = self.at_ident() { + if ident.text.chars().next()? != '\'' { + return None; + } + } + self.eat_ident().cloned().map(|ident| tt::Leaf::from(ident).into()) } -- cgit v1.2.3 From 1afde29adbb6c9094babe117f7972f7157d16cc1 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 19 Apr 2019 21:52:54 +0800 Subject: Add back missing assert --- crates/ra_mbe/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index 074be9043..814586fd6 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs @@ -209,6 +209,7 @@ impl_froms!(TokenTree: Leaf, Subtree); pub(crate) fn assert_expansion(rules: &MacroRules, invocation: &str, expansion: &str) { let expanded = expand(rules, invocation); + assert_eq!(expanded.to_string(), expansion); let tree = token_tree_to_macro_items(&expanded); @@ -807,7 +808,7 @@ MACRO_ITEMS@[0; 40) } "#, ); - assert_expansion(&rules, r#"foo!(u8 0)"#, r#"const VALUE: u8 = 0;"#); + assert_expansion(&rules, r#"foo!(u8 0)"#, r#"const VALUE : u8 = 0 ;"#); } #[test] @@ -819,6 +820,6 @@ MACRO_ITEMS@[0; 40) } "#, ); - assert_expansion(&rules, r#"foo!(pub foo);"#, r#"pub fn foo() {}"#); + assert_expansion(&rules, r#"foo!(pub foo);"#, r#"pub fn foo () {}"#); } } -- cgit v1.2.3