aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_mbe/src')
-rw-r--r--crates/ra_mbe/src/lib.rs22
-rw-r--r--crates/ra_mbe/src/mbe_expander.rs5
-rw-r--r--crates/ra_mbe/src/tt_cursor.rs4
3 files changed, 31 insertions, 0 deletions
diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs
index 4203929d4..a5b7fab52 100644
--- a/crates/ra_mbe/src/lib.rs
+++ b/crates/ra_mbe/src/lib.rs
@@ -379,4 +379,26 @@ SOURCE_FILE@[0; 40)
379 // [let] [s] [=] ["rust1"] [;] 379 // [let] [s] [=] ["rust1"] [;]
380 assert_eq!(to_literal(&stm_tokens[15 + 3]).text, "\"rust1\""); 380 assert_eq!(to_literal(&stm_tokens[15 + 3]).text, "\"rust1\"");
381 } 381 }
382
383 /// The following tests are port from intellij-rust directly
384 /// https://github.com/intellij-rust/intellij-rust/blob/c4e9feee4ad46e7953b1948c112533360b6087bb/src/test/kotlin/org/rust/lang/core/macros/RsMacroExpansionTest.kt
385
386 #[test]
387 fn test_path() {
388 let rules = create_rules(
389 r#"
390 macro_rules! foo {
391 ($ i:path) => {
392 fn foo() { let a = $ i; }
393 }
394 }
395"#,
396 );
397 assert_expansion(&rules, "foo! { foo }", "fn foo () {let a = foo ;}");
398 assert_expansion(
399 &rules,
400 "foo! { bar::<u8>::baz::<u8> }",
401 "fn foo () {let a = bar :: < u8 > :: baz :: < u8 > ;}",
402 );
403 }
382} 404}
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs
index 2dafd68f6..ce41d7225 100644
--- a/crates/ra_mbe/src/mbe_expander.rs
+++ b/crates/ra_mbe/src/mbe_expander.rs
@@ -139,6 +139,11 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings,
139 Binding::Simple(tt::Leaf::from(ident).into()), 139 Binding::Simple(tt::Leaf::from(ident).into()),
140 ); 140 );
141 } 141 }
142 "path" => {
143 let path =
144 input.eat_path().ok_or(ExpandError::UnexpectedToken)?.clone();
145 res.inner.insert(text.clone(), Binding::Simple(path.into()));
146 }
142 _ => return Err(ExpandError::UnexpectedToken), 147 _ => return Err(ExpandError::UnexpectedToken),
143 } 148 }
144 } 149 }
diff --git a/crates/ra_mbe/src/tt_cursor.rs b/crates/ra_mbe/src/tt_cursor.rs
index 3128cb9ae..6f619621a 100644
--- a/crates/ra_mbe/src/tt_cursor.rs
+++ b/crates/ra_mbe/src/tt_cursor.rs
@@ -78,6 +78,10 @@ impl<'a> TtCursor<'a> {
78 }) 78 })
79 } 79 }
80 80
81 pub(crate) fn eat_path(&mut self) -> Option<tt::Subtree> {
82 None
83 }
84
81 pub(crate) fn expect_char(&mut self, char: char) -> Result<(), ParseError> { 85 pub(crate) fn expect_char(&mut self, char: char) -> Result<(), ParseError> {
82 if self.at_char(char) { 86 if self.at_char(char) {
83 self.bump(); 87 self.bump();