Skip to content

Commit c80d67b

Browse files
committed
dependencies: Update nom to v8
1 parent 839dedd commit c80d67b

4 files changed

Lines changed: 61 additions & 68 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ libc = "0.2"
7777
memchr = "2"
7878
mime = "0.3"
7979
nix = { version = "0.31", features = ["socket"] }
80-
nom = "7"
80+
nom = "8"
8181
paste = { git = "https://github.com/dtolnay/paste", ref = "6a302522990cbfd9de4e0c61d91854622f7b2999" }
8282
rand = "0.10"
8383
regex = { version = "1" }

bel/src/duration.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
use chrono::Duration;
22
use nom::{
3-
IResult,
4-
branch::alt,
5-
bytes::complete::tag,
6-
character::complete::char,
7-
combinator::{map, opt},
8-
multi::many1,
3+
IResult, Parser, branch::alt, bytes::complete::tag, character::complete::char, combinator::opt, multi::many1,
94
number::complete::double,
105
};
116

@@ -34,12 +29,13 @@ const MICROSECOND: u64 = 1_000;
3429
/// - `1ns` parses as 1 nanosecond
3530
/// - `1.5ns` parses as 1 nanosecond (sub-nanosecond durations not supported)
3631
pub fn parse_duration(i: &str) -> IResult<&str, Duration> {
37-
let (i, neg) = opt(parse_negative)(i)?;
32+
let (i, neg) = opt(parse_negative).parse(i)?;
3833
if i == "0" {
3934
return Ok((i, Duration::zero()));
4035
}
41-
let (i, duration) =
42-
many1(parse_number_unit)(i).map(|(i, d)| (i, d.iter().fold(Duration::zero(), |acc, next| acc + *next)))?;
36+
let (i, duration) = many1(parse_number_unit)
37+
.parse(i)
38+
.map(|(i, d)| (i, d.iter().fold(Duration::zero(), |acc, next| acc + *next)))?;
4339
Ok((i, duration * if neg.is_some() { -1 } else { 1 }))
4440
}
4541

@@ -73,19 +69,20 @@ fn parse_number_unit(i: &str) -> IResult<&str, Duration> {
7369
}
7470

7571
fn parse_negative(i: &str) -> IResult<&str, ()> {
76-
let (i, _): (&str, char) = char('-')(i)?;
72+
let (i, _): (&str, char) = char('-').parse(i)?;
7773
Ok((i, ()))
7874
}
7975

8076
fn parse_unit(i: &str) -> IResult<&str, Unit> {
8177
alt((
82-
map(tag("ms"), |_| Unit::Millisecond),
83-
map(tag("us"), |_| Unit::Microsecond),
84-
map(tag("ns"), |_| Unit::Nanosecond),
85-
map(char('h'), |_| Unit::Hour),
86-
map(char('m'), |_| Unit::Minute),
87-
map(char('s'), |_| Unit::Second),
88-
))(i)
78+
tag("ms").map(|_| Unit::Millisecond),
79+
tag("us").map(|_| Unit::Microsecond),
80+
tag("ns").map(|_| Unit::Nanosecond),
81+
char('h').map(|_| Unit::Hour),
82+
char('m').map(|_| Unit::Minute),
83+
char('s').map(|_| Unit::Second),
84+
))
85+
.parse(i)
8986
}
9087

9188
fn to_duration(num: f64, unit: Unit) -> Duration {

cron/src/parsing.rs

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use std::{
44
};
55

66
use nom::{
7-
IResult,
7+
IResult, Parser,
88
branch::alt,
99
bytes::complete::tag,
1010
character::complete::{alpha1, digit1, multispace0},
11-
combinator::{all_consuming, eof, map, map_res, opt},
11+
combinator::{all_consuming, eof, opt},
1212
multi::separated_list1,
13-
sequence::{delimited, separated_pair, terminated, tuple},
13+
sequence::{delimited, separated_pair, terminated},
1414
};
1515

1616
use crate::{
@@ -71,11 +71,15 @@ where
7171
}
7272

7373
fn ordinal(i: &str) -> IResult<&str, u32> {
74-
map_res(delimited(multispace0, digit1, multispace0), u32::from_str)(i)
74+
delimited(multispace0, digit1, multispace0)
75+
.map_res(u32::from_str)
76+
.parse(i)
7577
}
7678

7779
fn name(i: &str) -> IResult<&str, String> {
78-
map(delimited(multispace0, alpha1, multispace0), ToOwned::to_owned)(i)
80+
delimited(multispace0, alpha1, multispace0)
81+
.map(ToOwned::to_owned)
82+
.parse(i)
7983
}
8084

8185
fn point(i: &str) -> IResult<&str, Specifier> {
@@ -89,27 +93,27 @@ fn named_point(i: &str) -> IResult<&str, RootSpecifier> {
8993
}
9094

9195
fn period(i: &str) -> IResult<&str, RootSpecifier> {
92-
map(separated_pair(specifier, tag("/"), ordinal), |(start, step)| {
93-
RootSpecifier::Period(start, step)
94-
})(i)
96+
separated_pair(specifier, tag("/"), ordinal)
97+
.map(|(start, step)| RootSpecifier::Period(start, step))
98+
.parse(i)
9599
}
96100

97101
fn period_with_any(i: &str) -> IResult<&str, RootSpecifier> {
98-
map(separated_pair(specifier_with_any, tag("/"), ordinal), |(start, step)| {
99-
RootSpecifier::Period(start, step)
100-
})(i)
102+
separated_pair(specifier_with_any, tag("/"), ordinal)
103+
.map(|(start, step)| RootSpecifier::Period(start, step))
104+
.parse(i)
101105
}
102106

103107
fn range(i: &str) -> IResult<&str, Specifier> {
104-
map(separated_pair(ordinal, tag("-"), ordinal), |(start, end)| {
105-
Specifier::Range(start, end)
106-
})(i)
108+
separated_pair(ordinal, tag("-"), ordinal)
109+
.map(|(start, end)| Specifier::Range(start, end))
110+
.parse(i)
107111
}
108112

109113
fn named_range(i: &str) -> IResult<&str, Specifier> {
110-
map(separated_pair(name, tag("-"), name), |(start, end)| {
111-
Specifier::NamedRange(start, end)
112-
})(i)
114+
separated_pair(name, tag("-"), name)
115+
.map(|(start, end)| Specifier::NamedRange(start, end))
116+
.parse(i)
113117
}
114118

115119
fn all(i: &str) -> IResult<&str, Specifier> {
@@ -123,31 +127,31 @@ fn any(i: &str) -> IResult<&str, Specifier> {
123127
}
124128

125129
fn specifier(i: &str) -> IResult<&str, Specifier> {
126-
alt((all, range, point, named_range))(i)
130+
alt((all, range, point, named_range)).parse(i)
127131
}
128132

129133
fn specifier_with_any(i: &str) -> IResult<&str, Specifier> {
130-
alt((any, specifier))(i)
134+
alt((any, specifier)).parse(i)
131135
}
132136

133137
fn root_specifier(i: &str) -> IResult<&str, RootSpecifier> {
134-
alt((period, map(specifier, RootSpecifier::from), named_point))(i)
138+
alt((period, specifier.map(RootSpecifier::from), named_point)).parse(i)
135139
}
136140

137141
fn root_specifier_with_any(i: &str) -> IResult<&str, RootSpecifier> {
138-
alt((period_with_any, map(specifier_with_any, RootSpecifier::from), named_point))(i)
142+
alt((period_with_any, specifier_with_any.map(RootSpecifier::from), named_point)).parse(i)
139143
}
140144

141145
fn root_specifier_list(i: &str) -> IResult<&str, Vec<RootSpecifier>> {
142146
let list = separated_list1(tag(","), root_specifier);
143-
let single_item = map(root_specifier, |spec| vec![spec]);
144-
delimited(multispace0, alt((list, single_item)), multispace0)(i)
147+
let single_item = root_specifier.map(|spec| vec![spec]);
148+
delimited(multispace0, alt((list, single_item)), multispace0).parse(i)
145149
}
146150

147151
fn root_specifier_list_with_any(i: &str) -> IResult<&str, Vec<RootSpecifier>> {
148152
let list = separated_list1(tag(","), root_specifier_with_any);
149-
let single_item = map(root_specifier_with_any, |spec| vec![spec]);
150-
delimited(multispace0, alt((list, single_item)), multispace0)(i)
153+
let single_item = root_specifier_with_any.map(|spec| vec![spec]);
154+
delimited(multispace0, alt((list, single_item)), multispace0).parse(i)
151155
}
152156

153157
fn field(i: &str) -> IResult<&str, Field> {
@@ -248,30 +252,29 @@ fn shorthand(i: &str) -> IResult<&str, ScheduleFields> {
248252
shorthand_daily,
249253
shorthand_hourly,
250254
));
251-
delimited(multispace0, keywords, multispace0)(i)
255+
delimited(multispace0, keywords, multispace0).parse(i)
252256
}
253257

254258
fn longhand(i: &str) -> IResult<&str, ScheduleFields> {
255-
let seconds = map_res(field, Seconds::from_field);
256-
let minutes = map_res(field, Minutes::from_field);
257-
let hours = map_res(field, Hours::from_field);
258-
let days_of_month = map_res(field_with_any, DaysOfMonth::from_field);
259-
let months = map_res(field, Months::from_field);
260-
let days_of_week = map_res(field_with_any, DaysOfWeek::from_field);
261-
let years = opt(map_res(field, Years::from_field));
262-
let fields = tuple((seconds, minutes, hours, days_of_month, months, days_of_week, years));
263-
264-
map(
265-
terminated(fields, eof),
266-
|(seconds, minutes, hours, days_of_month, months, days_of_week, years)| {
259+
let seconds = field.map_res(Seconds::from_field);
260+
let minutes = field.map_res(Minutes::from_field);
261+
let hours = field.map_res(Hours::from_field);
262+
let days_of_month = field_with_any.map_res(DaysOfMonth::from_field);
263+
let months = field.map_res(Months::from_field);
264+
let days_of_week = field_with_any.map_res(DaysOfWeek::from_field);
265+
let years = opt(field.map_res(Years::from_field));
266+
let fields = (seconds, minutes, hours, days_of_month, months, days_of_week, years);
267+
268+
terminated(fields, eof)
269+
.map(|(seconds, minutes, hours, days_of_month, months, days_of_week, years)| {
267270
let years = years.unwrap_or_else(Years::all);
268271
ScheduleFields::new(seconds, minutes, hours, days_of_month, months, days_of_week, years)
269-
},
270-
)(i)
272+
})
273+
.parse(i)
271274
}
272275

273276
fn schedule(i: &str) -> IResult<&str, ScheduleFields> {
274-
all_consuming(alt((shorthand, longhand)))(i)
277+
all_consuming(alt((shorthand, longhand))).parse(i)
275278
}
276279

277280
#[cfg(test)]

0 commit comments

Comments
 (0)