Skip to content

Commit aa3bbe6

Browse files
marcusklaasdjc
authored andcommitted
Upgrade to nom 5 (#53)
1 parent 7eddc6e commit aa3bbe6

File tree

9 files changed

+127
-126
lines changed

9 files changed

+127
-126
lines changed

imap-proto/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ azure-devops = { project = "dochtman/Projects", pipeline = "tokio-imap", build =
1515
maintenance = { status = "passively-maintained" }
1616

1717
[dependencies]
18-
nom = "4.0"
18+
nom = "5"
1919

2020
[dev-dependencies]
2121
assert_matches = "1.3"

imap-proto/src/body.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use types::*;
44
named!(pub section_part<Vec<u32>>, do_parse!(
55
part: number >>
66
rest: many0!(do_parse!(
7-
tag_s!(".") >>
7+
tag!(".") >>
88
part: number >>
99
(part)
1010
)) >> ({
@@ -15,7 +15,7 @@ named!(pub section_part<Vec<u32>>, do_parse!(
1515
));
1616

1717
named!(pub section_msgtext<MessageSection>, map!(
18-
alt!(tag_s!("HEADER") | tag_s!("TEXT")),
18+
alt!(tag!("HEADER") | tag!("TEXT")),
1919
|s| match s {
2020
b"HEADER" => MessageSection::Header,
2121
b"TEXT" => MessageSection::Text,
@@ -25,15 +25,15 @@ named!(pub section_msgtext<MessageSection>, map!(
2525

2626
named!(pub section_text<MessageSection>, alt!(
2727
section_msgtext |
28-
do_parse!(tag_s!("MIME") >> (MessageSection::Mime))
28+
do_parse!(tag!("MIME") >> (MessageSection::Mime))
2929
));
3030

3131
named!(pub section_spec<SectionPath>, alt!(
3232
map!(section_msgtext, |val| SectionPath::Full(val)) |
3333
do_parse!(
3434
part: section_part >>
3535
text: opt!(do_parse!(
36-
tag_s!(".") >>
36+
tag!(".") >>
3737
text: section_text >>
3838
(text)
3939
)) >>
@@ -42,22 +42,22 @@ named!(pub section_spec<SectionPath>, alt!(
4242
));
4343

4444
named!(pub section<Option<SectionPath>>, do_parse!(
45-
tag_s!("[") >>
45+
tag!("[") >>
4646
spec: opt!(section_spec) >>
47-
tag_s!("]") >>
47+
tag!("]") >>
4848
(spec)
4949
));
5050

5151
named!(pub msg_att_body_section<AttributeValue>, do_parse!(
52-
tag_s!("BODY") >>
52+
tag!("BODY") >>
5353
section: section >>
5454
index: opt!(do_parse!(
55-
tag_s!("<") >>
55+
tag!("<") >>
5656
num: number >>
57-
tag_s!(">") >>
57+
tag!(">") >>
5858
(num)
5959
)) >>
60-
tag_s!(" ") >>
60+
tag!(" ") >>
6161
data: nstring >>
6262
(AttributeValue::BodySection { section, index, data })
6363
));

imap-proto/src/body_structure.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ struct BodyFields<'a> {
1616

1717
named!(body_fields<BodyFields>, do_parse!(
1818
param: body_param >>
19-
tag_s!(" ") >>
19+
tag!(" ") >>
2020
id: nstring_utf8 >>
21-
tag_s!(" ") >>
21+
tag!(" ") >>
2222
description: nstring_utf8 >>
23-
tag_s!(" ") >>
23+
tag!(" ") >>
2424
transfer_encoding: body_encoding >>
25-
tag_s!(" ") >>
25+
tag!(" ") >>
2626
octets: number >>
2727
(BodyFields { param, id, description, transfer_encoding, octets })
2828
));
@@ -36,11 +36,11 @@ struct BodyExt1Part<'a> {
3636
}
3737

3838
named!(body_ext_1part<BodyExt1Part>, do_parse!(
39-
md5: opt_opt!(preceded!(tag_s!(" "), nstring_utf8)) >>
40-
disposition: opt_opt!(preceded!(tag_s!(" "), body_disposition)) >>
41-
language: opt_opt!(preceded!(tag_s!(" "), body_lang)) >>
42-
location: opt_opt!(preceded!(tag_s!(" "), nstring_utf8)) >>
43-
extension: opt!(preceded!(tag_s!(" "), body_extension)) >>
39+
md5: opt_opt!(preceded!(tag!(" "), nstring_utf8)) >>
40+
disposition: opt_opt!(preceded!(tag!(" "), body_disposition)) >>
41+
language: opt_opt!(preceded!(tag!(" "), body_lang)) >>
42+
location: opt_opt!(preceded!(tag!(" "), nstring_utf8)) >>
43+
extension: opt!(preceded!(tag!(" "), body_extension)) >>
4444
(BodyExt1Part { md5, disposition, language, location, extension })
4545
));
4646

@@ -53,21 +53,21 @@ struct BodyExtMPart<'a> {
5353
}
5454

5555
named!(body_ext_mpart<BodyExtMPart>, do_parse!(
56-
param: opt_opt!(preceded!(tag_s!(" "), body_param)) >>
57-
disposition: opt_opt!(preceded!(tag_s!(" "), body_disposition)) >>
58-
language: opt_opt!(preceded!(tag_s!(" "), body_lang)) >>
59-
location: opt_opt!(preceded!(tag_s!(" "), nstring_utf8)) >>
60-
extension: opt!(preceded!(tag_s!(" "), body_extension)) >>
56+
param: opt_opt!(preceded!(tag!(" "), body_param)) >>
57+
disposition: opt_opt!(preceded!(tag!(" "), body_disposition)) >>
58+
language: opt_opt!(preceded!(tag!(" "), body_lang)) >>
59+
location: opt_opt!(preceded!(tag!(" "), nstring_utf8)) >>
60+
extension: opt!(preceded!(tag!(" "), body_extension)) >>
6161
(BodyExtMPart { param, disposition, language, location, extension })
6262
));
6363

6464
named!(body_encoding<ContentEncoding>, alt!(
6565
delimited!(char!('"'), alt!(
66-
map!(tag_no_case_s!("7BIT"), |_| ContentEncoding::SevenBit) |
67-
map!(tag_no_case_s!("8BIT"), |_| ContentEncoding::EightBit) |
68-
map!(tag_no_case_s!("BINARY"), |_| ContentEncoding::Binary) |
69-
map!(tag_no_case_s!("BASE64"), |_| ContentEncoding::Base64) |
70-
map!(tag_no_case_s!("QUOTED-PRINTABLE"), |_| ContentEncoding::QuotedPrintable)
66+
map!(tag_no_case!("7BIT"), |_| ContentEncoding::SevenBit) |
67+
map!(tag_no_case!("8BIT"), |_| ContentEncoding::EightBit) |
68+
map!(tag_no_case!("BINARY"), |_| ContentEncoding::Binary) |
69+
map!(tag_no_case!("BASE64"), |_| ContentEncoding::Base64) |
70+
map!(tag_no_case!("QUOTED-PRINTABLE"), |_| ContentEncoding::QuotedPrintable)
7171
), char!('"')) |
7272
map!(string_utf8, |enc| ContentEncoding::Other(enc))
7373
));
@@ -81,7 +81,7 @@ named!(body_param<BodyParams>, alt!(
8181
map!(nil, |_| None) |
8282
map!(parenthesized_nonempty_list!(do_parse!(
8383
key: string_utf8 >>
84-
tag_s!(" ") >>
84+
tag!(" ") >>
8585
val: string_utf8 >>
8686
((key, val))
8787
)), Option::from)
@@ -97,7 +97,7 @@ named!(body_disposition<Option<ContentDisposition>>, alt!(
9797
map!(nil, |_| None) |
9898
paren_delimited!(do_parse!(
9999
ty: string_utf8 >>
100-
tag_s!(" ") >>
100+
tag!(" ") >>
101101
params: body_param >>
102102
(Some(ContentDisposition {
103103
ty,
@@ -108,9 +108,9 @@ named!(body_disposition<Option<ContentDisposition>>, alt!(
108108

109109
named!(body_type_basic<BodyStructure>, do_parse!(
110110
media_type: string_utf8 >>
111-
tag_s!(" ") >>
111+
tag!(" ") >>
112112
media_subtype: string_utf8 >>
113-
tag_s!(" ") >>
113+
tag!(" ") >>
114114
fields: body_fields >>
115115
ext: body_ext_1part >>
116116
(BodyStructure::Basic {
@@ -136,12 +136,12 @@ named!(body_type_basic<BodyStructure>, do_parse!(
136136
));
137137

138138
named!(body_type_text<BodyStructure>, do_parse!(
139-
tag_no_case_s!("\"TEXT\"") >>
140-
tag_s!(" ") >>
139+
tag_no_case!("\"TEXT\"") >>
140+
tag!(" ") >>
141141
media_subtype: string_utf8 >>
142-
tag_s!(" ") >>
142+
tag!(" ") >>
143143
fields: body_fields >>
144-
tag_s!(" ") >>
144+
tag!(" ") >>
145145
lines: number >>
146146
ext: body_ext_1part >>
147147
(BodyStructure::Text {
@@ -168,14 +168,14 @@ named!(body_type_text<BodyStructure>, do_parse!(
168168
));
169169

170170
named!(body_type_message<BodyStructure>, do_parse!(
171-
tag_no_case_s!("\"MESSAGE\" \"RFC822\"") >>
172-
tag_s!(" ") >>
171+
tag_no_case!("\"MESSAGE\" \"RFC822\"") >>
172+
tag!(" ") >>
173173
fields: body_fields >>
174-
tag_s!(" ") >>
174+
tag!(" ") >>
175175
envelope: envelope >>
176-
tag_s!(" ") >>
176+
tag!(" ") >>
177177
body: body >>
178-
tag_s!(" ") >>
178+
tag!(" ") >>
179179
lines: number >>
180180
ext: body_ext_1part >>
181181
(BodyStructure::Message {
@@ -205,7 +205,7 @@ named!(body_type_message<BodyStructure>, do_parse!(
205205

206206
named!(body_type_multipart<BodyStructure>, do_parse!(
207207
bodies: many1!(body) >>
208-
tag_s!(" ") >>
208+
tag!(" ") >>
209209
media_subtype: string_utf8 >>
210210
ext: body_ext_mpart >>
211211
(BodyStructure::Multipart {
@@ -229,7 +229,7 @@ named!(pub(crate) body<BodyStructure>, paren_delimited!(
229229
));
230230

231231
named!(pub(crate) msg_att_body_structure<AttributeValue>, do_parse!(
232-
tag_s!("BODYSTRUCTURE ") >>
232+
tag!("BODYSTRUCTURE ") >>
233233
body: body >>
234234
(AttributeValue::BodyStructure(body))
235235
));

imap-proto/src/core.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn atom_char(c: u8) -> bool {
3535
}
3636

3737
// nil = "NIL"
38-
named!(pub nil, tag_s!("NIL"));
38+
named!(pub nil, tag!("NIL"));
3939

4040
// ASTRING-CHAR = ATOM-CHAR / resp-specials
4141
pub fn astring_char(c: u8) -> bool {
@@ -75,10 +75,10 @@ named!(pub quoted_utf8<&str>, map_res!(quoted, str::from_utf8));
7575
// literal = "{" number "}" CRLF *CHAR8
7676
// ; Number represents the number of CHAR8s
7777
named!(pub literal<&[u8]>, do_parse!(
78-
tag_s!("{") >>
78+
tag!("{") >>
7979
len: number >>
80-
tag_s!("}") >>
81-
tag_s!("\r\n") >>
80+
tag!("}") >>
81+
tag!("\r\n") >>
8282
data: take!(len) >>
8383
(data)
8484
));
@@ -104,13 +104,13 @@ named!(pub nstring_utf8<Option<&str>>, alt!(
104104
// number = 1*DIGIT
105105
// ; Unsigned 32-bit integer
106106
// ; (0 <= n < 4,294,967,296)
107-
named!(pub number<u32>, flat_map!(nom::digit, parse_to!(u32)));
107+
named!(pub number<u32>, flat_map!(nom::character::complete::digit0, parse_to!(u32)));
108108

109109
// same as `number` but 64-bit
110-
named!(pub number_64<u64>, flat_map!(nom::digit, parse_to!(u64)));
110+
named!(pub number_64<u64>, flat_map!(nom::character::complete::digit0, parse_to!(u64)));
111111

112112
// atom = 1*ATOM-CHAR
113-
named!(pub atom<&str>, map_res!(take_while1_s!(atom_char),
113+
named!(pub atom<&str>, map_res!(take_while1!(atom_char),
114114
str::from_utf8
115115
));
116116

@@ -124,7 +124,7 @@ named!(pub astring<&[u8]>, alt!(
124124
named!(pub astring_utf8<&str>, map_res!(astring, str::from_utf8));
125125

126126
// text = 1*TEXT-CHAR
127-
named!(pub text<&str>, map_res!(take_while_s!(text_char),
127+
named!(pub text<&str>, map_res!(take_while!(text_char),
128128
str::from_utf8
129129
));
130130

0 commit comments

Comments
 (0)