Skip to content

Commit 377c941

Browse files
committed
Update nom to 8.0.0.
1 parent 38f2176 commit 377c941

File tree

7 files changed

+69
-60
lines changed

7 files changed

+69
-60
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ project adheres to
88
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
99

1010

11+
## Unreleased
12+
13+
* Updated `nom` to 8.0.0, and added `nom-language`.
14+
1115
## Release 0.18.0 -- 2025-02-03
1216

1317
* Fixed clippy lints in generated code (PR #143). Thanks @vbrandl!

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ base64 = "0.22.1"
2727
bytecount = "0.6.0"
2828
itertools = "0.14.0"
2929
md5 = "0.7"
30-
nom = "7.1.0"
30+
nom = "8.0.0"
31+
nom-language = "0.1.0"
3132

3233
rsass = { version = "0.29.0", optional = true }
3334
mime = { version = "0.3", optional = true }

src/expression.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ use nom::branch::alt;
33
use nom::bytes::complete::{escaped, is_a, is_not, tag};
44
use nom::character::complete::{alpha1, char, digit1, none_of, one_of};
55
use nom::combinator::{map, map_res, not, opt, recognize, value};
6-
use nom::error::context; //, VerboseError};
6+
use nom::error::context;
77
use nom::multi::{fold_many0, many0, separated_list0};
8-
use nom::sequence::{delimited, pair, preceded, terminated, tuple};
8+
use nom::sequence::{delimited, pair, preceded, terminated};
9+
use nom::Parser as _;
910
use std::str::{from_utf8, Utf8Error};
1011

1112
pub fn expression(input: &[u8]) -> PResult<&str> {
1213
map_res(
1314
recognize(context(
1415
"Expected rust expression",
15-
tuple((
16+
(
1617
map_res(alt((tag("&"), tag("*"), tag(""))), input_to_str),
1718
alt((
1819
rust_name,
@@ -34,10 +35,10 @@ pub fn expression(input: &[u8]) -> PResult<&str> {
3435
|| (),
3536
|_, _| (),
3637
),
37-
)),
38+
),
3839
)),
3940
input_to_str,
40-
)(input)
41+
).parse(input)
4142
}
4243

4344
pub fn input_to_str(s: &[u8]) -> Result<&str, Utf8Error> {
@@ -48,7 +49,7 @@ pub fn comma_expressions(input: &[u8]) -> PResult<String> {
4849
map(
4950
separated_list0(preceded(tag(","), many0(tag(" "))), expression),
5051
|list: Vec<_>| list.join(", "),
51-
)(input)
52+
).parse(input)
5253
}
5354

5455
pub fn rust_name(input: &[u8]) -> PResult<&str> {
@@ -58,14 +59,14 @@ pub fn rust_name(input: &[u8]) -> PResult<&str> {
5859
opt(is_a("_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")),
5960
)),
6061
input_to_str,
61-
)(input)
62+
).parse(input)
6263
}
6364

6465
fn expr_in_parens(input: &[u8]) -> PResult<&str> {
6566
map_res(
6667
recognize(delimited(tag("("), expr_inside_parens, tag(")"))),
6768
input_to_str,
68-
)(input)
69+
).parse(input)
6970
}
7071

7172
fn expr_in_brackets(input: &[u8]) -> PResult<&str> {
@@ -84,7 +85,7 @@ fn expr_in_brackets(input: &[u8]) -> PResult<&str> {
8485
tag("]"),
8586
)),
8687
input_to_str,
87-
)(input)
88+
).parse(input)
8889
}
8990

9091
pub fn expr_in_braces(input: &[u8]) -> PResult<&str> {
@@ -103,7 +104,7 @@ pub fn expr_in_braces(input: &[u8]) -> PResult<&str> {
103104
tag("}"),
104105
)),
105106
input_to_str,
106-
)(input)
107+
).parse(input)
107108
}
108109

109110
pub fn expr_inside_parens(input: &[u8]) -> PResult<&str> {
@@ -118,7 +119,7 @@ pub fn expr_inside_parens(input: &[u8]) -> PResult<&str> {
118119
value((), terminated(tag("/"), none_of("*"))),
119120
)))),
120121
input_to_str,
121-
)(input)
122+
).parse(input)
122123
}
123124

124125
pub fn quoted_string(input: &[u8]) -> PResult<&str> {
@@ -129,7 +130,7 @@ pub fn quoted_string(input: &[u8]) -> PResult<&str> {
129130
char('"'),
130131
)),
131132
input_to_str,
132-
)(input)
133+
).parse(input)
133134
}
134135

135136
pub fn rust_comment(input: &[u8]) -> PResult<&[u8]> {
@@ -140,7 +141,7 @@ pub fn rust_comment(input: &[u8]) -> PResult<&[u8]> {
140141
terminated(tag("*"), not(tag("/"))),
141142
)))),
142143
tag("*/"),
143-
)(input)
144+
).parse(input)
144145
}
145146

146147
#[cfg(test)]

src/parseresult.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use nom::error::{VerboseError, VerboseErrorKind};
1+
use nom_language::error::{VerboseError, VerboseErrorKind};
22
use nom::{Err, IResult};
33
use std::io::Write;
44
use std::str::from_utf8;

src/spacelike.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ use nom::character::complete::{multispace1, none_of};
55
use nom::combinator::{map, value};
66
use nom::multi::many0;
77
use nom::sequence::preceded;
8+
use nom::Parser as _;
89

910
pub fn spacelike(input: &[u8]) -> PResult<()> {
10-
map(many0(alt((comment, map(multispace1, |_| ())))), |_| ())(input)
11+
map(many0(alt((comment, map(multispace1, |_| ())))), |_| ()).parse(input)
1112
}
1213

1314
pub fn comment(input: &[u8]) -> PResult<()> {
14-
preceded(tag("@*"), comment_tail)(input)
15+
preceded(tag("@*"), comment_tail).parse(input)
1516
}
1617

1718
pub fn comment_tail(input: &[u8]) -> PResult<()> {
@@ -21,14 +22,14 @@ pub fn comment_tail(input: &[u8]) -> PResult<()> {
2122
value((), preceded(tag("*"), none_of("@"))),
2223
))),
2324
value((), tag("*@")),
24-
)(input)
25+
).parse(input)
2526
}
2627

2728
#[cfg(test)]
2829
mod test {
2930
use super::{comment, spacelike};
30-
use nom::error::{ErrorKind, VerboseError, VerboseErrorKind};
31-
use nom::Err;
31+
use nom_language::error::{VerboseError, VerboseErrorKind};
32+
use nom::{error::ErrorKind, Err};
3233

3334
#[test]
3435
fn comment1() {

src/template.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use nom::character::complete::{char, multispace0};
1010
use nom::combinator::{map, map_res, opt, recognize};
1111
use nom::error::context;
1212
use nom::multi::{many0, many_till, separated_list0, separated_list1};
13-
use nom::sequence::{delimited, preceded, terminated, tuple};
13+
use nom::sequence::{delimited, preceded, terminated};
14+
use nom::Parser as _;
1415
use std::io::{self, Write};
1516

1617
#[derive(Debug, PartialEq, Eq)]
@@ -62,7 +63,7 @@ impl Template {
6263

6364
pub fn template(input: &[u8]) -> PResult<Template> {
6465
map(
65-
tuple((
66+
(
6667
spacelike,
6768
many0(map(
6869
delimited(
@@ -114,21 +115,21 @@ pub fn template(input: &[u8]) -> PResult<Template> {
114115
),
115116
end_of_file,
116117
),
117-
)),
118+
),
118119
|((), preamble, _, type_args, args, body)| Template {
119120
preamble,
120121
type_args: type_args.map(String::from).unwrap_or_default(),
121122
args,
122123
body: body.0,
123124
},
124-
)(input)
125+
).parse(input)
125126
}
126127

127128
fn end_of_file(input: &[u8]) -> PResult<()> {
128129
if input.is_empty() {
129130
Ok((input, ()))
130131
} else {
131-
use nom::error::{VerboseError, VerboseErrorKind};
132+
use nom_language::error::{VerboseError, VerboseErrorKind};
132133
Err(nom::Err::Error(VerboseError {
133134
errors: vec![(input, VerboseErrorKind::Context("end of file"))],
134135
}))
@@ -137,20 +138,20 @@ fn end_of_file(input: &[u8]) -> PResult<()> {
137138

138139
fn formal_argument(input: &[u8]) -> PResult<&str> {
139140
map_res(
140-
recognize(tuple((
141+
recognize((
141142
rust_name,
142143
spacelike,
143144
char(':'),
144145
spacelike,
145146
type_expression,
146-
))),
147+
)),
147148
input_to_str,
148-
)(input)
149+
).parse(input)
149150
}
150151

151152
fn type_expression(input: &[u8]) -> PResult<()> {
152153
map(
153-
tuple((
154+
(
154155
alt((tag("&"), tag(""))),
155156
opt(lifetime),
156157
delimited(
@@ -173,9 +174,9 @@ fn type_expression(input: &[u8]) -> PResult<()> {
173174
)),
174175
),
175176
opt(delimited(tag("<"), comma_type_expressions, tag(">"))),
176-
)),
177+
),
177178
|_| (),
178-
)(input)
179+
).parse(input)
179180
}
180181

181182
pub fn comma_type_expressions(input: &[u8]) -> PResult<()> {
@@ -188,11 +189,11 @@ pub fn comma_type_expressions(input: &[u8]) -> PResult<()> {
188189
opt(preceded(tag(","), multispace0)),
189190
),
190191
|_| (),
191-
)(input)
192+
).parse(input)
192193
}
193194

194195
fn lifetime(input: &[u8]) -> PResult<()> {
195-
map(delimited(spacelike, tag("'"), rust_name), |_| ())(input)
196+
map(delimited(spacelike, tag("'"), rust_name), |_| ()).parse(input)
196197
}
197198

198199
#[cfg(test)]

0 commit comments

Comments
 (0)