Skip to content

Commit 98e5db8

Browse files
authored
generator: Bump nom to 8.0.0 (#987)
The main change is that we now have to call .parse(i) instead of the previous closure-based (i) call.
1 parent a5c4ca2 commit 98e5db8

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

generator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ publish = false
1212
bindgen = "=0.69.4"
1313
heck = "0.5"
1414
itertools = "0.14"
15-
nom = "7.1"
15+
nom = "8"
1616
once_cell = "1.7"
1717
proc-macro2 = "1.0"
1818
quote = "1.0"

generator/src/lib.rs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use nom::{
1818
},
1919
combinator::{map, map_res, opt, value},
2020
multi::{many1, separated_list1},
21-
sequence::{delimited, pair, preceded, separated_pair, terminated, tuple},
21+
sequence::{delimited, pair, preceded, separated_pair, terminated},
2222
IResult, Parser,
2323
};
2424
use once_cell::sync::Lazy;
@@ -84,7 +84,7 @@ impl quote::ToTokens for CType {
8484
}
8585

8686
fn parse_ctype(i: &str) -> IResult<&str, CType> {
87-
(alt((value(CType::U64, tag("ULL")), value(CType::U32, tag("U")))))(i)
87+
(alt((value(CType::U64, tag("ULL")), value(CType::U32, tag("U"))))).parse(i)
8888
}
8989

9090
fn parse_cexpr(i: &str) -> IResult<&str, (CType, String)> {
@@ -93,11 +93,12 @@ fn parse_cexpr(i: &str) -> IResult<&str, (CType, String)> {
9393
parse_inverse_number,
9494
parse_decimal_number,
9595
parse_hexadecimal_number,
96-
)))(i)
96+
)))
97+
.parse(i)
9798
}
9899

99100
fn parse_cfloat(i: &str) -> IResult<&str, f32> {
100-
(terminated(nom::number::complete::float, one_of("fF")))(i)
101+
(terminated(nom::number::complete::float, one_of("fF"))).parse(i)
101102
}
102103

103104
fn parse_inverse_number(i: &str) -> IResult<&str, (CType, String)> {
@@ -118,7 +119,8 @@ fn parse_inverse_number(i: &str) -> IResult<&str, (CType, String)> {
118119
};
119120
(ctyp, expr)
120121
},
121-
))(i)
122+
))
123+
.parse(i)
122124
}
123125

124126
// Like a C string, but does not support quote escaping and expects at least one character.
@@ -130,21 +132,24 @@ fn parse_c_include_string(i: &str) -> IResult<&str, String> {
130132
c.iter().map(char::to_string).join("")
131133
}),
132134
char('"'),
133-
))(i)
135+
))
136+
.parse(i)
134137
}
135138

136139
fn parse_c_include(i: &str) -> IResult<&str, String> {
137140
(preceded(
138141
tag("#include"),
139142
preceded(multispace1, parse_c_include_string),
140-
))(i)
143+
))
144+
.parse(i)
141145
}
142146

143147
fn parse_decimal_number(i: &str) -> IResult<&str, (CType, String)> {
144148
(map(
145149
pair(digit1.map(str::to_string), parse_ctype),
146150
|(dig, ctype)| (ctype, dig),
147-
))(i)
151+
))
152+
.parse(i)
148153
}
149154

150155
fn parse_hexadecimal_number(i: &str) -> IResult<&str, (CType, String)> {
@@ -156,23 +161,25 @@ fn parse_hexadecimal_number(i: &str) -> IResult<&str, (CType, String)> {
156161
format!("0x{}{}", num.to_ascii_lowercase(), typ.to_string()),
157162
)
158163
}),
159-
))(i)
164+
))
165+
.parse(i)
160166
}
161167

162168
fn parse_c_identifier(i: &str) -> IResult<&str, &str> {
163-
take_while1(|c: char| c == '_' || c.is_alphanumeric())(i)
169+
take_while1(|c: char| c == '_' || c.is_alphanumeric()).parse(i)
164170
}
165171

166172
fn parse_comment_suffix(i: &str) -> IResult<&str, Option<&str>> {
167-
opt(delimited(tag("//"), take_until("\n"), newline))(i)
173+
opt(delimited(tag("//"), take_until("\n"), newline)).parse(i)
168174
}
169175

170176
fn parse_parameter_names(i: &str) -> IResult<&str, Vec<&str>> {
171177
delimited(
172178
char('('),
173179
separated_list1(tag(", "), parse_c_identifier),
174180
char(')'),
175-
)(i)
181+
)
182+
.parse(i)
176183
}
177184

178185
/// Parses a C macro define optionally prefixed by a comment and optionally
@@ -185,7 +192,8 @@ fn parse_c_define_header(i: &str) -> IResult<&str, (Option<&str>, (&str, Option<
185192
tag("#define "),
186193
pair(parse_c_identifier, opt(parse_parameter_names)),
187194
),
188-
))(i)
195+
))
196+
.parse(i)
189197
}
190198

191199
#[derive(Debug)]
@@ -208,11 +216,11 @@ struct CParameterType<'a> {
208216
fn parse_c_type(i: &str) -> IResult<&str, CParameterType<'_>> {
209217
(map(
210218
separated_pair(
211-
tuple((
219+
(
212220
opt(tag("const ")),
213221
preceded(opt(tag("struct ")), parse_c_identifier),
214222
opt(char('*')),
215-
)),
223+
),
216224
multispace0,
217225
opt(pair(opt(tag("const")), char('*'))),
218226
),
@@ -236,7 +244,8 @@ fn parse_c_type(i: &str) -> IResult<&str, CParameterType<'_>> {
236244
(None, Some(_)) => unreachable!(),
237245
},
238246
},
239-
))(i)
247+
))
248+
.parse(i)
240249
}
241250

242251
#[derive(Debug)]
@@ -268,7 +277,8 @@ fn parse_c_parameter(i: &str) -> IResult<&str, CParameter<'_>> {
268277
_name: name,
269278
static_array,
270279
},
271-
))(i)
280+
))
281+
.parse(i)
272282
}
273283

274284
fn khronos_link<S: Display + ?Sized>(name: &S) -> Literal {

0 commit comments

Comments
 (0)