Skip to content

Commit 7aeb4b7

Browse files
committed
Add more parse_*_seq methods for code reuse.
1 parent 0a40ef2 commit 7aeb4b7

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
@@ -1002,6 +1002,26 @@ impl<'a> Parser<'a> {
10021002
Ok((result, trailing))
10031003
}
10041004

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

2651+
fn parse_paren_expr_seq(&mut self) -> PResult<'a, Vec<P<Expr>>> {
2652+
self.parse_paren_comma_seq(|p| p.parse_expr()).map(|(r, _)| r)
2653+
}
2654+
26312655
crate fn process_potential_macro_variable(&mut self) {
26322656
self.token = match self.token.kind {
26332657
token::Dollar if self.token.span.ctxt() != SyntaxContext::empty() &&

0 commit comments

Comments
 (0)