diff options
author | Edwin Cheng <[email protected]> | 2019-05-04 14:57:20 +0100 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2019-05-04 14:57:20 +0100 |
commit | 0c4efbb2b61a1309f144add2e680909d42530519 (patch) | |
tree | 58bf92ac4826c991a9dbe7c91098c5baa90c63dc /crates/ra_mbe | |
parent | b1febf2e6d4606a7e0eb422cdeba5dd286b10794 (diff) |
Error out when parse_subtree is not a subtree
Diffstat (limited to 'crates/ra_mbe')
-rw-r--r-- | crates/ra_mbe/src/mbe_parser.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/crates/ra_mbe/src/mbe_parser.rs b/crates/ra_mbe/src/mbe_parser.rs index c7ab463e2..110783689 100644 --- a/crates/ra_mbe/src/mbe_parser.rs +++ b/crates/ra_mbe/src/mbe_parser.rs | |||
@@ -34,11 +34,14 @@ fn parse_subtree(tt: &tt::Subtree, transcriber: bool) -> Result<crate::Subtree, | |||
34 | while let Some(tt) = p.eat() { | 34 | while let Some(tt) = p.eat() { |
35 | let child: crate::TokenTree = match tt { | 35 | let child: crate::TokenTree = match tt { |
36 | tt::TokenTree::Leaf(leaf) => match leaf { | 36 | tt::TokenTree::Leaf(leaf) => match leaf { |
37 | tt::Leaf::Punct(tt::Punct { char: '$', .. }) => { | 37 | tt::Leaf::Punct(tt::Punct { char: '$', spacing }) => { |
38 | if p.at_ident().is_some() { | 38 | if p.at_ident().is_some() { |
39 | crate::Leaf::from(parse_var(&mut p, transcriber)?).into() | 39 | crate::Leaf::from(parse_var(&mut p, transcriber)?).into() |
40 | } else { | 40 | } else if let Some(tt::TokenTree::Subtree(_)) = p.current() { |
41 | parse_repeat(&mut p, transcriber)?.into() | 41 | parse_repeat(&mut p, transcriber)?.into() |
42 | } else { | ||
43 | // Treat it as normal punct | ||
44 | crate::Leaf::from(tt::Punct { char: '$', spacing: *spacing }).into() | ||
42 | } | 45 | } |
43 | } | 46 | } |
44 | tt::Leaf::Punct(punct) => crate::Leaf::from(*punct).into(), | 47 | tt::Leaf::Punct(punct) => crate::Leaf::from(*punct).into(), |
@@ -89,7 +92,7 @@ fn mk_repeat( | |||
89 | } | 92 | } |
90 | 93 | ||
91 | fn parse_repeat(p: &mut TtCursor, transcriber: bool) -> Result<crate::Repeat, ParseError> { | 94 | fn parse_repeat(p: &mut TtCursor, transcriber: bool) -> Result<crate::Repeat, ParseError> { |
92 | let subtree = p.eat_subtree().unwrap(); | 95 | let subtree = p.eat_subtree()?; |
93 | let mut subtree = parse_subtree(subtree, transcriber)?; | 96 | let mut subtree = parse_subtree(subtree, transcriber)?; |
94 | subtree.delimiter = crate::Delimiter::None; | 97 | subtree.delimiter = crate::Delimiter::None; |
95 | 98 | ||