aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_mbe/src/parser.rs')
-rw-r--r--crates/ra_mbe/src/parser.rs29
1 files changed, 13 insertions, 16 deletions
diff --git a/crates/ra_mbe/src/parser.rs b/crates/ra_mbe/src/parser.rs
index 50b8011a9..10a6f300a 100644
--- a/crates/ra_mbe/src/parser.rs
+++ b/crates/ra_mbe/src/parser.rs
@@ -45,15 +45,15 @@ impl PartialEq for Separator {
45 } 45 }
46} 46}
47 47
48pub(crate) fn parse_template<'a>( 48pub(crate) fn parse_template(
49 template: &'a tt::Subtree, 49 template: &tt::Subtree,
50) -> impl Iterator<Item = Result<Op<'a>, ExpandError>> { 50) -> impl Iterator<Item = Result<Op<'_>, ExpandError>> {
51 parse_inner(template, Mode::Template) 51 parse_inner(template, Mode::Template)
52} 52}
53 53
54pub(crate) fn parse_pattern<'a>( 54pub(crate) fn parse_pattern(
55 pattern: &'a tt::Subtree, 55 pattern: &tt::Subtree,
56) -> impl Iterator<Item = Result<Op<'a>, ExpandError>> { 56) -> impl Iterator<Item = Result<Op<'_>, ExpandError>> {
57 parse_inner(pattern, Mode::Pattern) 57 parse_inner(pattern, Mode::Pattern)
58} 58}
59 59
@@ -63,10 +63,7 @@ enum Mode {
63 Template, 63 Template,
64} 64}
65 65
66fn parse_inner<'a>( 66fn parse_inner(src: &tt::Subtree, mode: Mode) -> impl Iterator<Item = Result<Op<'_>, ExpandError>> {
67 src: &'a tt::Subtree,
68 mode: Mode,
69) -> impl Iterator<Item = Result<Op<'a>, ExpandError>> {
70 let mut src = TtIter::new(src); 67 let mut src = TtIter::new(src);
71 std::iter::from_fn(move || { 68 std::iter::from_fn(move || {
72 let first = src.next()?; 69 let first = src.next()?;
@@ -100,7 +97,7 @@ fn next_op<'a>(
100 Op::Repeat { subtree, separator, kind } 97 Op::Repeat { subtree, separator, kind }
101 } 98 }
102 tt::TokenTree::Leaf(leaf) => match leaf { 99 tt::TokenTree::Leaf(leaf) => match leaf {
103 tt::Leaf::Punct(..) => Err(ExpandError::UnexpectedToken)?, 100 tt::Leaf::Punct(..) => return Err(ExpandError::UnexpectedToken),
104 tt::Leaf::Ident(ident) => { 101 tt::Leaf::Ident(ident) => {
105 let name = &ident.text; 102 let name = &ident.text;
106 let kind = eat_fragment_kind(src, mode)?; 103 let kind = eat_fragment_kind(src, mode)?;
@@ -147,15 +144,15 @@ fn parse_repeat(src: &mut TtIter) -> Result<(Option<Separator>, RepeatKind), Exp
147 for tt in src { 144 for tt in src {
148 let tt = match tt { 145 let tt = match tt {
149 tt::TokenTree::Leaf(leaf) => leaf, 146 tt::TokenTree::Leaf(leaf) => leaf,
150 tt::TokenTree::Subtree(_) => Err(ExpandError::InvalidRepeat)?, 147 tt::TokenTree::Subtree(_) => return Err(ExpandError::InvalidRepeat),
151 }; 148 };
152 let has_sep = match &separator { 149 let has_sep = match &separator {
153 Separator::Puncts(puncts) => puncts.len() != 0, 150 Separator::Puncts(puncts) => !puncts.is_empty(),
154 _ => true, 151 _ => true,
155 }; 152 };
156 match tt { 153 match tt {
157 tt::Leaf::Ident(_) | tt::Leaf::Literal(_) if has_sep => { 154 tt::Leaf::Ident(_) | tt::Leaf::Literal(_) if has_sep => {
158 Err(ExpandError::InvalidRepeat)? 155 return Err(ExpandError::InvalidRepeat)
159 } 156 }
160 tt::Leaf::Ident(ident) => separator = Separator::Ident(ident.clone()), 157 tt::Leaf::Ident(ident) => separator = Separator::Ident(ident.clone()),
161 tt::Leaf::Literal(lit) => separator = Separator::Literal(lit.clone()), 158 tt::Leaf::Literal(lit) => separator = Separator::Literal(lit.clone()),
@@ -168,11 +165,11 @@ fn parse_repeat(src: &mut TtIter) -> Result<(Option<Separator>, RepeatKind), Exp
168 match &mut separator { 165 match &mut separator {
169 Separator::Puncts(puncts) => { 166 Separator::Puncts(puncts) => {
170 if puncts.len() == 3 { 167 if puncts.len() == 3 {
171 Err(ExpandError::InvalidRepeat)? 168 return Err(ExpandError::InvalidRepeat);
172 } 169 }
173 puncts.push(punct.clone()) 170 puncts.push(punct.clone())
174 } 171 }
175 _ => Err(ExpandError::InvalidRepeat)?, 172 _ => return Err(ExpandError::InvalidRepeat),
176 } 173 }
177 continue; 174 continue;
178 } 175 }