diff options
author | Edwin Cheng <[email protected]> | 2020-03-03 17:03:44 +0000 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2020-03-03 17:03:44 +0000 |
commit | 3dc3d9d18fba0396afa73644865c687b2e64815e (patch) | |
tree | 055def4439847b0a5d20fe2daaeca35603f62bb7 /crates | |
parent | b55d22e06095821eaf588786663d3b2b946e8549 (diff) |
Fix a bug for single dollar sign macro
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_expand/src/db.rs | 15 | ||||
-rw-r--r-- | crates/ra_mbe/src/parser.rs | 6 | ||||
-rw-r--r-- | crates/ra_mbe/src/tests.rs | 1 |
3 files changed, 16 insertions, 6 deletions
diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs index af5b22d1c..70d969238 100644 --- a/crates/ra_hir_expand/src/db.rs +++ b/crates/ra_hir_expand/src/db.rs | |||
@@ -86,10 +86,13 @@ pub(crate) fn macro_def( | |||
86 | log::warn!("fail on macro_def to token tree: {:#?}", arg); | 86 | log::warn!("fail on macro_def to token tree: {:#?}", arg); |
87 | None | 87 | None |
88 | })?; | 88 | })?; |
89 | let rules = MacroRules::parse(&tt).ok().or_else(|| { | 89 | let rules = match MacroRules::parse(&tt) { |
90 | log::warn!("fail on macro_def parse: {:#?}", tt); | 90 | Ok(it) => it, |
91 | None | 91 | Err(err) => { |
92 | })?; | 92 | log::warn!("fail on macro_def parse: error: {:#?} {:#?}", err, tt); |
93 | return None; | ||
94 | } | ||
95 | }; | ||
93 | Some(Arc::new((TokenExpander::MacroRules(rules), tmap))) | 96 | Some(Arc::new((TokenExpander::MacroRules(rules), tmap))) |
94 | } | 97 | } |
95 | MacroDefKind::BuiltIn(expander) => { | 98 | MacroDefKind::BuiltIn(expander) => { |
@@ -150,7 +153,9 @@ pub(crate) fn parse_macro( | |||
150 | // Note: | 153 | // Note: |
151 | // The final goal we would like to make all parse_macro success, | 154 | // The final goal we would like to make all parse_macro success, |
152 | // such that the following log will not call anyway. | 155 | // such that the following log will not call anyway. |
153 | log::warn!("fail on macro_parse: (reason: {})", err,); | 156 | let loc: MacroCallLoc = db.lookup_intern_macro(macro_call_id); |
157 | let node = loc.kind.node(db); | ||
158 | log::warn!("fail on macro_parse: (reason: {} macro_call: {:#})", err, node.value); | ||
154 | }) | 159 | }) |
155 | .ok()?; | 160 | .ok()?; |
156 | 161 | ||
diff --git a/crates/ra_mbe/src/parser.rs b/crates/ra_mbe/src/parser.rs index 10a6f300a..034150432 100644 --- a/crates/ra_mbe/src/parser.rs +++ b/crates/ra_mbe/src/parser.rs | |||
@@ -90,7 +90,11 @@ fn next_op<'a>( | |||
90 | ) -> Result<Op<'a>, ExpandError> { | 90 | ) -> Result<Op<'a>, ExpandError> { |
91 | let res = match first { | 91 | let res = match first { |
92 | tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: '$', .. })) => { | 92 | tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: '$', .. })) => { |
93 | let second = src.next().ok_or_else(|| err!("bad var 1"))?; | 93 | // Note that the '$' itself is a valid token inside macro_rules. |
94 | let second = match src.next() { | ||
95 | None => return Ok(Op::TokenTree(first)), | ||
96 | Some(it) => it, | ||
97 | }; | ||
94 | match second { | 98 | match second { |
95 | tt::TokenTree::Subtree(subtree) => { | 99 | tt::TokenTree::Subtree(subtree) => { |
96 | let (separator, kind) = parse_repeat(src)?; | 100 | let (separator, kind) = parse_repeat(src)?; |
diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs index cb228702f..1dba82915 100644 --- a/crates/ra_mbe/src/tests.rs +++ b/crates/ra_mbe/src/tests.rs | |||
@@ -23,6 +23,7 @@ mod rule_parsing { | |||
23 | check("($($i:ident)*) => ($_)"); | 23 | check("($($i:ident)*) => ($_)"); |
24 | check("($($true:ident)*) => ($true)"); | 24 | check("($($true:ident)*) => ($true)"); |
25 | check("($($false:ident)*) => ($false)"); | 25 | check("($($false:ident)*) => ($false)"); |
26 | check("($) => ($)"); | ||
26 | } | 27 | } |
27 | 28 | ||
28 | #[test] | 29 | #[test] |