Skip to content

Commit

Permalink
fix: update to nom8 alpha2
Browse files Browse the repository at this point in the history
  • Loading branch information
hoodie committed May 16, 2024
1 parent 7de9acb commit 4c8f0e1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ default-features = false
features = ["clock", "std", "wasmbind"]

[dependencies.nom]
version = "7"
version = "8.0.0-alpha2"
optional = true

[target.'cfg(not(target_arch = "wasm32"))'.dependencies.uuid]
Expand Down
6 changes: 3 additions & 3 deletions src/parser/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ pub fn read_component(input: &str) -> Result<Component<'_>, String> {
pub fn component<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, Component, E> {
let (input, name) = line("BEGIN:", valid_key_sequence_cow)(input)?;
let (input, name) = line("BEGIN:", valid_key_sequence_cow).parse(input)?;

let (input, (properties, components)) = many_till(
cut(context(
Expand All @@ -270,7 +270,7 @@ pub fn component<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
})
.parse(input)?;

let (input, _) = many0(tag("\n"))(input)?;
let (input, _) = many0(tag("\n")).parse(input)?;

Ok((
input,
Expand Down Expand Up @@ -513,5 +513,5 @@ fn test_faulty_component() {
pub fn components<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, Vec<Component>, E> {
complete(many0(all_consuming(component)))(input)
complete(many0(all_consuming(component))).parse(input)
}
18 changes: 9 additions & 9 deletions src/parser/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use nom::{
combinator::{eof, opt},
error::{convert_error, ContextError, ParseError, VerboseError},
multi::many0,
sequence::{preceded, separated_pair, tuple},
sequence::{preceded, separated_pair},
Finish, IResult, Parser,
};

Expand Down Expand Up @@ -130,14 +130,14 @@ fn remove_empty_string_parsed(input: Option<ParseString<'_>>) -> Option<ParseStr
fn parameter<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, Parameter<'a>, E> {
alt((pair_parameter, base_parameter))(input)
alt((pair_parameter, base_parameter)).parse(input)
}

fn pair_parameter<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, Parameter<'a>, E> {
preceded(
tuple((tag(";"), space0)),
(tag(";"), space0),
separated_pair(
valid_key_sequence_cow, //key
tag("="),
Expand All @@ -154,19 +154,19 @@ fn pair_parameter<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
fn base_parameter<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, Parameter<'a>, E> {
tuple((
(
preceded(
tuple((tag(";"), space0)),
(tag(";"), space0),
valid_key_sequence_cow, //key
),
opt(preceded(
tag("="),
alt((eof, take_till1(|x| x == ';' || x == ':'))).map(ParseString::from),
))
.map(remove_empty_string_parsed),
))
.map(|(key, val)| Parameter { key, val })
.parse(input)
)
.map(|(key, val)| Parameter { key, val })
.parse(input)
}

// parameter list
Expand Down Expand Up @@ -200,5 +200,5 @@ pub fn parse_parameter_list() {
pub fn parameters<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, Vec<Parameter>, E> {
many0(parameter)(input)
many0(parameter).parse(input)
}
20 changes: 10 additions & 10 deletions src/parser/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use nom::{
character::complete::{line_ending, multispace0},
combinator::{cut, opt},
error::{context, convert_error, ContextError, ParseError, VerboseError},
sequence::{preceded, separated_pair, tuple},
sequence::{preceded, separated_pair},
Finish, IResult, Parser,
};

Expand Down Expand Up @@ -287,10 +287,10 @@ pub fn property<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
) -> IResult<&'a str, Property, E> {
context(
"property",
cut(tuple((
cut((
alt((
separated_pair(
tuple((
(
// preceded(multispace0, alpha_or_dash), // key
cut(context(
// this must be interpreted as component by `component()`
Expand All @@ -299,7 +299,7 @@ pub fn property<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
preceded(multispace0, property_key).map(ParseString::from),
)), // key
parameters, // params
)),
),
context("property separator", tag(":")), // separator
context(
"property value",
Expand All @@ -318,12 +318,12 @@ pub fn property<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
),
)),
opt(line_ending),
))
.map(|(((key, params), val), _)| Property {
name: key,
val,
params,
})),
)
.map(|(((key, params), val), _)| Property {
name: key,
val,
params,
})),
)
.parse(input)
}
8 changes: 4 additions & 4 deletions src/parser/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ pub fn valid_key_sequence_cow<'a, E: ParseError<&'a str> + ContextError<&'a str>
.parse(input)
}

pub fn line<'a, O, E: ParseError<&'a str>, F: Parser<&'a str, O, E>>(
pub fn line<'a, O, E: ParseError<&'a str>, F: Parser<&'a str, Output = O, Error = E>>(
prefix: &'a str,
f: F,
) -> impl FnMut(&'a str) -> IResult<&'a str, O, E> {
) -> impl Parser<&'a str, Output = O, Error = E> {
line_separated(complete(preceded(tag_no_case(prefix), f)))
}

pub fn line_separated<'a, O, E: ParseError<&'a str>, F: Parser<&'a str, O, E>>(
pub fn line_separated<'a, O, E: ParseError<&'a str>, F: Parser<&'a str, Output = O, Error = E>>(
f: F,
) -> impl FnMut(&'a str) -> IResult<&'a str, O, E> {
) -> impl Parser<&'a str, Output = O, Error = E> {
delimited(many0(line_ending), f, many0(line_ending))
}

Expand Down

0 comments on commit 4c8f0e1

Please sign in to comment.