split parse_angle_args into loop / single step
This commit is contained in:
parent
91194f795c
commit
abce4881e0
1 changed files with 67 additions and 63 deletions
|
@ -388,10 +388,20 @@ impl<'a> Parser<'a> {
|
||||||
/// possibly including trailing comma.
|
/// possibly including trailing comma.
|
||||||
fn parse_angle_args(&mut self) -> PResult<'a, Vec<AngleBracketedArg>> {
|
fn parse_angle_args(&mut self) -> PResult<'a, Vec<AngleBracketedArg>> {
|
||||||
let mut args = Vec::new();
|
let mut args = Vec::new();
|
||||||
loop {
|
while let Some(arg) = self.parse_angle_arg()? {
|
||||||
if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) {
|
args.push(arg);
|
||||||
|
if !self.eat(&token::Comma) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(args)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parses a single argument in the angle arguments `<...>` of a path segment.
|
||||||
|
fn parse_angle_arg(&mut self) -> PResult<'a, Option<AngleBracketedArg>> {
|
||||||
|
let arg = if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) {
|
||||||
// Parse lifetime argument.
|
// Parse lifetime argument.
|
||||||
args.push(AngleBracketedArg::Arg(GenericArg::Lifetime(self.expect_lifetime())));
|
AngleBracketedArg::Arg(GenericArg::Lifetime(self.expect_lifetime()))
|
||||||
} else if self.check_ident()
|
} else if self.check_ident()
|
||||||
&& self.look_ahead(1, |t| matches!(t.kind, token::Eq | token::Colon))
|
&& self.look_ahead(1, |t| matches!(t.kind, token::Eq | token::Colon))
|
||||||
{
|
{
|
||||||
|
@ -415,7 +425,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let constraint = AssocTyConstraint { id: ast::DUMMY_NODE_ID, ident, kind, span };
|
let constraint = AssocTyConstraint { id: ast::DUMMY_NODE_ID, ident, kind, span };
|
||||||
args.push(AngleBracketedArg::Constraint(constraint));
|
AngleBracketedArg::Constraint(constraint)
|
||||||
} else if self.check_const_arg() {
|
} else if self.check_const_arg() {
|
||||||
// Parse const argument.
|
// Parse const argument.
|
||||||
let expr = if let token::OpenDelim(token::Brace) = self.token.kind {
|
let expr = if let token::OpenDelim(token::Brace) = self.token.kind {
|
||||||
|
@ -442,19 +452,13 @@ impl<'a> Parser<'a> {
|
||||||
self.parse_literal_maybe_minus()?
|
self.parse_literal_maybe_minus()?
|
||||||
};
|
};
|
||||||
let value = AnonConst { id: ast::DUMMY_NODE_ID, value: expr };
|
let value = AnonConst { id: ast::DUMMY_NODE_ID, value: expr };
|
||||||
args.push(AngleBracketedArg::Arg(GenericArg::Const(value)));
|
AngleBracketedArg::Arg(GenericArg::Const(value))
|
||||||
} else if self.check_type() {
|
} else if self.check_type() {
|
||||||
// Parse type argument.
|
// Parse type argument.
|
||||||
args.push(AngleBracketedArg::Arg(GenericArg::Type(self.parse_ty()?)));
|
AngleBracketedArg::Arg(GenericArg::Type(self.parse_ty()?))
|
||||||
} else {
|
} else {
|
||||||
break;
|
return Ok(None);
|
||||||
}
|
};
|
||||||
|
Ok(Some(arg))
|
||||||
if !self.eat(&token::Comma) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(args)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue