Skip to content

Commit de3ae62

Browse files
committed
Add more parse_*_seq methods for code reuse.
1 parent 33421de commit de3ae62

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,26 @@ impl<'a> Parser<'a> {
10001000
Ok((result, trailing))
10011001
}
10021002

1003+
fn parse_delim_comma_seq<T>(
1004+
&mut self,
1005+
delim: DelimToken,
1006+
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
1007+
) -> PResult<'a, (Vec<T>, bool)> {
1008+
self.parse_unspanned_seq(
1009+
&token::OpenDelim(delim),
1010+
&token::CloseDelim(delim),
1011+
SeqSep::trailing_allowed(token::Comma),
1012+
f,
1013+
)
1014+
}
1015+
1016+
fn parse_paren_comma_seq<T>(
1017+
&mut self,
1018+
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
1019+
) -> PResult<'a, (Vec<T>, bool)> {
1020+
self.parse_delim_comma_seq(token::Paren, f)
1021+
}
1022+
10031023
/// Advance the parser by one token
10041024
pub fn bump(&mut self) {
10051025
if self.prev_token_kind == PrevTokenKind::Eof {
@@ -2623,6 +2643,10 @@ impl<'a> Parser<'a> {
26232643
return Ok(e);
26242644
}
26252645

2646+
fn parse_paren_expr_seq(&mut self) -> PResult<'a, Vec<P<Expr>>> {
2647+
self.parse_paren_comma_seq(|p| p.parse_expr()).map(|(r, _)| r)
2648+
}
2649+
26262650
crate fn process_potential_macro_variable(&mut self) {
26272651
self.token = match self.token.kind {
26282652
token::Dollar if self.token.span.ctxt() != SyntaxContext::empty() &&

0 commit comments

Comments
 (0)