diff options
author | Laurențiu Nicola <[email protected]> | 2020-12-18 15:47:48 +0000 |
---|---|---|
committer | Laurențiu Nicola <[email protected]> | 2020-12-20 06:06:17 +0000 |
commit | 75a26f64ff8aa4fcacd849b2b3cde8f688baa789 (patch) | |
tree | 8ecd068bb0d8764833f1b9f018fa36726761089a /crates/mbe/src | |
parent | f4929fa9ccd0eda65c2b77fef163c31e33bfb89a (diff) |
mbe: treat _ as ident
Diffstat (limited to 'crates/mbe/src')
-rw-r--r-- | crates/mbe/src/mbe_expander/transcriber.rs | 2 | ||||
-rw-r--r-- | crates/mbe/src/parser.rs | 4 | ||||
-rw-r--r-- | crates/mbe/src/syntax_bridge.rs | 3 | ||||
-rw-r--r-- | crates/mbe/src/tests.rs | 12 |
4 files changed, 18 insertions, 3 deletions
diff --git a/crates/mbe/src/mbe_expander/transcriber.rs b/crates/mbe/src/mbe_expander/transcriber.rs index 616119ba9..57592dc92 100644 --- a/crates/mbe/src/mbe_expander/transcriber.rs +++ b/crates/mbe/src/mbe_expander/transcriber.rs | |||
@@ -97,7 +97,7 @@ fn expand_subtree( | |||
97 | err = err.or(e); | 97 | err = err.or(e); |
98 | arena.push(tt.into()); | 98 | arena.push(tt.into()); |
99 | } | 99 | } |
100 | Op::Var { name, kind: _ } => { | 100 | Op::Var { name, .. } => { |
101 | let ExpandResult { value: fragment, err: e } = expand_var(ctx, name); | 101 | let ExpandResult { value: fragment, err: e } = expand_var(ctx, name); |
102 | err = err.or(e); | 102 | err = err.or(e); |
103 | push_fragment(arena, fragment); | 103 | push_fragment(arena, fragment); |
diff --git a/crates/mbe/src/parser.rs b/crates/mbe/src/parser.rs index 6b46a1673..c3fdd4040 100644 --- a/crates/mbe/src/parser.rs +++ b/crates/mbe/src/parser.rs | |||
@@ -101,7 +101,9 @@ fn next_op<'a>( | |||
101 | Op::Repeat { subtree, separator, kind } | 101 | Op::Repeat { subtree, separator, kind } |
102 | } | 102 | } |
103 | tt::TokenTree::Leaf(leaf) => match leaf { | 103 | tt::TokenTree::Leaf(leaf) => match leaf { |
104 | tt::Leaf::Punct(..) => return Err(ExpandError::UnexpectedToken), | 104 | tt::Leaf::Punct(_) => { |
105 | return Err(ExpandError::UnexpectedToken); | ||
106 | } | ||
105 | tt::Leaf::Ident(ident) => { | 107 | tt::Leaf::Ident(ident) => { |
106 | let name = &ident.text; | 108 | let name = &ident.text; |
107 | let kind = eat_fragment_kind(src, mode)?; | 109 | let kind = eat_fragment_kind(src, mode)?; |
diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs index 265c0d63d..2bec7fd49 100644 --- a/crates/mbe/src/syntax_bridge.rs +++ b/crates/mbe/src/syntax_bridge.rs | |||
@@ -313,7 +313,7 @@ trait TokenConvertor { | |||
313 | return; | 313 | return; |
314 | } | 314 | } |
315 | 315 | ||
316 | result.push(if k.is_punct() { | 316 | result.push(if k.is_punct() && k != UNDERSCORE { |
317 | assert_eq!(range.len(), TextSize::of('.')); | 317 | assert_eq!(range.len(), TextSize::of('.')); |
318 | let delim = match k { | 318 | let delim = match k { |
319 | T!['('] => Some((tt::DelimiterKind::Parenthesis, T![')'])), | 319 | T!['('] => Some((tt::DelimiterKind::Parenthesis, T![')'])), |
@@ -378,6 +378,7 @@ trait TokenConvertor { | |||
378 | let leaf: tt::Leaf = match k { | 378 | let leaf: tt::Leaf = match k { |
379 | T![true] | T![false] => make_leaf!(Ident), | 379 | T![true] | T![false] => make_leaf!(Ident), |
380 | IDENT => make_leaf!(Ident), | 380 | IDENT => make_leaf!(Ident), |
381 | UNDERSCORE => make_leaf!(Ident), | ||
381 | k if k.is_keyword() => make_leaf!(Ident), | 382 | k if k.is_keyword() => make_leaf!(Ident), |
382 | k if k.is_literal() => make_leaf!(Literal), | 383 | k if k.is_literal() => make_leaf!(Literal), |
383 | LIFETIME_IDENT => { | 384 | LIFETIME_IDENT => { |
diff --git a/crates/mbe/src/tests.rs b/crates/mbe/src/tests.rs index dff6e98c2..f10e7a9b6 100644 --- a/crates/mbe/src/tests.rs +++ b/crates/mbe/src/tests.rs | |||
@@ -992,6 +992,18 @@ fn test_tt_composite2() { | |||
992 | } | 992 | } |
993 | 993 | ||
994 | #[test] | 994 | #[test] |
995 | fn test_underscore() { | ||
996 | parse_macro( | ||
997 | r#" | ||
998 | macro_rules! foo { | ||
999 | ($_:tt) => { 0 } | ||
1000 | } | ||
1001 | "#, | ||
1002 | ) | ||
1003 | .assert_expand_items(r#"foo! { => }"#, r#"0"#); | ||
1004 | } | ||
1005 | |||
1006 | #[test] | ||
995 | fn test_lifetime() { | 1007 | fn test_lifetime() { |
996 | parse_macro( | 1008 | parse_macro( |
997 | r#" | 1009 | r#" |