Skip to content

Commit c8310f9

Browse files
committed
Change parse_lines and parse_all to require 1 item by default
1 parent d6b487a commit c8310f9

File tree

5 files changed

+6
-14
lines changed

5 files changed

+6
-14
lines changed

crates/utils/src/parser/base.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ pub trait Parser<'i>: Sized {
426426
#[inline]
427427
fn parse_all(&self, input: &'i str) -> Result<Vec<Self::Output>, InputError> {
428428
ParserRef(self)
429-
.repeat(Constant(()), 0)
429+
.repeat(Constant(()), 1)
430430
.parse_complete(input)
431431
}
432432

@@ -451,10 +451,7 @@ pub trait Parser<'i>: Sized {
451451
/// ```
452452
#[inline]
453453
fn parse_lines(&self, input: &'i str) -> Result<Vec<Self::Output>, InputError> {
454-
ParserRef(self)
455-
.with_suffix(Eol())
456-
.repeat(Constant(()), 0)
457-
.parse_complete(input)
454+
ParserRef(self).repeat(Eol(), 1).parse_complete(input)
458455
}
459456

460457
/// Create an iterator which applies this parser repeatedly until the provided input is fully

crates/year2015/src/day06.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ examples!(Day06 -> (u32, u32) [
138138
},
139139
{
140140
input: "turn on 0,0 through 0,0\n\
141-
toggle 0,0 through 999,999\n",
141+
toggle 0,0 through 999,999",
142142
part2: 2000001,
143143
},
144144
]);

crates/year2016/src/day20.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ impl Day20 {
1717
Err("end value cannot be less than start")
1818
}
1919
})
20-
.parse_lines(input)?;
20+
.repeat(parser::eol(), 0)
21+
.parse_complete(input)?;
2122
ranges.sort_unstable();
2223
Ok(Self { ranges })
2324
}

crates/year2018/src/day06.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ impl Day06 {
1616
.repeat_n(", ")
1717
.map(Vec2::from)
1818
.parse_lines(input)?;
19-
if locations.is_empty() {
20-
return Err(InputError::new(input, 0, "expected at least one location"));
21-
}
19+
2220
if locations.len() >= u8::MAX as usize {
2321
return Err(InputError::new(input, 0, "too many locations"));
2422
}

crates/year2018/src/day17.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ impl Day17 {
3434
})
3535
.parse_lines(input)?;
3636

37-
if segments.is_empty() {
38-
return Err(InputError::new(input, 0, "expected at least one line"));
39-
}
40-
4137
let (mut x_min, mut x_max, mut y_min, mut y_max) = (500, 500, usize::MAX, 0);
4238
for &(axis, c1, c2, c3) in &segments {
4339
if axis == b'x' {

0 commit comments

Comments
 (0)