@@ -4,13 +4,13 @@ use std::{
44} ;
55
66use 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
1616use crate :: {
@@ -71,11 +71,15 @@ where
7171}
7272
7373fn 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
7779fn 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
8185fn point ( i : & str ) -> IResult < & str , Specifier > {
@@ -89,27 +93,27 @@ fn named_point(i: &str) -> IResult<&str, RootSpecifier> {
8993}
9094
9195fn 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
97101fn 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
103107fn 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
109113fn 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
115119fn all ( i : & str ) -> IResult < & str , Specifier > {
@@ -123,31 +127,31 @@ fn any(i: &str) -> IResult<&str, Specifier> {
123127}
124128
125129fn 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
129133fn specifier_with_any ( i : & str ) -> IResult < & str , Specifier > {
130- alt ( ( any, specifier) ) ( i)
134+ alt ( ( any, specifier) ) . parse ( i)
131135}
132136
133137fn 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
137141fn 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
141145fn 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
147151fn 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
153157fn 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
254258fn 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
273276fn 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