aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-05-20 20:27:05 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-05-20 20:27:05 +0100
commit11742e33716cd9fdce08bf5501afcb793fcc59ac (patch)
tree072112a8cd2061bf1acc31aad9cfa343191d0204 /crates/ra_mbe/src
parentc8f93ff58cf4f63d48d2258e1a4c449e043987f3 (diff)
parentad9d2012ded90a33702efedabf8f8e2c8d992975 (diff)
Merge #1287
1287: Add support of matching literal in mbe r=matklad a=edwin0cheng This PR adds support of matching literal in mbe , which used in our `T` macro : ```rust macro_rules! foo { ('(') => { fn foo() {} } } ``` Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_mbe/src')
-rw-r--r--crates/ra_mbe/src/mbe_expander.rs6
-rw-r--r--crates/ra_mbe/src/tests.rs14
2 files changed, 19 insertions, 1 deletions
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs
index 3a4dbb5f5..7fff8deff 100644
--- a/crates/ra_mbe/src/mbe_expander.rs
+++ b/crates/ra_mbe/src/mbe_expander.rs
@@ -281,7 +281,11 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings,
281 return Err(ExpandError::UnexpectedToken); 281 return Err(ExpandError::UnexpectedToken);
282 } 282 }
283 } 283 }
284 _ => return Err(ExpandError::UnexpectedToken), 284 crate::Leaf::Literal(literal) => {
285 if input.eat_literal().map(|i| &i.text) != Some(&literal.text) {
286 return Err(ExpandError::UnexpectedToken);
287 }
288 }
285 }, 289 },
286 crate::TokenTree::Repeat(crate::Repeat { subtree, kind, separator }) => { 290 crate::TokenTree::Repeat(crate::Repeat { subtree, kind, separator }) => {
287 // Dirty hack to make macro-expansion terminate. 291 // Dirty hack to make macro-expansion terminate.
diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs
index 004faf77e..e3a5ceecf 100644
--- a/crates/ra_mbe/src/tests.rs
+++ b/crates/ra_mbe/src/tests.rs
@@ -575,6 +575,20 @@ fn test_tt_to_stmts() {
575 ); 575 );
576} 576}
577 577
578#[test]
579fn test_match_literal() {
580 let rules = create_rules(
581 r#"
582 macro_rules! foo {
583 ('(') => {
584 fn foo() {}
585 }
586 }
587"#,
588 );
589 assert_expansion(MacroKind::Items, &rules, "foo! ['(']", "fn foo () {}");
590}
591
578// The following tests are port from intellij-rust directly 592// The following tests are port from intellij-rust directly
579// https://github.com/intellij-rust/intellij-rust/blob/c4e9feee4ad46e7953b1948c112533360b6087bb/src/test/kotlin/org/rust/lang/core/macros/RsMacroExpansionTest.kt 593// https://github.com/intellij-rust/intellij-rust/blob/c4e9feee4ad46e7953b1948c112533360b6087bb/src/test/kotlin/org/rust/lang/core/macros/RsMacroExpansionTest.kt
580 594