Skip to content

Commit

Permalink
Update nom from 7.1.3 to 8.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Jan 27, 2025
1 parent 18150b7 commit 784af50
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 23 deletions.
13 changes: 11 additions & 2 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 @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
crc32fast = "1.4.2"
esplugin = "6.1.1"
nom = "7.0.0"
nom = "8.0.0"
pelite = "0.10.0"
regex = "1.11.1"
unicase = "2.8.1"
Expand Down
30 changes: 17 additions & 13 deletions src/function/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use nom::branch::alt;
use nom::bytes::complete::{is_not, tag};
use nom::character::complete::hex_digit1;
use nom::combinator::{map, map_parser, value};
use nom::sequence::{delimited, tuple};
use nom::{Err, IResult};
use nom::sequence::delimited;
use nom::{Err, IResult, Parser};
use regex::{Regex, RegexBuilder};

use super::{ComparisonOperator, Function};
Expand All @@ -22,7 +22,8 @@ impl ComparisonOperator {
value(ComparisonOperator::GreaterThanOrEqual, tag(">=")),
value(ComparisonOperator::LessThan, tag("<")),
value(ComparisonOperator::GreaterThan, tag(">")),
))(input)
))
.parse(input)
}
}

Expand Down Expand Up @@ -60,7 +61,8 @@ fn parse_path(input: &str) -> IResult<&str, PathBuf> {
map(
delimited(tag("\""), is_not(INVALID_PATH_CHARS), tag("\"")),
PathBuf::from,
)(input)
)
.parse(input)
}

fn parse_version_args(input: &str) -> ParsingResult<(PathBuf, String, ComparisonOperator)> {
Expand All @@ -69,15 +71,15 @@ fn parse_version_args(input: &str) -> ParsingResult<(PathBuf, String, Comparison
|version: &str| version.to_string(),
);

let parser = tuple((
let parser = (
parse_path,
whitespace(tag(",")),
version_parser,
whitespace(tag(",")),
ComparisonOperator::parse,
));
);

let (remaining_input, (path, _, version, _, comparator)) = map_err(parser)(input)?;
let (remaining_input, (path, _, version, _, comparator)) = map_err(parser).parse(input)?;

if is_in_game_path(&path) {
Ok((remaining_input, (path, version, comparator)))
Expand All @@ -93,13 +95,13 @@ fn parse_crc(input: &str) -> ParsingResult<u32> {
}

fn parse_checksum_args(input: &str) -> ParsingResult<(PathBuf, u32)> {
let mut parser = tuple((
let mut parser = (
map_err(parse_path),
map_err(whitespace(tag(","))),
map_parser(hex_digit1, parse_crc),
));
);

let (remaining_input, (path, _, crc)) = parser(input)?;
let (remaining_input, (path, _, crc)) = parser.parse(input)?;

if is_in_game_path(&path) {
Ok((remaining_input, (path, crc)))
Expand All @@ -111,7 +113,8 @@ fn parse_checksum_args(input: &str) -> ParsingResult<(PathBuf, u32)> {
fn parse_non_regex_path(input: &str) -> ParsingResult<PathBuf> {
let (remaining_input, path) = map(is_not(INVALID_NON_REGEX_PATH_CHARS), |path: &str| {
PathBuf::from(path)
})(input)?;
})
.parse(input)?;

if is_in_game_path(&path) {
Ok((remaining_input, path))
Expand Down Expand Up @@ -148,7 +151,7 @@ fn parse_regex_path(input: &str) -> ParsingResult<(PathBuf, Regex)> {
}

fn parse_regex_filename(input: &str) -> ParsingResult<Regex> {
map_parser(is_not(INVALID_REGEX_PATH_CHARS), parse_regex)(input)
map_parser(is_not(INVALID_REGEX_PATH_CHARS), parse_regex).parse(input)
}

impl Function {
Expand Down Expand Up @@ -242,7 +245,8 @@ impl Function {
),
|(path, crc)| Function::Checksum(path, crc),
),
))(input)
))
.parse(input)
}
}

Expand Down
17 changes: 10 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use nom::character::complete::space0;
use nom::combinator::map;
use nom::multi::separated_list0;
use nom::sequence::{delimited, preceded};
use nom::IResult;
use nom::{IResult, Parser};

use error::ParsingError;
pub use error::{Error, MoreDataNeeded, ParsingErrorKind};
Expand Down Expand Up @@ -171,7 +171,8 @@ fn parse_expression(input: &str) -> ParsingResult<Expression> {
map(
separated_list0(map_err(whitespace(tag("or"))), CompoundCondition::parse),
Expression,
)(input)
)
.parse(input)
}

impl fmt::Display for Expression {
Expand Down Expand Up @@ -199,7 +200,8 @@ impl CompoundCondition {
map(
separated_list0(map_err(whitespace(tag("and"))), Condition::parse),
CompoundCondition,
)(input)
)
.parse(input)
}
}

Expand Down Expand Up @@ -251,7 +253,8 @@ impl Condition {
),
Condition::InvertedExpression,
),
))(input)
))
.parse(input)
}
}

Expand All @@ -268,14 +271,14 @@ impl fmt::Display for Condition {
}

fn map_err<'a, O>(
mut parser: impl FnMut(&'a str) -> IResult<&'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) -> ParsingResult<'a, O> {
move |i| parser(i).map_err(nom::Err::convert)
move |i| parser.parse(i).map_err(nom::Err::convert)
}

fn whitespace<'a, O>(
parser: impl Fn(&'a str) -> IResult<&'a str, O>,
) -> impl FnMut(&'a str) -> IResult<&'a str, O> {
) -> impl Parser<&'a str, Output = O, Error = nom::error::Error<&'a str>> {
delimited(space0, parser, space0)
}

Expand Down

0 comments on commit 784af50

Please sign in to comment.