mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-26 13:20:32 +01:00
Slightly cleaner parser
This commit is contained in:
@@ -9,7 +9,6 @@ use nom::combinator::opt;
|
|||||||
use nom::multi::fold_many0;
|
use nom::multi::fold_many0;
|
||||||
use nom::sequence::delimited;
|
use nom::sequence::delimited;
|
||||||
use nom::sequence::preceded;
|
use nom::sequence::preceded;
|
||||||
use nom::sequence::separated_pair;
|
|
||||||
use nom::sequence::terminated;
|
use nom::sequence::terminated;
|
||||||
use nom::sequence::tuple;
|
use nom::sequence::tuple;
|
||||||
use nom::IResult;
|
use nom::IResult;
|
||||||
@@ -37,14 +36,9 @@ fn parse_dir<'a>(
|
|||||||
// of either
|
// of either
|
||||||
alt((
|
alt((
|
||||||
// A size followed by a name
|
// A size followed by a name
|
||||||
map(
|
map(terminated(u32, take_until("\n")), Entry::File),
|
||||||
separated_pair(u32, tag(" "), take_until("\n")),
|
|
||||||
|(size, _)| Entry::File(size),
|
|
||||||
),
|
|
||||||
// Or the word "dir" followed by a name
|
// Or the word "dir" followed by a name
|
||||||
map(preceded(tag("dir "), take_until("\n")), |name| {
|
map(preceded(tag("dir "), take_until("\n")), Entry::Dir),
|
||||||
Entry::Dir(name)
|
|
||||||
}),
|
|
||||||
)),
|
)),
|
||||||
newline,
|
newline,
|
||||||
),
|
),
|
||||||
@@ -72,6 +66,7 @@ fn parse_dir<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
dirs.push(size);
|
dirs.push(size);
|
||||||
|
dir_stack.truncate(initial_len);
|
||||||
|
|
||||||
Ok((input, size))
|
Ok((input, size))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user