Skip to content

Commit 5e0151f

Browse files
committed
Move eat
1 parent cb1bfcd commit 5e0151f

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

crates/pep508-rs/src/lib.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -617,21 +617,22 @@ fn parse_extras(cursor: &mut Cursor) -> Result<Vec<ExtraName>, Pep508Error> {
617617
let Some(bracket_pos) = cursor.eat_char('[') else {
618618
return Ok(vec![]);
619619
};
620+
cursor.eat_whitespace();
621+
620622
let mut extras = Vec::new();
621623
let mut is_first_iteration = true;
622624

623625
loop {
624-
cursor.eat_whitespace();
625-
626-
// End of the extras section
626+
// End of the extras section. (Empty extras are allowed.)
627627
if let Some(']') = cursor.peek_char() {
628628
cursor.next();
629629
break;
630630
}
631631

632+
632633
// Comma separator
633634
match (cursor.peek(), is_first_iteration) {
634-
// For the first iteration, we don't expect a comma
635+
// For the first iteration, we don't expect a comma.
635636
(Some((pos, ',')), true) => {
636637
return Err(Pep508Error {
637638
message: Pep508ErrorSource::String(
@@ -642,7 +643,7 @@ fn parse_extras(cursor: &mut Cursor) -> Result<Vec<ExtraName>, Pep508Error> {
642643
input: cursor.to_string(),
643644
});
644645
}
645-
// For the other iterations, the comma is required
646+
// For the other iterations, the comma is required.
646647
(Some((_, ',')), false) => {
647648
cursor.next();
648649
}
@@ -672,7 +673,7 @@ fn parse_extras(cursor: &mut Cursor) -> Result<Vec<ExtraName>, Pep508Error> {
672673
input: cursor.to_string(),
673674
};
674675

675-
// First char of the identifier
676+
// First char of the identifier.
676677
match cursor.next() {
677678
// letterOrDigit
678679
Some((_, alphanumeric @ ('a'..='z' | 'A'..='Z' | '0'..='9'))) => {
@@ -712,6 +713,7 @@ fn parse_extras(cursor: &mut Cursor) -> Result<Vec<ExtraName>, Pep508Error> {
712713
};
713714
// wsp* after the identifier
714715
cursor.eat_whitespace();
716+
715717
// Add the parsed extra
716718
extras.push(
717719
ExtraName::new(buffer).expect("`ExtraName` validation should match PEP 508 parsing"),
@@ -1258,6 +1260,18 @@ mod tests {
12581260
);
12591261
}
12601262

1263+
#[test]
1264+
fn error_extras_illegal_start3() {
1265+
assert_err(
1266+
"black[,]",
1267+
indoc! {"
1268+
Expected either alphanumerical character (starting the extra name) or ']' (ending the extras section), found ','
1269+
black[,]
1270+
^"
1271+
},
1272+
);
1273+
}
1274+
12611275
#[test]
12621276
fn error_extras_illegal_character() {
12631277
assert_err(

0 commit comments

Comments
 (0)