6
6
*/
7
7
8
8
use nom:: IResult ;
9
+ use nom:: Parser ;
9
10
use nom:: branch:: alt;
10
11
use nom:: bytes:: complete:: escaped;
11
12
use nom:: bytes:: complete:: tag;
@@ -35,21 +36,31 @@ use unicode_ident::is_xid_start;
35
36
36
37
use crate :: platform:: PlatformPredicate ;
37
38
38
- fn sp < ' a , E : ParseError < & ' a str > > ( i : & ' a str ) -> IResult < & ' a str , & ' a str , E > {
39
+ fn sp < ' a , E > ( i : & ' a str ) -> IResult < & ' a str , & ' a str , E >
40
+ where
41
+ E : ParseError < & ' a str > ,
42
+ {
39
43
multispace0 ( i)
40
44
}
41
45
42
- fn graphic < ' a , E : ParseError < & ' a str > > ( i : & ' a str ) -> IResult < & ' a str , & ' a str , E > {
43
- take_while1 ( |c : char | c. is_ascii_graphic ( ) && !( c == '\\' || c == '"' ) ) ( i)
46
+ fn graphic < ' a , E > ( i : & ' a str ) -> IResult < & ' a str , & ' a str , E >
47
+ where
48
+ E : ParseError < & ' a str > ,
49
+ {
50
+ take_while1 ( |c : char | c. is_ascii_graphic ( ) && !( c == '\\' || c == '"' ) ) . parse ( i)
44
51
}
45
52
46
- fn parse_str < ' a , E : ParseError < & ' a str > > ( i : & ' a str ) -> IResult < & ' a str , & ' a str , E > {
47
- escaped ( graphic, '\\' , one_of ( r#"n"\"# ) ) ( i)
53
+ fn parse_str < ' a , E > ( i : & ' a str ) -> IResult < & ' a str , & ' a str , E >
54
+ where
55
+ E : ParseError < & ' a str > ,
56
+ {
57
+ escaped ( graphic, '\\' , one_of ( r#"n"\"# ) ) . parse ( i)
48
58
}
49
59
50
- fn string < ' a , E : ParseError < & ' a str > + ContextError < & ' a str > > (
51
- i : & ' a str ,
52
- ) -> IResult < & ' a str , & ' a str , E > {
60
+ fn string < ' a , E > ( i : & ' a str ) -> IResult < & ' a str , & ' a str , E >
61
+ where
62
+ E : ParseError < & ' a str > + ContextError < & ' a str > ,
63
+ {
53
64
context (
54
65
"string" ,
55
66
preceded (
@@ -59,25 +70,33 @@ fn string<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
59
70
char ( '\"' ) ,
60
71
) ) ,
61
72
) ,
62
- ) ( i)
73
+ )
74
+ . parse ( i)
63
75
}
64
76
65
- fn sep < ' a , E : ParseError < & ' a str > > ( sep : char ) -> impl FnMut ( & ' a str ) -> IResult < & ' a str , ( ) , E > {
66
- map ( preceded ( sp, char ( sep) ) , |_| ( ) )
77
+ fn sep < ' a , E > ( sep : char ) -> impl Parser < & ' a str , Output = ( ) , Error = E >
78
+ where
79
+ E : ParseError < & ' a str > ,
80
+ {
81
+ map ( preceded ( sp, char ( sep) ) , drop)
67
82
}
68
83
69
- fn keyword < ' a , E : ParseError < & ' a str > > (
70
- kw : & ' static str ,
71
- ) -> impl FnMut ( & ' a str ) -> IResult < & ' a str , ( ) , E > {
72
- map ( verify ( atom, move |s : & str | s == kw) , |_| ( ) )
84
+ fn keyword < ' a , E > ( kw : & ' static str ) -> impl Parser < & ' a str , Output = ( ) , Error = E >
85
+ where
86
+ E : ParseError < & ' a str > ,
87
+ {
88
+ map ( verify ( atom, move |s : & str | s == kw) , drop)
73
89
}
74
90
75
91
// Parse an atom comprising one or more hyphen-separated words. Each word
76
92
// has a first character that satisfies is_xid_start and the rest satisfy
77
93
// is_xid_continue.
78
94
//
79
95
// For example `target_os` or `x86_64-unknown-linux-gnu`
80
- fn atom < ' a , E : ParseError < & ' a str > > ( i : & ' a str ) -> IResult < & ' a str , & ' a str , E > {
96
+ fn atom < ' a , E > ( i : & ' a str ) -> IResult < & ' a str , & ' a str , E >
97
+ where
98
+ E : ParseError < & ' a str > ,
99
+ {
81
100
preceded (
82
101
sp,
83
102
recognize ( separated_list1 (
@@ -87,23 +106,28 @@ fn atom<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, &'a str, E>
87
106
many0_count ( satisfy ( is_xid_continue) ) ,
88
107
) ,
89
108
) ) ,
90
- ) ( i)
109
+ )
110
+ . parse ( i)
91
111
}
92
112
93
113
// Parses: `keyword` '(' inner ')'
94
- fn operator < ' a , T , E : ParseError < & ' a str > + ContextError < & ' a str > > (
114
+ fn operator < ' a , F > (
95
115
kw : & ' static str ,
96
- inner : impl FnMut ( & ' a str ) -> IResult < & ' a str , T , E > ,
97
- ) -> impl FnMut ( & ' a str ) -> IResult < & ' a str , T , E > {
116
+ inner : F ,
117
+ ) -> impl Parser < & ' a str , Output = F :: Output , Error = F :: Error >
118
+ where
119
+ F : Parser < & ' a str , Error : ContextError < & ' a str > > ,
120
+ {
98
121
context (
99
122
kw,
100
123
preceded ( keyword ( kw) , cut ( delimited ( sep ( '(' ) , inner, sep ( ')' ) ) ) ) ,
101
124
)
102
125
}
103
126
104
- fn parse_predicate < ' a , E : ParseError < & ' a str > + ContextError < & ' a str > > (
105
- i : & ' a str ,
106
- ) -> IResult < & ' a str , PlatformPredicate < ' a > , E > {
127
+ fn parse_predicate < ' a , E > ( i : & ' a str ) -> IResult < & ' a str , PlatformPredicate < ' a > , E >
128
+ where
129
+ E : ParseError < & ' a str > + ContextError < & ' a str > ,
130
+ {
107
131
use PlatformPredicate :: * ;
108
132
109
133
context (
@@ -126,12 +150,14 @@ fn parse_predicate<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
126
150
) ,
127
151
map ( atom, |key| Bool { key } ) ,
128
152
) ) ,
129
- ) ( i)
153
+ )
154
+ . parse ( i)
130
155
}
131
156
132
- pub ( crate ) fn parse < ' a , E : ParseError < & ' a str > + ContextError < & ' a str > > (
133
- i : & ' a str ,
134
- ) -> IResult < & ' a str , PlatformPredicate < ' a > , E > {
157
+ pub ( crate ) fn parse < ' a , E > ( i : & ' a str ) -> IResult < & ' a str , PlatformPredicate < ' a > , E >
158
+ where
159
+ E : ParseError < & ' a str > + ContextError < & ' a str > ,
160
+ {
135
161
context (
136
162
"cfg" ,
137
163
alt ( (
@@ -141,7 +167,8 @@ pub(crate) fn parse<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
141
167
) ,
142
168
map ( atom, |triple| PlatformPredicate :: Bool { key : triple } ) ,
143
169
) ) ,
144
- ) ( i)
170
+ )
171
+ . parse ( i)
145
172
}
146
173
147
174
#[ cfg( test) ]
0 commit comments