Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9589746

Browse files
authored
Merge pull request#159 from yuankunzhang/weekday-optional-comma
fix: weekday may be followed by an optional comma
2 parents30cb26d +73f69b1 commit9589746

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

‎src/items/weekday.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
//! >
2222
//! > A comma following a day of the week item is ignored.
2323
24-
use winnow::{ascii::alpha1, combinator::opt, seq,ModalResult,Parser};
24+
use winnow::{
25+
ascii::alpha1,
26+
combinator::{opt, terminated},
27+
seq,ModalResult,Parser,
28+
};
2529

2630
usesuper::{ordinal::ordinal, primitive::s};
2731

@@ -55,10 +59,26 @@ impl From<Day> for chrono::Weekday {
5559
}
5660
}
5761
}
62+
63+
/// Parse a weekday item.
64+
///
65+
/// Grammar:
66+
///
67+
/// ```ebnf
68+
/// weekday = [ ordinal ] day [ "," ] ;
69+
///
70+
/// day = "monday" | "mon" | "mon."
71+
/// | "tuesday" | "tue" | "tue." | "tues"
72+
/// | "wednesday" | "wed" | "wed." | "wednes"
73+
/// | "thursday" | "thu" | "thu." | "thur" | "thurs"
74+
/// | "friday" | "fri" | "fri."
75+
/// | "saturday" | "sat" | "sat."
76+
/// | "sunday" | "sun" | "sun." ;
77+
/// ```
5878
pubfnparse(input:&mut&str) ->ModalResult<Weekday>{
5979
seq!(Weekday{
6080
offset: opt(ordinal).map(|o| o.unwrap_or_default()),
61-
day: day,
81+
day:terminated(day, opt(s(","))),
6282
})
6383
.parse_next(input)
6484
}
@@ -134,4 +154,17 @@ mod tests {
134154
);
135155
}
136156
}
157+
158+
#[test]
159+
fnoptional_comma(){
160+
formut sin["monday,","mon,","mon.,","mon. ,"]{
161+
assert_eq!(
162+
parse(&mut s).unwrap(),
163+
Weekday{
164+
offset:0,
165+
day:Day::Monday,
166+
}
167+
);
168+
}
169+
}
137170
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp