Skip to content

Commit e782876

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

File tree

8 files changed

+102
-62
lines changed

8 files changed

+102
-62
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- stable
1515
- 1.75.0
1616
- 1.67.1
17-
- 1.63.0
17+
- 1.65.0
1818
- beta
1919
- nightly
2020
steps:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ 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+
* MSRV is now 1.65.0, as required by `nom` 8.0.
15+
16+
1117
## Release 0.18.0 -- 2025-02-03
1218

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

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ keywords = ["web", "templating", "template", "html"]
1010
categories = ["template-engine", "web-programming"]
1111
license = "MIT OR Apache-2.0"
1212
edition = "2021"
13-
rust-version = "1.63.0"
13+
rust-version = "1.65.0"
1414

1515
[features]
1616
sass = ["dep:rsass"]
@@ -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: 22 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,11 @@ pub fn expression(input: &[u8]) -> PResult<&str> {
3435
|| (),
3536
|_, _| (),
3637
),
37-
)),
38+
),
3839
)),
3940
input_to_str,
40-
)(input)
41+
)
42+
.parse(input)
4143
}
4244

4345
pub fn input_to_str(s: &[u8]) -> Result<&str, Utf8Error> {
@@ -48,7 +50,8 @@ pub fn comma_expressions(input: &[u8]) -> PResult<String> {
4850
map(
4951
separated_list0(preceded(tag(","), many0(tag(" "))), expression),
5052
|list: Vec<_>| list.join(", "),
51-
)(input)
53+
)
54+
.parse(input)
5255
}
5356

5457
pub fn rust_name(input: &[u8]) -> PResult<&str> {
@@ -58,14 +61,15 @@ pub fn rust_name(input: &[u8]) -> PResult<&str> {
5861
opt(is_a("_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")),
5962
)),
6063
input_to_str,
61-
)(input)
64+
).parse(input)
6265
}
6366

6467
fn expr_in_parens(input: &[u8]) -> PResult<&str> {
6568
map_res(
6669
recognize(delimited(tag("("), expr_inside_parens, tag(")"))),
6770
input_to_str,
68-
)(input)
71+
)
72+
.parse(input)
6973
}
7074

7175
fn expr_in_brackets(input: &[u8]) -> PResult<&str> {
@@ -84,7 +88,8 @@ fn expr_in_brackets(input: &[u8]) -> PResult<&str> {
8488
tag("]"),
8589
)),
8690
input_to_str,
87-
)(input)
91+
)
92+
.parse(input)
8893
}
8994

9095
pub fn expr_in_braces(input: &[u8]) -> PResult<&str> {
@@ -103,7 +108,8 @@ pub fn expr_in_braces(input: &[u8]) -> PResult<&str> {
103108
tag("}"),
104109
)),
105110
input_to_str,
106-
)(input)
111+
)
112+
.parse(input)
107113
}
108114

109115
pub fn expr_inside_parens(input: &[u8]) -> PResult<&str> {
@@ -118,7 +124,8 @@ pub fn expr_inside_parens(input: &[u8]) -> PResult<&str> {
118124
value((), terminated(tag("/"), none_of("*"))),
119125
)))),
120126
input_to_str,
121-
)(input)
127+
)
128+
.parse(input)
122129
}
123130

124131
pub fn quoted_string(input: &[u8]) -> PResult<&str> {
@@ -129,7 +136,8 @@ pub fn quoted_string(input: &[u8]) -> PResult<&str> {
129136
char('"'),
130137
)),
131138
input_to_str,
132-
)(input)
139+
)
140+
.parse(input)
133141
}
134142

135143
pub fn rust_comment(input: &[u8]) -> PResult<&[u8]> {
@@ -140,7 +148,8 @@ pub fn rust_comment(input: &[u8]) -> PResult<&[u8]> {
140148
terminated(tag("*"), not(tag("/"))),
141149
)))),
142150
tag("*/"),
143-
)(input)
151+
)
152+
.parse(input)
144153
}
145154

146155
#[cfg(test)]

src/parseresult.rs

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

src/spacelike.rs

Lines changed: 7 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,15 @@ pub fn comment_tail(input: &[u8]) -> PResult<()> {
2122
value((), preceded(tag("*"), none_of("@"))),
2223
))),
2324
value((), tag("*@")),
24-
)(input)
25+
)
26+
.parse(input)
2527
}
2628

2729
#[cfg(test)]
2830
mod test {
2931
use super::{comment, spacelike};
30-
use nom::error::{ErrorKind, VerboseError, VerboseErrorKind};
31-
use nom::Err;
32+
use nom::{error::ErrorKind, Err};
33+
use nom_language::error::{VerboseError, VerboseErrorKind};
3234

3335
#[test]
3436
fn comment1() {

src/template.rs

Lines changed: 18 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,22 @@ 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+
)
126+
.parse(input)
125127
}
126128

127129
fn end_of_file(input: &[u8]) -> PResult<()> {
128130
if input.is_empty() {
129131
Ok((input, ()))
130132
} else {
131-
use nom::error::{VerboseError, VerboseErrorKind};
133+
use nom_language::error::{VerboseError, VerboseErrorKind};
132134
Err(nom::Err::Error(VerboseError {
133135
errors: vec![(input, VerboseErrorKind::Context("end of file"))],
134136
}))
@@ -137,20 +139,21 @@ fn end_of_file(input: &[u8]) -> PResult<()> {
137139

138140
fn formal_argument(input: &[u8]) -> PResult<&str> {
139141
map_res(
140-
recognize(tuple((
142+
recognize((
141143
rust_name,
142144
spacelike,
143145
char(':'),
144146
spacelike,
145147
type_expression,
146-
))),
148+
)),
147149
input_to_str,
148-
)(input)
150+
)
151+
.parse(input)
149152
}
150153

151154
fn type_expression(input: &[u8]) -> PResult<()> {
152155
map(
153-
tuple((
156+
(
154157
alt((tag("&"), tag(""))),
155158
opt(lifetime),
156159
delimited(
@@ -173,9 +176,10 @@ fn type_expression(input: &[u8]) -> PResult<()> {
173176
)),
174177
),
175178
opt(delimited(tag("<"), comma_type_expressions, tag(">"))),
176-
)),
179+
),
177180
|_| (),
178-
)(input)
181+
)
182+
.parse(input)
179183
}
180184

181185
pub fn comma_type_expressions(input: &[u8]) -> PResult<()> {
@@ -188,11 +192,12 @@ pub fn comma_type_expressions(input: &[u8]) -> PResult<()> {
188192
opt(preceded(tag(","), multispace0)),
189193
),
190194
|_| (),
191-
)(input)
195+
)
196+
.parse(input)
192197
}
193198

194199
fn lifetime(input: &[u8]) -> PResult<()> {
195-
map(delimited(spacelike, tag("'"), rust_name), |_| ())(input)
200+
map(delimited(spacelike, tag("'"), rust_name), |_| ()).parse(input)
196201
}
197202

198203
#[cfg(test)]

0 commit comments

Comments
 (0)