diff options
author | Aleksey Kladov <[email protected]> | 2019-01-31 09:03:16 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-31 20:23:30 +0000 |
commit | 0d9210e9bc807ce64ea5fa694abb331ee5370c26 (patch) | |
tree | f3e1df9582a937465bdb1302950bc17bd79606f1 /crates/ra_hir/src | |
parent | f3489e8111e02bbd4e882d05d2fffe29962aef71 (diff) |
handle multibyte tokens
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/macros.rs | 45 | ||||
-rw-r--r-- | crates/ra_hir/src/macros/mbe.rs | 9 |
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 | ||
87 | fn parse_rule(p: &mut RulesParser) -> Option<Rule> { | 87 | fn 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 | ||
95 | fn parse_subtree(tt: &tt::Subtree) -> Option<Subtree> { | 95 | fn 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 | ||
99 | struct RulesParser<'a> { | 102 | struct RulesParser<'a> { |