diff --git a/nextest-filtering/src/parsing.rs b/nextest-filtering/src/parsing.rs index ffe6c0d0c72..d2bb6e07c9b 100644 --- a/nextest-filtering/src/parsing.rs +++ b/nextest-filtering/src/parsing.rs @@ -34,8 +34,8 @@ pub(crate) use glob::GenericGlob; pub(crate) use unicode_string::DisplayParsedString; pub(crate) type Span<'a> = winnow::Stateful, State<'a>>; -type Error<'a> = winnow::error::InputError>; -type PResult<'a, T> = winnow::PResult>; +type Error = (); +type PResult = winnow::PResult; impl<'a> ToSourceSpan for Span<'a> { fn to_span(&self) -> SourceSpan { @@ -233,9 +233,9 @@ fn expect_inner<'a, F, T>( mut parser: F, make_err: fn(SourceSpan) -> ParseSingleError, limit: SpanLength, -) -> impl Parser, Option, Error<'a>> +) -> impl Parser, Option, Error> where - F: Parser, T, Error<'a>>, + F: Parser, T, Error>, { move |input: &mut _| match parser.parse_next(input) { Ok(out) => Ok(Some(out)), @@ -267,9 +267,9 @@ where fn expect<'a, F, T>( parser: F, make_err: fn(SourceSpan) -> ParseSingleError, -) -> impl Parser, Option, Error<'a>> +) -> impl Parser, Option, Error> where - F: Parser, T, Error<'a>>, + F: Parser, T, Error>, { expect_inner(parser, make_err, SpanLength::Unknown) } @@ -278,9 +278,9 @@ fn expect_n<'a, F, T>( parser: F, make_err: fn(SourceSpan) -> ParseSingleError, limit: SpanLength, -) -> impl Parser, Option, Error<'a>> +) -> impl Parser, Option, Error> where - F: Parser, T, Error<'a>>, + F: Parser, T, Error>, { expect_inner(parser, make_err, limit) } @@ -288,13 +288,13 @@ where fn expect_char<'a>( c: char, make_err: fn(SourceSpan) -> ParseSingleError, -) -> impl Parser, Option, Error<'a>> { +) -> impl Parser, Option, Error> { expect_inner(ws(c), make_err, SpanLength::Exact(0)) } -fn silent_expect<'a, F, T>(mut parser: F) -> impl Parser, Option, Error<'a>> +fn silent_expect<'a, F, T>(mut parser: F) -> impl Parser, Option, Error> where - F: Parser, T, Error<'a>>, + F: Parser, T, Error>, { move |input: &mut _| match parser.parse_next(input) { Ok(out) => Ok(Some(out)), @@ -303,9 +303,7 @@ where } } -fn ws<'a, T, P: Parser, T, Error<'a>>>( - mut inner: P, -) -> impl Parser, T, Error<'a>> { +fn ws<'a, T, P: Parser, T, Error>>(mut inner: P) -> impl Parser, T, Error> { move |input: &mut Span<'a>| { let start = input.checkpoint(); let _: () = repeat( @@ -323,21 +321,11 @@ fn ws<'a, T, P: Parser, T, Error<'a>>>( Ok(res) => Ok(res), Err(winnow::error::ErrMode::Backtrack(err)) => { input.reset(start); - let winnow::error::InputError { kind, .. } = err; - Err(winnow::error::ErrMode::Backtrack( - winnow::error::InputError { - input: input.clone(), - kind, - }, - )) + Err(winnow::error::ErrMode::Backtrack(err)) } Err(winnow::error::ErrMode::Cut(err)) => { input.reset(start); - let winnow::error::InputError { kind, .. } = err; - Err(winnow::error::ErrMode::Cut(winnow::error::InputError { - input: input.clone(), - kind, - })) + Err(winnow::error::ErrMode::Cut(err)) } Err(err) => Err(err), } @@ -345,7 +333,7 @@ fn ws<'a, T, P: Parser, T, Error<'a>>>( } // This parse will never fail -fn parse_matcher_text<'i>(input: &mut Span<'i>) -> PResult<'i, Option> { +fn parse_matcher_text<'i>(input: &mut Span<'i>) -> PResult> { trace("parse_matcher_text", |input: &mut Span<'i>| { let res = match expect( unicode_string::parse_string, @@ -369,7 +357,7 @@ fn parse_matcher_text<'i>(input: &mut Span<'i>) -> PResult<'i, Option> { .parse_next(input) } -fn parse_contains_matcher<'i>(input: &mut Span<'i>) -> PResult<'i, Option> { +fn parse_contains_matcher<'i>(input: &mut Span<'i>) -> PResult> { trace( "parse_contains_matcher", preceded('~', parse_matcher_text).map(|res: Option| { @@ -382,7 +370,7 @@ fn parse_contains_matcher<'i>(input: &mut Span<'i>) -> PResult<'i, Option(input: &mut Span<'i>) -> PResult<'i, Option> { +fn parse_equal_matcher<'i>(input: &mut Span<'i>) -> PResult> { trace( "parse_equal_matcher", ws( @@ -397,7 +385,7 @@ fn parse_equal_matcher<'i>(input: &mut Span<'i>) -> PResult<'i, Option(input: &mut Span<'i>) -> PResult<'i, String> { +fn parse_regex_inner<'i>(input: &mut Span<'i>) -> PResult { trace("parse_regex_inner", |input: &mut _| { enum Frag<'a> { Literal(&'a str), @@ -451,16 +439,14 @@ impl fmt::Display for DisplayParsedRegex<'_> { } } -fn parse_regex<'i>(input: &mut Span<'i>) -> PResult<'i, Option> { +fn parse_regex<'i>(input: &mut Span<'i>) -> PResult> { trace("parse_regex", |input: &mut Span<'i>| { let start = input.checkpoint(); let res = match parse_regex_inner.parse_next(input) { Ok(res) => res, Err(_) => { input.reset(start); - match take_till::<_, _, winnow::error::InputError>>(0.., ')') - .parse_next(input) - { + match take_till::<_, _, Error>(0.., ')').parse_next(input) { Ok(_) => { let start = input.location(); let err = ParseSingleError::ExpectedCloseRegex((start, 0).into()); @@ -491,7 +477,7 @@ fn parse_regex<'i>(input: &mut Span<'i>) -> PResult<'i, Option> { .parse_next(input) } -fn parse_regex_matcher<'i>(input: &mut Span<'i>) -> PResult<'i, Option> { +fn parse_regex_matcher<'i>(input: &mut Span<'i>) -> PResult> { trace( "parse_regex_matcher", ws(delimited('/', parse_regex, silent_expect(ws('/')))), @@ -499,7 +485,7 @@ fn parse_regex_matcher<'i>(input: &mut Span<'i>) -> PResult<'i, Option(input: &mut Span<'i>) -> PResult<'i, Option> { +fn parse_glob_matcher<'i>(input: &mut Span<'i>) -> PResult> { trace( "parse_glob_matcher", ws(preceded('#', glob::parse_glob(false))), @@ -510,7 +496,7 @@ fn parse_glob_matcher<'i>(input: &mut Span<'i>) -> PResult<'i, Option( default_matcher: DefaultMatcher, -) -> impl Parser, Option, Error<'a>> { +) -> impl Parser, Option, Error> { ws(alt(( parse_regex_matcher, parse_glob_matcher, @@ -520,7 +506,7 @@ fn set_matcher<'a>( ))) } -fn recover_unexpected_comma<'i>(input: &mut Span<'i>) -> PResult<'i, ()> { +fn recover_unexpected_comma<'i>(input: &mut Span<'i>) -> PResult<()> { trace("recover_unexpected_comma", |input: &mut Span<'i>| { let start = input.checkpoint(); match peek(ws(',')).parse_next(input) { @@ -529,9 +515,7 @@ fn recover_unexpected_comma<'i>(input: &mut Span<'i>) -> PResult<'i, ()> { input .state .report_error(ParseSingleError::UnexpectedComma((pos..0).into())); - match take_till::<_, _, winnow::error::InputError>>(0.., ')') - .parse_next(input) - { + match take_till::<_, _, Error>(0.., ')').parse_next(input) { Ok(_) => Ok(()), Err(_) => unreachable!(), } @@ -548,12 +532,12 @@ fn recover_unexpected_comma<'i>(input: &mut Span<'i>) -> PResult<'i, ()> { fn nullary_set_def<'a>( name: &'static str, make_set: fn() -> SetDef, -) -> impl Parser, Option, Error<'a>> { +) -> impl Parser, Option, Error> { move |i: &mut _| { let _ = tag(name).parse_next(i)?; let _ = expect_char('(', ParseSingleError::ExpectedOpenParenthesis).parse_next(i)?; let err_loc = i.location(); - match take_till::<_, _, Error<'a>>(0.., ')').parse_next(i) { + match take_till::<_, _, Error>(0.., ')').parse_next(i) { Ok(res) => { if !res.trim().is_empty() { let span = (err_loc, res.len()).into(); @@ -577,7 +561,7 @@ enum DefaultMatcher { } impl DefaultMatcher { - fn into_parser<'a>(self) -> impl Parser, Option, Error<'a>> { + fn into_parser<'a>(self) -> impl Parser, Option, Error> { move |input: &mut _| match self { Self::Equal => parse_matcher_text .map(|res: Option| res.map(NameMatcher::implicit_equal)) @@ -594,7 +578,7 @@ fn unary_set_def<'a>( name: &'static str, default_matcher: DefaultMatcher, make_set: fn(NameMatcher, SourceSpan) -> SetDef, -) -> impl Parser, Option, Error<'a>> { +) -> impl Parser, Option, Error> { move |i: &mut _| { let _ = tag(name).parse_next(i)?; let _ = expect_char('(', ParseSingleError::ExpectedOpenParenthesis).parse_next(i)?; @@ -607,7 +591,7 @@ fn unary_set_def<'a>( } } -fn platform_def<'i>(i: &mut Span<'i>) -> PResult<'i, Option> { +fn platform_def<'i>(i: &mut Span<'i>) -> PResult> { let _ = "platform".parse_next(i)?; let _ = expect_char('(', ParseSingleError::ExpectedOpenParenthesis).parse_next(i)?; let start = i.location(); @@ -636,7 +620,7 @@ fn platform_def<'i>(i: &mut Span<'i>) -> PResult<'i, Option> { Ok(platform.map(|platform| SetDef::Platform(platform, (start, end - start).into()))) } -fn parse_set_def<'i>(input: &mut Span<'i>) -> PResult<'i, Option> { +fn parse_set_def<'i>(input: &mut Span<'i>) -> PResult> { trace( "parse_set_def", ws(alt(( @@ -656,13 +640,13 @@ fn parse_set_def<'i>(input: &mut Span<'i>) -> PResult<'i, Option> { .parse_next(input) } -fn expect_expr<'a, P: Parser, ExprResult, Error<'a>>>( +fn expect_expr<'a, P: Parser, ExprResult, Error>>( inner: P, -) -> impl Parser, ExprResult, Error<'a>> { +) -> impl Parser, ExprResult, Error> { expect(inner, ParseSingleError::ExpectedExpr).map(|res| res.unwrap_or(ExprResult::Error)) } -fn parse_parentheses_expr<'i>(input: &mut Span<'i>) -> PResult<'i, ExprResult> { +fn parse_parentheses_expr<'i>(input: &mut Span<'i>) -> PResult { trace( "parse_parentheses_expr", delimited( @@ -675,7 +659,7 @@ fn parse_parentheses_expr<'i>(input: &mut Span<'i>) -> PResult<'i, ExprResult> { .parse_next(input) } -fn parse_basic_expr<'i>(input: &mut Span<'i>) -> PResult<'i, ExprResult> { +fn parse_basic_expr<'i>(input: &mut Span<'i>) -> PResult { trace( "parse_basic_expr", ws(alt(( @@ -709,7 +693,7 @@ impl fmt::Display for NotOperator { } } -fn parse_expr_not<'i>(input: &mut Span<'i>) -> PResult<'i, ExprResult> { +fn parse_expr_not<'i>(input: &mut Span<'i>) -> PResult { trace( "parse_expr_not", ( @@ -747,7 +731,7 @@ impl fmt::Display for OrOperator { } } -fn parse_expr<'i>(input: &mut Span<'i>) -> PResult<'i, ExprResult> { +fn parse_expr<'i>(input: &mut Span<'i>) -> PResult { trace("parse_expr", |input: &mut _| { // "or" binds less tightly than "and", so parse and within or. let expr = expect_expr(parse_and_or_difference_expr).parse_next(input)?; @@ -779,7 +763,7 @@ fn parse_expr<'i>(input: &mut Span<'i>) -> PResult<'i, ExprResult> { .parse_next(input) } -fn parse_or_operator<'i>(input: &mut Span<'i>) -> PResult<'i, Option> { +fn parse_or_operator<'i>(input: &mut Span<'i>) -> PResult> { trace( "parse_or_operator", ws(alt(( @@ -846,7 +830,7 @@ enum AndOrDifferenceOperator { Difference(DifferenceOperator), } -fn parse_and_or_difference_expr<'i>(input: &mut Span<'i>) -> PResult<'i, ExprResult> { +fn parse_and_or_difference_expr<'i>(input: &mut Span<'i>) -> PResult { trace("parse_and_or_difference_expr", |input: &mut _| { let expr = expect_expr(parse_basic_expr).parse_next(input)?; @@ -883,7 +867,7 @@ fn parse_and_or_difference_expr<'i>(input: &mut Span<'i>) -> PResult<'i, ExprRes fn parse_and_or_difference_operator<'i>( input: &mut Span<'i>, -) -> PResult<'i, Option> { +) -> PResult> { trace( "parse_and_or_difference_operator", ws(alt(( @@ -908,9 +892,7 @@ fn parse_and_or_difference_operator<'i>( // --- -pub(crate) fn parse( - input: Span<'_>, -) -> Result>>> { +pub(crate) fn parse(input: Span<'_>) -> Result> { let (_, expr) = terminated( parse_expr, expect(ws(eof), ParseSingleError::ExpectedEndOfExpression), @@ -1433,7 +1415,7 @@ mod tests { // string parsing is compatible with possible future syntax fn parse_future_syntax<'i>( input: &mut Span<'i>, - ) -> PResult<'i, (Option, Option)> { + ) -> PResult<(Option, Option)> { let _ = "something".parse_next(input)?; let _ = '('.parse_next(input)?; let n1 = set_matcher(DefaultMatcher::Contains).parse_next(input)?; diff --git a/nextest-filtering/src/parsing/glob.rs b/nextest-filtering/src/parsing/glob.rs index 19a9d644254..3dbb12e6d95 100644 --- a/nextest-filtering/src/parsing/glob.rs +++ b/nextest-filtering/src/parsing/glob.rs @@ -60,9 +60,7 @@ impl GenericGlob { } // This never returns Err(()) -- instead, it reports an error to the parsing state. -pub(super) fn parse_glob<'i>( - implicit: bool, -) -> impl Parser, Option, Error<'i>> { +pub(super) fn parse_glob<'i>(implicit: bool) -> impl Parser, Option, Error> { trace("parse_glob", move |input: &mut Span<'i>| { let start = input.location(); let res = match parse_matcher_text.parse_next(input) { diff --git a/nextest-filtering/src/parsing/unicode_string.rs b/nextest-filtering/src/parsing/unicode_string.rs index 9b24ee0f7e7..7926d123fe7 100644 --- a/nextest-filtering/src/parsing/unicode_string.rs +++ b/nextest-filtering/src/parsing/unicode_string.rs @@ -13,7 +13,7 @@ use winnow::{ Parser, }; -fn parse_unicode<'i>(input: &mut Span<'i>) -> PResult<'i, char> { +fn parse_unicode<'i>(input: &mut Span<'i>) -> PResult { trace("parse_unicode", |input: &mut _| { let parse_hex = take_while(1..=6, |c: char| c.is_ascii_hexdigit()); let parse_delimited_hex = preceded('u', delimited('{', parse_hex, '}')); @@ -23,7 +23,7 @@ fn parse_unicode<'i>(input: &mut Span<'i>) -> PResult<'i, char> { .parse_next(input) } -fn parse_escaped_char<'i>(input: &mut Span<'i>) -> PResult<'i, Option> { +fn parse_escaped_char<'i>(input: &mut Span<'i>) -> PResult> { trace("parse_escaped_char", |input: &mut _| { let valid = alt(( parse_unicode, @@ -70,7 +70,7 @@ impl fmt::Display for DisplayParsedString<'_> { Ok(()) } } -fn parse_literal<'i>(input: &mut Span<'i>) -> PResult<'i, &'i str> { +fn parse_literal<'i>(input: &mut Span<'i>) -> PResult<&'i str> { trace("parse_literal", |input: &mut _| { let not_quote_slash = take_till(1.., (',', ')', '\\')); let res = not_quote_slash @@ -87,7 +87,7 @@ enum StringFragment<'a> { EscapedChar(char), } -fn parse_fragment<'i>(input: &mut Span<'i>) -> PResult<'i, Option>> { +fn parse_fragment<'i>(input: &mut Span<'i>) -> PResult>> { trace( "parse_fragment", alt(( @@ -101,7 +101,7 @@ fn parse_fragment<'i>(input: &mut Span<'i>) -> PResult<'i, Option(input: &mut Span<'i>) -> PResult<'i, Option> { +pub(super) fn parse_string<'i>(input: &mut Span<'i>) -> PResult> { trace( "parse_string", fold_repeat(