From ebae951eae54a1f33b256d53781d754632adc109 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Nov 2020 18:51:39 +0000 Subject: [PATCH] Update nom requirement from 5.0.0 to 6.0.0 (#6) Updates the requirements on [nom](https://github.com/Geal/nom) to permit the latest version. - [Release notes](https://github.com/Geal/nom/releases) - [Changelog](https://github.com/Geal/nom/blob/master/CHANGELOG.md) - [Commits](https://github.com/Geal/nom/compare/5.0.0...6.0.0) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.toml | 2 +- src/error.rs | 7 +++++++ src/function/parse.rs | 2 +- src/lib.rs | 14 +++++++------- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dd3cdde..d0bb7c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] crc32fast = "1.2.0" esplugin = "3.0.0" -nom = "5.0.0" +nom = "6.0.0" pelite = "0.9.0" regex = "1.0.5" unicase = "2.2.0" diff --git a/src/error.rs b/src/error.rs index d1d06b3..d91617d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -85,6 +85,13 @@ impl From<(I, ErrorKind)> for ParsingError { } } +impl From> for ParsingError { + fn from(error: nom::error::Error) -> Self { + use nom::error::ParseError; + ParsingError::from_error_kind(error.input, error.code) + } +} + impl fmt::Display for ParsingError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( diff --git a/src/function/parse.rs b/src/function/parse.rs index 4ba254d..1d29062 100644 --- a/src/function/parse.rs +++ b/src/function/parse.rs @@ -93,7 +93,7 @@ fn parse_crc(input: &str) -> ParsingResult { } fn parse_checksum_args(input: &str) -> ParsingResult<(PathBuf, u32)> { - let parser = tuple(( + let mut parser = tuple(( map_err(parse_path), map_err(whitespace(tag(","))), map_parser(hex_digit1, parse_crc), diff --git a/src/lib.rs b/src/lib.rs index 3e35b5f..da47091 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ use nom::branch::alt; use nom::bytes::complete::tag; use nom::character::complete::space0; use nom::combinator::map; -use nom::multi::separated_list; +use nom::multi::separated_list0; use nom::sequence::{delimited, preceded}; use nom::IResult; @@ -175,7 +175,7 @@ impl str::FromStr for Expression { fn parse_expression(input: &str) -> ParsingResult { map( - separated_list(map_err(whitespace(tag("or"))), CompoundCondition::parse), + separated_list0(map_err(whitespace(tag("or"))), CompoundCondition::parse), Expression, )(input) } @@ -203,7 +203,7 @@ impl CompoundCondition { fn parse(input: &str) -> ParsingResult { map( - separated_list(map_err(whitespace(tag("and"))), Condition::parse), + separated_list0(map_err(whitespace(tag("and"))), Condition::parse), CompoundCondition, )(input) } @@ -263,14 +263,14 @@ impl fmt::Display for Condition { } fn map_err<'a, O>( - parser: impl Fn(&'a str) -> IResult<&'a str, O, (&'a str, nom::error::ErrorKind)>, -) -> impl Fn(&'a str) -> ParsingResult<'a, O> { + mut parser: impl FnMut(&'a str) -> IResult<&'a str, O, nom::error::Error<&'a str>>, +) -> impl FnMut(&'a str) -> ParsingResult<'a, O> { move |i| parser(i).map_err(nom::Err::convert) } fn whitespace<'a, O>( parser: impl Fn(&'a str) -> IResult<&'a str, O>, -) -> impl Fn(&'a str) -> IResult<&'a str, O> { +) -> impl FnMut(&'a str) -> IResult<&'a str, O> { delimited(space0, parser, space0) } @@ -454,7 +454,7 @@ mod tests { let error = Expression::from_str("file(\"Carg").unwrap_err(); assert_eq!( - "An error was encountered while parsing the expression \"file(\\\"Carg\": Error in parser: Separated list", + "The parser did not consume the following input: \"file(\"Carg\"", error.to_string() ); }