Skip to content

Commit

Permalink
chore(deps): Bump nom from 7.1.3 to 8.0.0 (#541)
Browse files Browse the repository at this point in the history
Bumps [nom](https://github.com/rust-bakery/nom) from 7.1.3 to 8.0.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/rust-bakery/nom/blob/main/CHANGELOG.md">nom's
changelog</a>.</em></p>
<blockquote>
<h2>8.0.0 2025-01-25</h2>
<p>This versions represents a significant refactoring of nom to reduce
the amount of code generated by prsers, and reduce the API surface. As
such, it comes with some breaking changes, mostly around the move from
closure based combinators to trait based ones. In practice, it means
that instead of writing <code>combinator(arg)(input)</code>, we now
write <code>combinator(arg).parse(input)</code>.</p>
<p>This release also marks th introduction of the <a
href="https://crates.io/crates/nom-language">nom-language</a> crate,
which will hold tools more focused on language parsing than the rest of
nom, like the <code>VerboseError</code> type and the newly added
precedence parsing combinators.</p>
<h3>Thanks</h3>
<ul>
<li><a href="https://github.com/cky"><code>@​cky</code></a></li>
<li><a
href="https://github.com/5c077m4n"><code>@​5c077m4n</code></a></li>
<li><a href="https://github.com/epage"><code>@​epage</code></a></li>
<li><a href="https://github.com/Fumon"><code>@​Fumon</code></a></li>
<li><a href="https://github.com/jtracey"><code>@​jtracey</code></a></li>
<li><a
href="https://github.com/OliveIsAWord"><code>@​OliveIsAWord</code></a></li>
<li><a href="https://github.com/Xiretza"><code>@​Xiretza</code></a></li>
<li><a href="https://github.com/flier"><code>@​flier</code></a></li>
<li><a href="https://github.com/cenodis"><code>@​cenodis</code></a></li>
<li><a
href="https://github.com/Shadow53"><code>@​Shadow53</code></a></li>
<li>@<a href="https://github.com/jmmaa"><code>@​jmmaa</code></a></li>
<li><a href="https://github.com/terror"><code>@​terror</code></a></li>
<li><a href="https://github.com/zanedp"><code>@​zanedp</code></a></li>
<li><a
href="https://github.com/atouchet"><code>@​atouchet</code></a></li>
<li><a href="https://github.com/CMDJojo"><code>@​CMDJojo</code></a></li>
<li><a
href="https://github.com/ackxolotl"><code>@​ackxolotl</code></a></li>
<li><a href="https://github.com/xmakro"><code>@​xmakro</code></a></li>
<li><a href="https://github.com/tfpk"><code>@​tfpk</code></a></li>
<li><a
href="https://github.com/WhyNotHugo"><code>@​WhyNotHugo</code></a></li>
<li><a href="https://github.com/brollb"><code>@​brollb</code></a></li>
<li><a
href="https://github.com/smheidrich"><code>@​smheidrich</code></a></li>
<li><a
href="https://github.com/glittershark"><code>@​glittershark</code></a></li>
<li><a
href="https://github.com/GuillaumeGomez"><code>@​GuillaumeGomez</code></a></li>
<li><a
href="https://github.com/LeoDog896"><code>@​LeoDog896</code></a></li>
<li><a href="https://github.com/fmiras"><code>@​fmiras</code></a></li>
<li><a
href="https://github.com/ttsugriy"><code>@​ttsugriy</code></a></li>
<li><a
href="https://github.com/McDostone"><code>@​McDostone</code></a></li>
<li><a
href="https://github.com/superboum"><code>@​superboum</code></a></li>
<li><a href="https://github.com/rruppy"><code>@​rruppy</code></a></li>
<li><a href="https://github.com/thssuck"><code>@​thssuck</code></a></li>
<li><a
href="https://github.com/Chasing1020"><code>@​Chasing1020</code></a></li>
<li><a
href="https://github.com/thatmarkenglishguy"><code>@​thatmarkenglishguy</code></a></li>
<li><a href="https://github.com/ambiso"><code>@​ambiso</code></a></li>
<li><a href="https://github.com/boxdot"><code>@​boxdot</code></a></li>
<li><a href="https://github.com/krtab"><code>@​krtab</code></a></li>
<li><a
href="https://github.com/code10129"><code>@​code10129</code></a></li>
<li><a href="https://github.com/manunio"><code>@​manunio</code></a></li>
<li><a href="https://github.com/stuarth"><code>@​stuarth</code></a></li>
<li><a href="https://github.com/mindeng"><code>@​mindeng</code></a></li>
<li><a
href="https://github.com/JonathanPlasse"><code>@​JonathanPlasse</code></a></li>
<li><a
href="https://github.com/nabilwadih"><code>@​nabilwadih</code></a></li>
<li><a
href="https://github.com/phoenixr-codes"><code>@​phoenixr-codes</code></a></li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/rust-bakery/nom/commit/2cec1b3e4c9ccac62c902d60c00de6d1549ccbe1"><code>2cec1b3</code></a>
v8.0.0 (<a
href="https://redirect.github.com/rust-bakery/nom/issues/1797">#1797</a>)</li>
<li><a
href="https://github.com/rust-bakery/nom/commit/7afe3a8c4021871a8647d3bbf928aecd551c9b62"><code>7afe3a8</code></a>
Merge pull request <a
href="https://redirect.github.com/rust-bakery/nom/issues/1793">#1793</a>
from rust-bakery/beta.1</li>
<li><a
href="https://github.com/rust-bakery/nom/commit/84af9e79216462cf00fc7c85cbbbdb67d6897110"><code>84af9e7</code></a>
nom 8.0.0-beta.1</li>
<li><a
href="https://github.com/rust-bakery/nom/commit/555eab9ddcbd6665626150ed14d17106eb85ad5f"><code>555eab9</code></a>
Merge pull request <a
href="https://redirect.github.com/rust-bakery/nom/issues/1792">#1792</a>
from rust-bakery/nom-language</li>
<li><a
href="https://github.com/rust-bakery/nom/commit/6a25312dbf4df8fe0ad1f1dc5de19843139d381e"><code>6a25312</code></a>
fix nom-language tests</li>
<li><a
href="https://github.com/rust-bakery/nom/commit/bcc1b0cb64bcbf82ab3f35e32eec1429129e5d02"><code>bcc1b0c</code></a>
move the left_assoc combinator to nom-language</li>
<li><a
href="https://github.com/rust-bakery/nom/commit/9b0e18cf5a75964a3d4a841292c0aacf6a513c39"><code>9b0e18c</code></a>
Implement new parser <code>left_assoc</code>. (<a
href="https://redirect.github.com/rust-bakery/nom/issues/1775">#1775</a>)</li>
<li><a
href="https://github.com/rust-bakery/nom/commit/cb3b5b8ebbbca2efe81ae4089541bab322bc3bfe"><code>cb3b5b8</code></a>
move precedence parsing to nom-language</li>
<li><a
href="https://github.com/rust-bakery/nom/commit/f1abba64a7384a29602ee0df00b4809e1fd39f2a"><code>f1abba6</code></a>
fix precedence parsing</li>
<li><a
href="https://github.com/rust-bakery/nom/commit/6c124693c10dd3e932013fdfa0e1690af8b53af7"><code>6c12469</code></a>
Precedence parsing (<a
href="https://redirect.github.com/rust-bakery/nom/issues/1362">#1362</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/rust-bakery/nom/compare/7.1.3...8.0.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=nom&package-manager=cargo&previous-version=7.1.3&new-version=8.0.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Yota Toyama <raviqqe@gmail.com>
  • Loading branch information
dependabot[bot] and raviqqe authored Feb 22, 2025
1 parent 6d34913 commit 8719a5d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 67 deletions.
11 changes: 2 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ clap = { version = "4", features = ["derive", "env"] }
dashmap = "6.1.0"
futures = "0.3"
itertools = "0.14"
nom = "7.1.3"
nom = "8.0.0"
num_cpus = "1"
once_cell = "1"
petgraph = "0.7"
Expand Down
129 changes: 72 additions & 57 deletions src/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,30 @@ use nom::{
character::complete::{alpha1, alphanumeric1, line_ending, none_of, one_of, space1},
combinator::{all_consuming, into, map, not, opt, peek, recognize, value},
multi::{many0, many0_count, many1, many1_count},
sequence::{delimited, preceded, terminated, tuple},
sequence::{delimited, preceded, terminated},
};

const OPERATOR_CHARACTERS: &str = "|:";
const DYNAMIC_MODULE_VERSION_VARIABLE: &str = "ninja_dyndep_version";

pub fn module(input: &str) -> IResult<&str, Module> {
map(
all_consuming(tuple((opt(line_break), many0(statement), opt(line_break)))),
all_consuming((opt(line_break), many0(statement), opt(line_break))),
|(_, statements, _)| Module::new(statements),
)(input)
)
.parse(input)
}

pub fn dynamic_module(input: &str) -> IResult<&str, DynamicModule> {
map(
all_consuming(tuple((
all_consuming((
opt(line_break),
dynamic_module_version,
many0(dynamic_build),
))),
)),
|(_, _, builds)| DynamicModule::new(builds),
)(input)
)
.parse(input)
}

fn statement(input: &str) -> IResult<&str, Statement> {
Expand All @@ -41,52 +43,56 @@ fn statement(input: &str) -> IResult<&str, Statement> {
into(rule),
into(submodule),
into(variable_definition),
))(input)
))
.parse(input)
}

fn variable_definition(input: &str) -> IResult<&str, VariableDefinition> {
map(
tuple((identifier, sign("="), opt(string_line), line_break)),
(identifier, sign("="), opt(string_line), line_break),
|(name, _, value, _)| VariableDefinition::new(name, value.unwrap_or_default()),
)(input)
)
.parse(input)
}

fn dynamic_module_version(input: &str) -> IResult<&str, &str> {
map(
tuple((
(
keyword(DYNAMIC_MODULE_VERSION_VARIABLE),
sign("="),
string_line,
line_break,
)),
),
|(_, _, version, _)| version,
)(input)
)
.parse(input)
}

fn rule(input: &str) -> IResult<&str, Rule> {
map(
tuple((
(
keyword("rule"),
identifier,
line_break,
delimited(
tuple((indent, keyword("command"), sign("="))),
(indent, keyword("command"), sign("=")),
string_line,
line_break,
),
opt(delimited(
tuple((indent, keyword("description"), sign("="))),
(indent, keyword("description"), sign("=")),
string_line,
line_break,
)),
)),
),
|(_, name, _, command, description)| Rule::new(name, command, description.map(From::from)),
)(input)
)
.parse(input)
}

fn build(input: &str) -> IResult<&str, Build> {
map(
tuple((
(
keyword("build"),
many1(string_literal),
opt(preceded(sign("|"), many1(string_literal))),
Expand All @@ -97,7 +103,7 @@ fn build(input: &str) -> IResult<&str, Build> {
opt(preceded(sign("||"), many1(string_literal))),
line_break,
many0(preceded(indent, variable_definition)),
)),
),
|(
_,
outputs,
Expand All @@ -120,50 +126,56 @@ fn build(input: &str) -> IResult<&str, Build> {
variable_definitions,
)
},
)(input)
)
.parse(input)
}

pub fn dynamic_build(input: &str) -> IResult<&str, DynamicBuild> {
map(
tuple((
(
keyword("build"),
string_literal,
sign(":"),
keyword("dyndep"),
opt(preceded(sign("|"), many1(string_literal))),
line_break,
)),
),
|(_, output, _, _, implicit_inputs, _)| {
DynamicBuild::new(output, implicit_inputs.unwrap_or_default())
},
)(input)
)
.parse(input)
}

fn default(input: &str) -> IResult<&str, DefaultOutput> {
map(
tuple((keyword("default"), many1(string_literal), line_break)),
(keyword("default"), many1(string_literal), line_break),
|(_, outputs, _)| DefaultOutput::new(outputs.into_iter().collect()),
)(input)
)
.parse(input)
}

fn include(input: &str) -> IResult<&str, Include> {
map(
tuple((keyword("include"), string_line, line_break)),
(keyword("include"), string_line, line_break),
|(_, path, _)| Include::new(path),
)(input)
)
.parse(input)
}

fn submodule(input: &str) -> IResult<&str, Submodule> {
map(
tuple((keyword("subninja"), string_line, line_break)),
(keyword("subninja"), string_line, line_break),
|(_, path, _)| Submodule::new(path),
)(input)
)
.parse(input)
}

fn string_line(input: &str) -> IResult<&str, &str> {
map(recognize(many1_count(none_of("\n"))), |string: &str| {
string.trim()
})(input)
})
.parse(input)
}

fn string_literal(input: &str) -> IResult<&str, String> {
Expand All @@ -172,18 +184,20 @@ fn string_literal(input: &str) -> IResult<&str, String> {
&*(" \t\r\n".to_owned() + OPERATOR_CHARACTERS),
)))),
|string| string.to_owned(),
)(input)
)
.parse(input)
}

fn keyword(name: &'static str) -> impl Fn(&str) -> IResult<&str, ()> {
move |input| value((), token(tuple((tag(name), peek(not(alphanumeric1))))))(input)
move |input| value((), token((tag(name), peek(not(alphanumeric1))))).parse(input)
}

fn identifier(input: &str) -> IResult<&str, &str> {
token(recognize(tuple((
token(recognize((
alt((alpha1, tag("_"))),
many0_count(alt((alphanumeric1, tag("_")))),
))))(input)
)))
.parse(input)
}

fn sign(sign: &'static str) -> impl Fn(&str) -> IResult<&str, ()> {
Expand All @@ -194,12 +208,13 @@ fn sign(sign: &'static str) -> impl Fn(&str) -> IResult<&str, ()> {
tag(sign),
peek(not(one_of(OPERATOR_CHARACTERS))),
)),
)(input)
)
.parse(input)
}
}

fn token<'a, O>(
mut parser: impl Parser<&'a str, O, nom::error::Error<&'a str>>,
mut parser: impl Parser<&'a str, Output = O, Error = nom::error::Error<&'a str>>,
) -> impl FnMut(&'a str) -> IResult<&'a str, O> {
move |input| {
let (input, _) = blank(input)?;
Expand All @@ -209,19 +224,19 @@ fn token<'a, O>(
}

fn indent(input: &str) -> IResult<&str, ()> {
value((), space1)(input)
value((), space1).parse(input)
}

fn blank(input: &str) -> IResult<&str, ()> {
value((), many0_count(alt((value((), space1), comment))))(input)
value((), many0_count(alt((value((), space1), comment)))).parse(input)
}

fn comment(input: &str) -> IResult<&str, ()> {
value((), tuple((tag("#"), many0_count(none_of("\n")))))(input)
value((), (tag("#"), many0_count(none_of("\n")))).parse(input)
}

fn line_break(input: &str) -> IResult<&str, ()> {
value((), many1_count(tuple((blank, line_ending))))(input)
value((), many1_count((blank, line_ending))).parse(input)
}

#[cfg(test)]
Expand Down Expand Up @@ -539,26 +554,26 @@ mod tests {

#[test]
fn parse_blank() {
assert!(all_consuming(blank)("").is_ok());
assert!(all_consuming(blank)(" ").is_ok());
assert!(all_consuming(blank)("\t").is_ok());
assert!(all_consuming(blank)(" ").is_ok());
assert!(all_consuming(blank)(" \t").is_ok());
assert!(all_consuming(blank)("#").is_ok());
assert!(all_consuming(blank)("#foo").is_ok());
assert!(all_consuming(blank)(" #foo").is_ok());
assert!(all_consuming(blank)("\n").is_err());
assert!(all_consuming(blank)(" \n").is_err());
assert!(all_consuming(blank).parse("").is_ok());
assert!(all_consuming(blank).parse(" ").is_ok());
assert!(all_consuming(blank).parse("\t").is_ok());
assert!(all_consuming(blank).parse(" ").is_ok());
assert!(all_consuming(blank).parse(" \t").is_ok());
assert!(all_consuming(blank).parse("#").is_ok());
assert!(all_consuming(blank).parse("#foo").is_ok());
assert!(all_consuming(blank).parse(" #foo").is_ok());
assert!(all_consuming(blank).parse("\n").is_err());
assert!(all_consuming(blank).parse(" \n").is_err());
}

#[test]
fn parse_line_break() {
assert!(all_consuming(line_break)("").is_err());
assert!(all_consuming(line_break)("\n").is_ok());
assert!(all_consuming(line_break)("\r\n").is_ok());
assert!(all_consuming(line_break)(" \n").is_ok());
assert!(all_consuming(line_break)(" \n").is_ok());
assert!(all_consuming(line_break)("\n\n").is_ok());
assert!(all_consuming(line_break)("\n ").is_err());
assert!(all_consuming(line_break).parse("").is_err());
assert!(all_consuming(line_break).parse("\n").is_ok());
assert!(all_consuming(line_break).parse("\r\n").is_ok());
assert!(all_consuming(line_break).parse(" \n").is_ok());
assert!(all_consuming(line_break).parse(" \n").is_ok());
assert!(all_consuming(line_break).parse("\n\n").is_ok());
assert!(all_consuming(line_break).parse("\n ").is_err());
}
}

0 comments on commit 8719a5d

Please sign in to comment.