aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/macros.rs45
-rw-r--r--crates/ra_hir/src/macros/mbe.rs9
2 files changed, 31 insertions, 23 deletions
diff --git a/crates/ra_hir/src/macros.rs b/crates/ra_hir/src/macros.rs
index 4740e5337..0497d2168 100644
--- a/crates/ra_hir/src/macros.rs
+++ b/crates/ra_hir/src/macros.rs
@@ -221,27 +221,32 @@ fn convert_tt(tt: &SyntaxNode) -> Option<tt::Subtree> {
221 if child == first_child || child == last_child || child.kind().is_trivia() { 221 if child == first_child || child == last_child || child.kind().is_trivia() {
222 continue; 222 continue;
223 } 223 }
224 let child: tt::TokenTree = if child.kind() == TOKEN_TREE { 224 if child.kind().is_punct() {
225 convert_tt(child)?.into() 225 let leaves = child
226 } else if child.kind().is_keyword() || child.kind() == IDENT { 226 .leaf_text()
227 let text = child.leaf_text().unwrap().clone(); 227 .unwrap()
228 tt::Leaf::from(tt::Ident { text }).into() 228 .chars()
229 } else if child.kind().is_punct() { 229 .map(|char| tt::Punct { char })
230 // FIXME: multibyte tokens 230 .map(tt::Leaf::from)
231 tt::Leaf::from(tt::Punct { 231 .map(tt::TokenTree::from);
232 char: child.text().char_at(0)?, 232 token_trees.extend(leaves);
233 })
234 .into()
235 } else if child.kind().is_literal() {
236 tt::Leaf::from(tt::Literal {
237 text: child.leaf_text().unwrap().clone(),
238 })
239 .into()
240 } else { 233 } else {
241 log::error!("unknown kind: {:?}", child); 234 let child: tt::TokenTree = if child.kind() == TOKEN_TREE {
242 return None; 235 convert_tt(child)?.into()
243 }; 236 } else if child.kind().is_keyword() || child.kind() == IDENT {
244 token_trees.push(child) 237 let text = child.leaf_text().unwrap().clone();
238 tt::Leaf::from(tt::Ident { text }).into()
239 } else if child.kind().is_literal() {
240 tt::Leaf::from(tt::Literal {
241 text: child.leaf_text().unwrap().clone(),
242 })
243 .into()
244 } else {
245 log::error!("unknown kind: {:?}", child);
246 return None;
247 };
248 token_trees.push(child)
249 }
245 } 250 }
246 251
247 let res = tt::Subtree { 252 let res = tt::Subtree {
diff --git a/crates/ra_hir/src/macros/mbe.rs b/crates/ra_hir/src/macros/mbe.rs
index 3d6dcefa8..62b7fa24c 100644
--- a/crates/ra_hir/src/macros/mbe.rs
+++ b/crates/ra_hir/src/macros/mbe.rs
@@ -86,14 +86,17 @@ pub(crate) fn parse(tt: &tt::Subtree) -> Option<MacroRules> {
86 86
87fn parse_rule(p: &mut RulesParser) -> Option<Rule> { 87fn parse_rule(p: &mut RulesParser) -> Option<Rule> {
88 let lhs = parse_subtree(p.eat_subtree()?)?; 88 let lhs = parse_subtree(p.eat_subtree()?)?;
89 p.eat_punct('='); 89 p.eat_punct('=')?;
90 p.eat_punct('>'); 90 p.eat_punct('>')?;
91 let rhs = parse_subtree(p.eat_subtree()?)?; 91 let rhs = parse_subtree(p.eat_subtree()?)?;
92 Some(Rule { lhs, rhs }) 92 Some(Rule { lhs, rhs })
93} 93}
94 94
95fn parse_subtree(tt: &tt::Subtree) -> Option<Subtree> { 95fn parse_subtree(tt: &tt::Subtree) -> Option<Subtree> {
96 None 96 Some(Subtree {
97 token_trees: Vec::new(),
98 delimiter: Delimiter::None,
99 })
97} 100}
98 101
99struct RulesParser<'a> { 102struct RulesParser<'a> {