diff options
author | Florian Diebold <[email protected]> | 2020-03-15 14:15:56 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-03-16 17:38:19 +0000 |
commit | f3c6a2e3dbe477a7e0ac714a5bdbda6e8838fcfa (patch) | |
tree | bc2e523c1ab11a257a9910f471fe92759af0d6c4 /crates/ra_mbe/src | |
parent | 0660dd10d203cba4069b48d00d02ec9935a916f0 (diff) |
Fix remaining test failure
Diffstat (limited to 'crates/ra_mbe/src')
-rw-r--r-- | crates/ra_mbe/src/mbe_expander.rs | 2 | ||||
-rw-r--r-- | crates/ra_mbe/src/mbe_expander/matcher.rs | 18 |
2 files changed, 11 insertions, 9 deletions
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index 1328e4349..204c30e3d 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs | |||
@@ -21,9 +21,7 @@ fn expand_rules(rules: &[crate::Rule], input: &tt::Subtree) -> ExpandResult<tt:: | |||
21 | let (new_match, bindings_err) = matcher::match_(&rule.lhs, input); | 21 | let (new_match, bindings_err) = matcher::match_(&rule.lhs, input); |
22 | if bindings_err.is_none() { | 22 | if bindings_err.is_none() { |
23 | // if we find a rule that applies without errors, we're done | 23 | // if we find a rule that applies without errors, we're done |
24 | eprintln!("match without errors: {:?}", new_match); | ||
25 | let (res, transcribe_err) = transcriber::transcribe(&rule.rhs, &new_match.bindings); | 24 | let (res, transcribe_err) = transcriber::transcribe(&rule.rhs, &new_match.bindings); |
26 | eprintln!("transcribe_err = {:?}", transcribe_err); | ||
27 | if transcribe_err.is_none() { | 25 | if transcribe_err.is_none() { |
28 | return (res, None); | 26 | return (res, None); |
29 | } | 27 | } |
diff --git a/crates/ra_mbe/src/mbe_expander/matcher.rs b/crates/ra_mbe/src/mbe_expander/matcher.rs index ae65fb69a..f40d55d4e 100644 --- a/crates/ra_mbe/src/mbe_expander/matcher.rs +++ b/crates/ra_mbe/src/mbe_expander/matcher.rs | |||
@@ -255,7 +255,7 @@ impl<'a> TtIter<'a> { | |||
255 | pub(crate) fn expect_fragment( | 255 | pub(crate) fn expect_fragment( |
256 | &mut self, | 256 | &mut self, |
257 | fragment_kind: ra_parser::FragmentKind, | 257 | fragment_kind: ra_parser::FragmentKind, |
258 | ) -> ExpandResult<tt::TokenTree> { | 258 | ) -> ExpandResult<Option<tt::TokenTree>> { |
259 | pub(crate) struct OffsetTokenSink<'a> { | 259 | pub(crate) struct OffsetTokenSink<'a> { |
260 | pub(crate) cursor: Cursor<'a>, | 260 | pub(crate) cursor: Cursor<'a>, |
261 | pub(crate) error: bool, | 261 | pub(crate) error: bool, |
@@ -297,12 +297,16 @@ impl<'a> TtIter<'a> { | |||
297 | } | 297 | } |
298 | } | 298 | } |
299 | self.inner = self.inner.as_slice()[res.len()..].iter(); | 299 | self.inner = self.inner.as_slice()[res.len()..].iter(); |
300 | if res.len() == 0 && err.is_none() { | ||
301 | err = Some(err!("no tokens consumed")); | ||
302 | } | ||
300 | let res = match res.len() { | 303 | let res = match res.len() { |
301 | 1 => res[0].clone(), | 304 | 1 => Some(res[0].clone()), |
302 | _ => tt::TokenTree::Subtree(tt::Subtree { | 305 | 0 => None, |
306 | _ => Some(tt::TokenTree::Subtree(tt::Subtree { | ||
303 | delimiter: None, | 307 | delimiter: None, |
304 | token_trees: res.into_iter().cloned().collect(), | 308 | token_trees: res.into_iter().cloned().collect(), |
305 | }), | 309 | })), |
306 | }; | 310 | }; |
307 | (res, err) | 311 | (res, err) |
308 | } | 312 | } |
@@ -312,7 +316,7 @@ impl<'a> TtIter<'a> { | |||
312 | match fork.expect_fragment(Visibility) { | 316 | match fork.expect_fragment(Visibility) { |
313 | (tt, None) => { | 317 | (tt, None) => { |
314 | *self = fork; | 318 | *self = fork; |
315 | Some(tt) | 319 | tt |
316 | } | 320 | } |
317 | (_, Some(_)) => None, | 321 | (_, Some(_)) => None, |
318 | } | 322 | } |
@@ -419,8 +423,8 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult<Option<Fragmen | |||
419 | } | 423 | } |
420 | }; | 424 | }; |
421 | let (tt, err) = input.expect_fragment(fragment); | 425 | let (tt, err) = input.expect_fragment(fragment); |
422 | let fragment = if kind == "expr" { Fragment::Ast(tt) } else { Fragment::Tokens(tt) }; | 426 | let fragment = if kind == "expr" { tt.map(Fragment::Ast) } else { tt.map(Fragment::Tokens) }; |
423 | (Some(fragment), err) | 427 | (fragment, err) |
424 | } | 428 | } |
425 | 429 | ||
426 | fn collect_vars(buf: &mut Vec<SmolStr>, pattern: &tt::Subtree) -> Result<(), ExpandError> { | 430 | fn collect_vars(buf: &mut Vec<SmolStr>, pattern: &tt::Subtree) -> Result<(), ExpandError> { |