Skip to content

Commit 4ee09dc

Browse files
Bump nom from 7.1.3 to 8.0.0 (#1570)
* Bump nom from 7.1.3 to 8.0.0 Bumps [nom](https://github.com/rust-bakery/nom) from 7.1.3 to 8.0.0. - [Changelog](https://github.com/rust-bakery/nom/blob/main/CHANGELOG.md) - [Commits](rust-bakery/nom@7.1.3...8.0.0) --- updated-dependencies: - dependency-name: nom dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Add nom-language dependency and update imports to point at it. * Use Parser::parse instead of function call syntax. * Fix function signatures of ws() functions * Don't use tuple() * Import nom::Input * Don't import InputTakeAtPosition * Fix dependency ordering --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Mathew Horner <mhorner@veracode.com>
1 parent 5784966 commit 4ee09dc

16 files changed

Lines changed: 151 additions & 128 deletions

File tree

Cargo.lock

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lockfile/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ anyhow = "1.0.44"
1515
ignore = "0.4.20"
1616
lockfile_generator = { path = "../lockfile_generator", optional = true }
1717
log = "0.4.6"
18-
nom = "7.1.1"
18+
nom = "8.0.0"
19+
nom-language = "0.1.0"
1920
phylum_types = { git = "https://github.com/phylum-dev/phylum-types", branch = "development" }
2021
purl = "0.1.1"
2122
quick-xml = { version = "0.37.1", features = [

lockfile/src/golang.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use anyhow::{anyhow, Context};
66
use lockfile_generator::go::Go as GoGenerator;
77
#[cfg(feature = "generator")]
88
use lockfile_generator::Generator;
9-
use nom::error::convert_error;
109
use nom::Finish;
10+
use nom_language::error::convert_error;
1111

1212
use crate::parsers::{go_mod, go_sum};
1313
use crate::{Package, Parse};

lockfile/src/java.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use lockfile_generator::gradle::Gradle as GradleGenerator;
88
use lockfile_generator::maven::Maven as MavenGenerator;
99
#[cfg(feature = "generator")]
1010
use lockfile_generator::Generator;
11-
use nom::error::convert_error;
1211
use nom::Finish;
12+
use nom_language::error::convert_error;
1313
use phylum_types::ecosystems::maven::{Dependency, Plugin, Project};
1414
use phylum_types::types::package::PackageType;
1515
use serde::Deserialize;

lockfile/src/javascript.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use lockfile_generator::yarn::Yarn as YarnGenerator;
1313
#[cfg(feature = "generator")]
1414
use lockfile_generator::Generator;
1515
use log::debug;
16-
use nom::error::convert_error;
1716
use nom::Finish;
17+
use nom_language::error::convert_error;
1818
use phylum_types::types::package::PackageType;
1919
use serde::Deserialize;
2020
use serde_json::Value as JsonValue;

lockfile/src/parsers/gem.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use nom::branch::alt;
22
use nom::bytes::complete::{tag, take_until};
33
use nom::character::complete::{line_ending, not_line_ending, satisfy, space0};
44
use nom::combinator::{opt, recognize};
5-
use nom::error::{VerboseError, VerboseErrorKind};
65
use nom::multi::{many1, many_till};
7-
use nom::sequence::{delimited, tuple};
8-
use nom::Err as NomErr;
6+
use nom::sequence::delimited;
7+
use nom::{Err as NomErr, Parser};
8+
use nom_language::error::{VerboseError, VerboseErrorKind};
99
use phylum_types::types::package::PackageType;
1010

1111
use crate::parsers::{take_till_blank_line, IResult};
@@ -36,7 +36,8 @@ impl<'a> Section<'a> {
3636
let (new_input, consumed) = recognize(many_till(
3737
take_till_line_end,
3838
alt((tag("GEM"), tag("GIT"), tag("PATH"), tag("BUNDLED WITH"))),
39-
))(input)?;
39+
))
40+
.parse(input)?;
4041

4142
// Check for type of section head.
4243
let section_type = if consumed.ends_with("GEM") {
@@ -193,10 +194,8 @@ fn revision(input: &str) -> IResult<&str, &str> {
193194
}
194195

195196
fn specs(input: &str) -> IResult<&str, &str> {
196-
recognize(many_till(
197-
take_till_line_end,
198-
recognize(tuple((space0, tag("specs:"), opt(line_ending)))),
199-
))(input)
197+
recognize(many_till(take_till_line_end, recognize((space0, tag("specs:"), opt(line_ending)))))
198+
.parse(input)
200199
}
201200

202201
fn package(input: &str) -> Result<Option<SpecsPackage>, NomErr<VerboseError<&str>>> {
@@ -219,8 +218,8 @@ fn package(input: &str) -> Result<Option<SpecsPackage>, NomErr<VerboseError<&str
219218
}
220219

221220
fn package_name(input: &str) -> IResult<&str, &str> {
222-
let (input, _) = recognize(space0)(input)?;
223-
recognize(alt((take_until(" "), not_line_ending)))(input)
221+
let (input, _) = recognize(space0).parse(input)?;
222+
recognize(alt((take_until(" "), not_line_ending))).parse(input)
224223
}
225224

226225
/// Parser allowing for loose `(>= 1.2.0, < 2.0, != 1.2.3)` and strict
@@ -238,27 +237,29 @@ fn loose_package_version(input: &str) -> IResult<&str, &str> {
238237
c.is_ascii_alphanumeric() || LOOSE_VERSION_CHARS.contains(&c)
239238
}))),
240239
tag(")"),
241-
)(input)
240+
)
241+
.parse(input)
242242
}
243243

244244
/// Parser allowing only strict `1.2.3.alpha.1` versions.
245245
fn strict_package_version(input: &str) -> IResult<&str, &str> {
246246
let (input, _) = space0(input)?;
247247
recognize(many1(satisfy(|c: char| {
248248
c.is_ascii_alphanumeric() || STRICT_VERSION_CHARS.contains(&c)
249-
})))(input)
249+
})))
250+
.parse(input)
250251
}
251252

252253
/// Get the value for a key in a ` key: value` line.
253254
fn key<'a>(input: &'a str, key: &str) -> IResult<&'a str, &'a str> {
254-
let (input, _key) = recognize(tuple((space0, tag(key), tag(": "))))(input)?;
255+
let (input, _key) = recognize((space0, tag(key), tag(": "))).parse(input)?;
255256
take_till_line_end(input)
256257
}
257258

258259
/// Take everything until a line end, swallowing the line end character
259260
/// completely.
260261
fn take_till_line_end(input: &str) -> IResult<&str, &str> {
261-
let (input, consumed) = recognize(alt((take_until("\n"), take_until("\r\n"))))(input)?;
262-
let (input, _) = alt((tag("\n"), tag("\r\n")))(input)?;
262+
let (input, consumed) = recognize(alt((take_until("\n"), take_until("\r\n")))).parse(input)?;
263+
let (input, _) = alt((tag("\n"), tag("\r\n"))).parse(input)?;
263264
Ok((input, consumed))
264265
}

lockfile/src/parsers/go_mod.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use nom::bytes::complete::{tag, take_till, take_till1, take_while};
55
use nom::character::complete::{char, multispace0, space0, space1};
66
use nom::combinator::{map, opt};
77
use nom::multi::many0;
8-
use nom::sequence::{delimited, preceded, tuple};
9-
use nom::IResult;
8+
use nom::sequence::{delimited, preceded};
9+
use nom::{IResult, Parser};
1010

1111
use crate::golang::GoDeps;
1212
use crate::{Package, PackageType, PackageVersion};
@@ -68,7 +68,7 @@ impl From<ModuleReplacement> for Package {
6868
}
6969

7070
pub fn parse(input: &str) -> IResult<&str, GoDeps> {
71-
let (_, directives) = many0(directive)(input)?;
71+
let (_, directives) = many0(directive).parse(input)?;
7272

7373
let mut required: Vec<Module> = Vec::new();
7474
let mut excluded: Vec<Module> = Vec::new();
@@ -126,28 +126,26 @@ pub fn parse(input: &str) -> IResult<&str, GoDeps> {
126126

127127
fn directive(input: &str) -> IResult<&str, Directive<'_>> {
128128
let (input, _) = take_while(|c: char| c == '\n')(input)?;
129-
alt((module_directive, go_directive, require_directive, replace_directive, exclude_directive))(
130-
input.trim(),
131-
)
129+
alt((module_directive, go_directive, require_directive, replace_directive, exclude_directive))
130+
.parse(input.trim())
132131
}
133132

134133
fn module_directive(input: &str) -> IResult<&str, Directive<'_>> {
135134
let (input, module_name) =
136-
preceded(tuple((tag("module"), space1)), take_till(|c| c == '\n'))(input)?;
135+
preceded((tag("module"), space1), take_till(|c| c == '\n')).parse(input)?;
137136
Ok((input, Directive::Module(module_name)))
138137
}
139138

140139
fn go_directive(input: &str) -> IResult<&str, Directive<'_>> {
141140
let (input, go_version) =
142-
preceded(tuple((tag("go"), space1)), take_till(|c| c == '\n'))(input)?;
141+
preceded((tag("go"), space1), take_till(|c| c == '\n')).parse(input)?;
143142
Ok((input, Directive::Go(go_version.trim())))
144143
}
145144

146145
fn require_directive(input: &str) -> IResult<&str, Directive<'_>> {
147-
let (input, deps) = preceded(
148-
tuple((tag("require"), space1)),
149-
alt((module_block, map(require_spec, |r| vec![r]))),
150-
)(input)?;
146+
let (input, deps) =
147+
preceded((tag("require"), space1), alt((module_block, map(require_spec, |r| vec![r]))))
148+
.parse(input)?;
151149
Ok((input, Directive::Require(deps)))
152150
}
153151

@@ -158,7 +156,8 @@ fn require_spec(input: &str) -> IResult<&str, Module> {
158156
let (input, _) = space0(input)?;
159157

160158
// Check if there is a comment starting with "//".
161-
let (input, comments) = opt(preceded(tag("//"), take_till1(|c: char| c == '\n')))(input)?;
159+
let (input, comments) =
160+
opt(preceded(tag("//"), take_till1(|c: char| c == '\n'))).parse(input)?;
162161

163162
// Determine if the comment indicates the module is indirect.
164163
let indirect = comments.is_some_and(|s: &str| s.trim().eq("indirect"));
@@ -168,10 +167,9 @@ fn require_spec(input: &str) -> IResult<&str, Module> {
168167
}
169168

170169
fn replace_directive(input: &str) -> IResult<&str, Directive<'_>> {
171-
preceded(tuple((tag("replace"), space1)), alt((replace_block, map(replace_spec, |r| vec![r]))))(
172-
input,
173-
)
174-
.map(|(next_input, reps)| (next_input, Directive::Replace(reps)))
170+
preceded((tag("replace"), space1), alt((replace_block, map(replace_spec, |r| vec![r]))))
171+
.parse(input)
172+
.map(|(next_input, reps)| (next_input, Directive::Replace(reps)))
175173
}
176174

177175
fn replace_spec(input: &str) -> IResult<&str, ModuleReplacement> {
@@ -187,13 +185,14 @@ fn replace_spec(input: &str) -> IResult<&str, ModuleReplacement> {
187185
};
188186

189187
// Consume "=>" with surrounding spaces.
190-
let (input, _) = tuple((space1, tag("=>"), space1))(input)?;
188+
let (input, _) = (space1, tag("=>"), space1).parse(input)?;
191189

192190
// Parse the destination path and optional version.
193-
let (input, (dest_path, dest_version)) = tuple((
191+
let (input, (dest_path, dest_version)) = (
194192
take_till1(|c: char| c.is_whitespace()),
195193
opt(preceded(space1, take_till1(|c: char| c.is_whitespace()))),
196-
))(input)?;
194+
)
195+
.parse(input)?;
197196

198197
let replacement = if let Some(version) = dest_version {
199198
Replacement::Module(Module {
@@ -213,10 +212,9 @@ fn replace_spec(input: &str) -> IResult<&str, ModuleReplacement> {
213212
}
214213

215214
fn exclude_directive(input: &str) -> IResult<&str, Directive<'_>> {
216-
preceded(tuple((tag("exclude"), space1)), alt((module_block, map(require_spec, |r| vec![r]))))(
217-
input,
218-
)
219-
.map(|(next_input, deps)| (next_input, Directive::Exclude(deps)))
215+
preceded((tag("exclude"), space1), alt((module_block, map(require_spec, |r| vec![r]))))
216+
.parse(input)
217+
.map(|(next_input, deps)| (next_input, Directive::Exclude(deps)))
220218
}
221219

222220
fn parse_block<T, F>(input: &str, line_parser: F) -> IResult<&str, Vec<T>>
@@ -227,7 +225,8 @@ where
227225
char('('),
228226
many0(preceded(multispace0, line_parser)),
229227
preceded(multispace0, char(')')),
230-
)(input)
228+
)
229+
.parse(input)
231230
}
232231

233232
fn module_block(input: &str) -> IResult<&str, Vec<Module>> {

lockfile/src/parsers/go_sum.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ use nom::bytes::complete::{tag, take_until};
33
use nom::character::complete::{alphanumeric1, line_ending, space0, space1};
44
use nom::combinator::{opt, recognize};
55
use nom::multi::{many0, many1};
6-
use nom::sequence::{preceded, tuple};
6+
use nom::sequence::preceded;
7+
use nom::Parser;
78
use phylum_types::types::package::PackageType;
89

910
use crate::parsers::IResult;
1011
use crate::{Package, PackageVersion};
1112

1213
pub fn parse(input: &str) -> IResult<&str, Vec<Package>> {
13-
let (input, pkgs) = many0(package)(input)?;
14+
let (input, pkgs) = many0(package).parse(input)?;
1415

1516
let pkgs = pkgs
1617
.into_iter()
@@ -42,19 +43,20 @@ fn package_name(input: &str) -> IResult<&str, &str> {
4243
let (input, _) = space0(input)?;
4344

4445
// The package name will be everything up until a space.
45-
recognize(take_until(" "))(input)
46+
recognize(take_until(" ")).parse(input)
4647
}
4748

4849
fn package_version(input: &str) -> IResult<&str, &str> {
4950
// Take away any leading whitespace.
5051
let (input, _) = space0(input)?;
5152

5253
// Accept all of `v[a-zA-Z0-9.+-]+` with an optional "/go.mod" suffix.
53-
let (input, version) = recognize(tuple((
54+
let (input, version) = recognize((
5455
tag("v"),
5556
many1(alt((alphanumeric1, tag("."), tag("-"), tag("+")))),
5657
opt(tag("/go.mod")),
57-
)))(input)?;
58+
))
59+
.parse(input)?;
5860

5961
// Expect at least one whitespace after version.
6062
let (input, _) = space1(input)?;
@@ -70,7 +72,7 @@ fn package_hash(input: &str) -> IResult<&str, &str> {
7072
let base64_parser = recognize(many1(alt((alphanumeric1, tag("+"), tag("/"), tag("=")))));
7173

7274
// Parse base64 hash with `h1:` prefix.
73-
let (input, hash) = preceded(tag("h1:"), base64_parser)(input)?;
75+
let (input, hash) = preceded(tag("h1:"), base64_parser).parse(input)?;
7476

7577
// Expect EOL.
7678
let (input, _) = line_ending(input)?;

lockfile/src/parsers/gradle_dep.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use nom::branch::alt;
22
use nom::bytes::complete::{tag, take_till};
33
use nom::combinator::eof;
4-
use nom::error::VerboseError;
4+
use nom::Parser;
5+
use nom_language::error::VerboseError;
56
use phylum_types::types::package::PackageType;
67

78
use crate::parsers::IResult;
@@ -33,7 +34,7 @@ fn package(input: &str) -> Result<Package, nom::Err<VerboseError<&str>>> {
3334
let (input, _) = tag(":")(input)?;
3435

3536
let (input, version) = not_space_until(input, '=')?;
36-
let _ = alt((tag("="), eof))(input)?;
37+
let _ = alt((tag("="), eof)).parse(input)?;
3738

3839
Ok(Package {
3940
name: format!("{group_id}:{artifact_id}"),

lockfile/src/parsers/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ use nom::branch::alt;
22
use nom::bytes::complete::{tag, take_until};
33
use nom::character::complete::{line_ending, not_line_ending, space0};
44
use nom::combinator::{eof, opt, recognize, rest};
5-
use nom::error::{context, VerboseError};
5+
use nom::error::context;
66
use nom::multi::many_till;
7-
use nom::sequence::{delimited, terminated, tuple};
8-
use nom::AsChar;
7+
use nom::sequence::{delimited, terminated};
8+
use nom::{AsChar, Parser};
9+
use nom_language::error::VerboseError;
910

1011
pub mod gem;
1112
pub mod go_mod;
@@ -17,12 +18,12 @@ pub mod yarn;
1718

1819
/// Consume everything until the next `\n` or `\r\n`.
1920
fn take_till_line_end(input: &str) -> IResult<&str, &str> {
20-
recognize(terminated(not_line_ending, line_ending))(input)
21+
recognize(terminated(not_line_ending, line_ending)).parse(input)
2122
}
2223

2324
/// Consume everything until the next `\n\n` or `\r\n\r\n`.
2425
fn take_till_blank_line(input: &str) -> IResult<&str, &str> {
25-
recognize(alt((take_until("\n\n"), take_until("\r\n\r\n"))))(input)
26+
recognize(alt((take_until("\n\n"), take_until("\r\n\r\n")))).parse(input)
2627
}
2728

2829
/// Consume the next line.
@@ -32,7 +33,7 @@ fn take_till_blank_line(input: &str) -> IResult<&str, &str> {
3233
fn take_continued_line(mut input: &str) -> IResult<&str, ()> {
3334
loop {
3435
// Get everything up to the next NL or EOF.
35-
let (new_input, line) = recognize(alt((take_till_line_end, rest)))(input)?;
36+
let (new_input, line) = recognize(alt((take_till_line_end, rest))).parse(input)?;
3637
input = new_input;
3738

3839
// Stop consuming lines once there are no continuations.

0 commit comments

Comments
 (0)