diff --git a/rinja_parser/Cargo.toml b/rinja_parser/Cargo.toml index d208eb3c6..36e89a406 100644 --- a/rinja_parser/Cargo.toml +++ b/rinja_parser/Cargo.toml @@ -24,7 +24,7 @@ harness = false [dependencies] memchr = "2" serde = { version = "1.0", optional = true, features = ["derive"] } -winnow = "0.5" +winnow = "0.6" [dev-dependencies] criterion = "0.5" diff --git a/rinja_parser/src/expr.rs b/rinja_parser/src/expr.rs index f0a802fab..2c37735ea 100644 --- a/rinja_parser/src/expr.rs +++ b/rinja_parser/src/expr.rs @@ -469,7 +469,7 @@ impl<'a> Expr<'a> { fn num(i: &mut &'a str) -> ParseResult<'a, WithSpan<'a, Self>> { let start = *i; - let (num, full) = num_lit.with_recognized().parse_next(i)?; + let (num, full) = num_lit.with_taken().parse_next(i)?; Ok(WithSpan::new(Expr::NumLit(full, num), start)) } @@ -647,7 +647,7 @@ impl<'a> Suffix<'a> { preceded( (ws('!'), '('), cut_err(terminated( - nested_parenthesis.recognize().map(Self::MacroCall), + nested_parenthesis.take().map(Self::MacroCall), ')', )), ) diff --git a/rinja_parser/src/lib.rs b/rinja_parser/src/lib.rs index 7ab0d3bd8..278eb29e8 100644 --- a/rinja_parser/src/lib.rs +++ b/rinja_parser/src/lib.rs @@ -11,7 +11,7 @@ use std::sync::Arc; use std::{fmt, str}; use winnow::Parser; -use winnow::ascii::escaped; +use winnow::ascii::take_escaped; use winnow::combinator::{alt, cut_err, delimited, fail, not, opt, peek, preceded, repeat}; use winnow::error::{ErrorKind, FromExternalError}; use winnow::stream::{AsChar, Stream as _}; @@ -312,7 +312,12 @@ impl<'a> winnow::error::ParserError<&'a str> for ErrorContext<'a> { } } - fn append(self, _: &&'a str, _: ErrorKind) -> Self { + fn append( + self, + _: &&'a str, + _: &<&str as winnow::stream::Stream>::Checkpoint, + _: ErrorKind, + ) -> Self { self } } @@ -394,7 +399,7 @@ fn identifier<'i>(input: &mut &'i str) -> ParseResult<'i> { c.is_alphanum() || c == '_' || c >= '\u{0080}' }); - (start, opt(tail)).recognize().parse_next(input) + (start, opt(tail)).take().parse_next(input) } fn bool_lit<'i>(i: &mut &'i str) -> ParseResult<'i> { @@ -434,7 +439,7 @@ fn num_lit<'a>(i: &mut &'a str) -> ParseResult<'a, Num<'a>> { // Equivalent to . let int_with_base = (opt('-'), |i: &mut _| { let (base, kind) = preceded('0', alt(('b'.value(2), 'o'.value(8), 'x'.value(16)))) - .with_recognized() + .with_taken() .parse_next(i)?; match opt(separated_digits(base, false)).parse_next(i)? { Some(_) => Ok(()), @@ -469,13 +474,13 @@ fn num_lit<'a>(i: &mut &'a str) -> ParseResult<'a, Num<'a>> { } }; - let num = if let Ok(Some(num)) = opt(int_with_base.recognize()).parse_next(i) { + let num = if let Ok(Some(num)) = opt(int_with_base.take()).parse_next(i) { let suffix = opt(|i: &mut _| num_lit_suffix("integer", INTEGER_TYPES, start, i)).parse_next(i)?; Num::Int(num, suffix) } else { let (float, num) = preceded((opt('-'), separated_digits(10, true)), opt(float)) - .with_recognized() + .with_taken() .parse_next(i)?; if float.is_some() { let suffix = @@ -508,7 +513,7 @@ fn separated_digits<'a>( one_of(move |ch: char| ch.is_digit(radix)), repeat(0.., one_of(move |ch: char| ch == '_' || ch.is_digit(radix))).map(|()| ()), ) - .recognize() + .take() } #[derive(Clone, Copy, Debug, PartialEq)] @@ -544,7 +549,7 @@ pub struct StrLit<'a> { fn str_lit_without_prefix<'a>(i: &mut &'a str) -> ParseResult<'a> { let s = delimited( '"', - opt(escaped(take_till(1.., ['\\', '"']), '\\', any)), + opt(take_escaped(take_till(1.., ['\\', '"']), '\\', any)), '"', ) .parse_next(i)?; @@ -580,14 +585,14 @@ fn char_lit<'a>(i: &mut &'a str) -> ParseResult<'a, CharLit<'a>> { opt('b'), delimited( '\'', - opt(escaped(take_till(1.., ['\\', '\'']), '\\', any)), + opt(take_escaped(take_till(1.., ['\\', '\'']), '\\', any)), '\'', ), ) .parse_next(i)?; let Some(s) = s else { - i.reset(start); + i.reset(&start); return Err(winnow::error::ErrMode::Cut(ErrorContext::new( "empty character literal", *i, @@ -595,7 +600,7 @@ fn char_lit<'a>(i: &mut &'a str) -> ParseResult<'a, CharLit<'a>> { }; let mut is = s; let Ok(c) = Char::parse(&mut is) else { - i.reset(start); + i.reset(&start); return Err(winnow::error::ErrMode::Cut(ErrorContext::new( "invalid character", *i, @@ -626,11 +631,11 @@ fn char_lit<'a>(i: &mut &'a str) -> ParseResult<'a, CharLit<'a>> { }; let Ok(nb) = u32::from_str_radix(nb, 16) else { - i.reset(start); + i.reset(&start); return Err(winnow::error::ErrMode::Cut(ErrorContext::new(err1, *i))); }; if nb > max_value { - i.reset(start); + i.reset(&start); return Err(winnow::error::ErrMode::Cut(ErrorContext::new(err2, *i))); } diff --git a/rinja_parser/src/node.rs b/rinja_parser/src/node.rs index 25133671d..fff88b0b3 100644 --- a/rinja_parser/src/node.rs +++ b/rinja_parser/src/node.rs @@ -315,7 +315,7 @@ impl<'a> When<'a> { ), ), )) - .with_recognized() + .with_taken() .map(|((pws, _), span)| { // A comment node is used to pass the whitespace suppressing information to the // generator. This way we don't have to fix up the next `when` node or the closing @@ -1071,7 +1071,7 @@ impl<'a> Lit<'a> { literal(s.syntax.expr_start), )); - let content = opt(skip_till(candidate_finder, p_start).recognize()).parse_next(i)?; + let content = opt(skip_till(candidate_finder, p_start).take()).parse_next(i)?; let content = match content { Some("") => { // {block,comment,expr}_start follows immediately. @@ -1121,7 +1121,7 @@ impl<'a> Raw<'a> { ( opt(Whitespace::parse), |i: &mut _| s.tag_block_end(i), - skip_till(Splitter1::new(s.syntax.block_start), endraw).with_recognized(), + skip_till(Splitter1::new(s.syntax.block_start), endraw).with_taken(), ), ), ); @@ -1378,13 +1378,13 @@ fn end_node<'a, 'g: 'a>( if actual == expected { Ok(actual) } else if actual.starts_with("end") { - i.reset(start); + i.reset(&start); Err(winnow::error::ErrMode::Cut(ErrorContext::new( format!("expected `{expected}` to terminate `{node}` node, found `{actual}`"), *i, ))) } else { - i.reset(start); + i.reset(&start); fail.parse_next(i) } } diff --git a/rinja_parser/src/target.rs b/rinja_parser/src/target.rs index b47868a56..58de02492 100644 --- a/rinja_parser/src/target.rs +++ b/rinja_parser/src/target.rs @@ -122,7 +122,7 @@ impl<'a> Target<'a> { str_lit.map(Self::StrLit), char_lit.map(Self::CharLit), num_lit - .with_recognized() + .with_taken() .map(|(num, full)| Target::NumLit(full, num)), bool_lit.map(Self::BoolLit), )) @@ -135,7 +135,7 @@ impl<'a> Target<'a> { fn named(i: &mut &'a str, s: &State<'_>) -> ParseResult<'a, (&'a str, Self)> { let start = *i; - let rest = opt(Self::rest.with_recognized()).parse_next(i)?; + let rest = opt(Self::rest.with_taken()).parse_next(i)?; if let Some(rest) = rest { let chr = peek(ws(opt(one_of([',', ':'])))).parse_next(i)?; if let Some(chr) = chr {