Skip to content

Commit 67d7fda

Browse files
David Tolnayfacebook-github-bot
authored andcommitted
Update from nom v7 to nom v8
Reviewed By: diliop Differential Revision: D75888825 fbshipit-source-id: b8afcf69334c348301b22d00f67b51f07f468ea4
1 parent 0420db0 commit 67d7fda

File tree

4 files changed

+71
-40
lines changed

4 files changed

+71
-40
lines changed

Cargo.lock

Lines changed: 12 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ itertools = "0.14.0"
2323
log = { version = "0.4.22", features = ["kv_unstable"] }
2424
measure_time = "0.9"
2525
monostate = "0.1.8"
26-
nom = "7.1"
26+
nom = "8"
27+
nom-language = "0.1"
2728
proc-macro2 = { version = "1.0.70", features = ["span-locations"] }
2829
rayon = "1.9.0"
2930
rustsec = "0.30"

src/cfg.rs

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
use nom::IResult;
9+
use nom::Parser;
910
use nom::branch::alt;
1011
use nom::bytes::complete::escaped;
1112
use nom::bytes::complete::tag;
@@ -35,21 +36,31 @@ use unicode_ident::is_xid_start;
3536

3637
use crate::platform::PlatformPredicate;
3738

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+
{
3943
multispace0(i)
4044
}
4145

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)
4451
}
4552

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)
4858
}
4959

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+
{
5364
context(
5465
"string",
5566
preceded(
@@ -59,25 +70,33 @@ fn string<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
5970
char('\"'),
6071
)),
6172
),
62-
)(i)
73+
)
74+
.parse(i)
6375
}
6476

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)
6782
}
6883

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)
7389
}
7490

7591
// Parse an atom comprising one or more hyphen-separated words. Each word
7692
// has a first character that satisfies is_xid_start and the rest satisfy
7793
// is_xid_continue.
7894
//
7995
// 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+
{
81100
preceded(
82101
sp,
83102
recognize(separated_list1(
@@ -87,23 +106,28 @@ fn atom<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, &'a str, E>
87106
many0_count(satisfy(is_xid_continue)),
88107
),
89108
)),
90-
)(i)
109+
)
110+
.parse(i)
91111
}
92112

93113
// Parses: `keyword` '(' inner ')'
94-
fn operator<'a, T, E: ParseError<&'a str> + ContextError<&'a str>>(
114+
fn operator<'a, F>(
95115
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+
{
98121
context(
99122
kw,
100123
preceded(keyword(kw), cut(delimited(sep('('), inner, sep(')')))),
101124
)
102125
}
103126

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+
{
107131
use PlatformPredicate::*;
108132

109133
context(
@@ -126,12 +150,14 @@ fn parse_predicate<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
126150
),
127151
map(atom, |key| Bool { key }),
128152
)),
129-
)(i)
153+
)
154+
.parse(i)
130155
}
131156

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+
{
135161
context(
136162
"cfg",
137163
alt((
@@ -141,7 +167,8 @@ pub(crate) fn parse<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
141167
),
142168
map(atom, |triple| PlatformPredicate::Bool { key: triple }),
143169
)),
144-
)(i)
170+
)
171+
.parse(i)
145172
}
146173

147174
#[cfg(test)]

src/platform.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use std::fmt;
1212
use std::fmt::Debug;
1313
use std::fmt::Display;
1414

15-
use nom::error::VerboseError;
16-
use nom::error::convert_error;
15+
use nom_language::error::VerboseError;
16+
use nom_language::error::convert_error;
1717
use serde::Deserialize;
1818
use serde::Serialize;
1919

0 commit comments

Comments
 (0)