diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
commit | d1b2d29528b7794b41e66fc2136e395a02f8529b (patch) | |
tree | a4a17504b260206dec3cf55b2dca82929a348ac2 /vendor/toml_edit/src/parser | |
parent | Releasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip |
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/toml_edit/src/parser')
-rw-r--r-- | vendor/toml_edit/src/parser/array.rs | 25 | ||||
-rw-r--r-- | vendor/toml_edit/src/parser/datetime.rs | 153 | ||||
-rw-r--r-- | vendor/toml_edit/src/parser/document.rs | 105 | ||||
-rw-r--r-- | vendor/toml_edit/src/parser/errors.rs | 172 | ||||
-rw-r--r-- | vendor/toml_edit/src/parser/inline_table.rs | 31 | ||||
-rw-r--r-- | vendor/toml_edit/src/parser/key.rs | 76 | ||||
-rw-r--r-- | vendor/toml_edit/src/parser/macros.rs | 13 | ||||
-rw-r--r-- | vendor/toml_edit/src/parser/mod.rs | 67 | ||||
-rw-r--r-- | vendor/toml_edit/src/parser/numbers.rs | 260 | ||||
-rw-r--r-- | vendor/toml_edit/src/parser/strings.rs | 206 | ||||
-rw-r--r-- | vendor/toml_edit/src/parser/table.rs | 30 | ||||
-rw-r--r-- | vendor/toml_edit/src/parser/trivia.rs | 18 | ||||
-rw-r--r-- | vendor/toml_edit/src/parser/value.rs | 44 |
13 files changed, 520 insertions, 680 deletions
diff --git a/vendor/toml_edit/src/parser/array.rs b/vendor/toml_edit/src/parser/array.rs index a99bb8241..e3b1f3f52 100644 --- a/vendor/toml_edit/src/parser/array.rs +++ b/vendor/toml_edit/src/parser/array.rs @@ -2,6 +2,7 @@ use winnow::combinator::cut_err; use winnow::combinator::delimited; use winnow::combinator::opt; use winnow::combinator::separated1; +use winnow::trace::trace; use crate::parser::trivia::ws_comment_newline; use crate::parser::value::value; @@ -12,19 +13,17 @@ use crate::parser::prelude::*; // ;; Array // array = array-open array-values array-close -pub(crate) fn array( - check: RecursionCheck, -) -> impl FnMut(Input<'_>) -> IResult<Input<'_>, Array, ParserError<'_>> { - move |input| { +pub(crate) fn array<'i>(check: RecursionCheck) -> impl Parser<Input<'i>, Array, ContextError> { + trace("array", move |input: &mut Input<'i>| { delimited( ARRAY_OPEN, cut_err(array_values(check)), cut_err(ARRAY_CLOSE) - .context(Context::Expression("array")) - .context(Context::Expected(ParserValue::CharLiteral(']'))), + .context(StrContext::Label("array")) + .context(StrContext::Expected(StrContextValue::CharLiteral(']'))), ) .parse_next(input) - } + }) } // note: we're omitting ws and newlines here, because @@ -39,10 +38,10 @@ const ARRAY_SEP: u8 = b','; // note: this rule is modified // array-values = [ ( array-value array-sep array-values ) / // array-value / ws-comment-newline ] -pub(crate) fn array_values( +pub(crate) fn array_values<'i>( check: RecursionCheck, -) -> impl FnMut(Input<'_>) -> IResult<Input<'_>, Array, ParserError<'_>> { - move |input| { +) -> impl Parser<Input<'i>, Array, ContextError> { + move |input: &mut Input<'i>| { let check = check.recursing(input)?; ( opt( @@ -67,10 +66,10 @@ pub(crate) fn array_values( } } -pub(crate) fn array_value( +pub(crate) fn array_value<'i>( check: RecursionCheck, -) -> impl FnMut(Input<'_>) -> IResult<Input<'_>, Value, ParserError<'_>> { - move |input| { +) -> impl Parser<Input<'i>, Value, ContextError> { + move |input: &mut Input<'i>| { ( ws_comment_newline.span(), value(check), diff --git a/vendor/toml_edit/src/parser/datetime.rs b/vendor/toml_edit/src/parser/datetime.rs index 122a00f5a..6e89b9779 100644 --- a/vendor/toml_edit/src/parser/datetime.rs +++ b/vendor/toml_edit/src/parser/datetime.rs @@ -11,6 +11,7 @@ use winnow::combinator::opt; use winnow::combinator::preceded; use winnow::token::one_of; use winnow::token::take_while; +use winnow::trace::trace; // ;; Date and Time (as defined in RFC 3339) @@ -20,89 +21,101 @@ use winnow::token::take_while; // local-date = full-date // local-time = partial-time // full-time = partial-time time-offset -pub(crate) fn date_time(input: Input<'_>) -> IResult<Input<'_>, Datetime, ParserError<'_>> { - alt(( - (full_date, opt((time_delim, partial_time, opt(time_offset)))) - .map(|(date, opt)| { - match opt { - // Offset Date-Time - Some((_, time, offset)) => Datetime { - date: Some(date), - time: Some(time), - offset, - }, - // Local Date - None => Datetime { - date: Some(date), - time: None, - offset: None, - }, - } - }) - .context(Context::Expression("date-time")), - partial_time - .map(|t| t.into()) - .context(Context::Expression("time")), - )) +pub(crate) fn date_time(input: &mut Input<'_>) -> PResult<Datetime> { + trace( + "date-time", + alt(( + (full_date, opt((time_delim, partial_time, opt(time_offset)))) + .map(|(date, opt)| { + match opt { + // Offset Date-Time + Some((_, time, offset)) => Datetime { + date: Some(date), + time: Some(time), + offset, + }, + // Local Date + None => Datetime { + date: Some(date), + time: None, + offset: None, + }, + } + }) + .context(StrContext::Label("date-time")), + partial_time + .map(|t| t.into()) + .context(StrContext::Label("time")), + )), + ) .parse_next(input) } // full-date = date-fullyear "-" date-month "-" date-mday -pub(crate) fn full_date(input: Input<'_>) -> IResult<Input<'_>, Date, ParserError<'_>> { - (date_fullyear, b'-', cut_err((date_month, b'-', date_mday))) - .map(|(year, _, (month, _, day))| Date { year, month, day }) - .parse_next(input) +pub(crate) fn full_date(input: &mut Input<'_>) -> PResult<Date> { + trace( + "full-date", + (date_fullyear, b'-', cut_err((date_month, b'-', date_mday))) + .map(|(year, _, (month, _, day))| Date { year, month, day }), + ) + .parse_next(input) } // partial-time = time-hour ":" time-minute ":" time-second [time-secfrac] -pub(crate) fn partial_time(input: Input<'_>) -> IResult<Input<'_>, Time, ParserError<'_>> { - ( - time_hour, - b':', - cut_err((time_minute, b':', time_second, opt(time_secfrac))), +pub(crate) fn partial_time(input: &mut Input<'_>) -> PResult<Time> { + trace( + "partial-time", + ( + time_hour, + b':', + cut_err((time_minute, b':', time_second, opt(time_secfrac))), + ) + .map(|(hour, _, (minute, _, second, nanosecond))| Time { + hour, + minute, + second, + nanosecond: nanosecond.unwrap_or_default(), + }), ) - .map(|(hour, _, (minute, _, second, nanosecond))| Time { - hour, - minute, - second, - nanosecond: nanosecond.unwrap_or_default(), - }) - .parse_next(input) + .parse_next(input) } // time-offset = "Z" / time-numoffset // time-numoffset = ( "+" / "-" ) time-hour ":" time-minute -pub(crate) fn time_offset(input: Input<'_>) -> IResult<Input<'_>, Offset, ParserError<'_>> { - alt(( - one_of((b'Z', b'z')).value(Offset::Z), - ( - one_of((b'+', b'-')), - cut_err((time_hour, b':', time_minute)), - ) - .map(|(sign, (hours, _, minutes))| { - let sign = match sign { - b'+' => 1, - b'-' => -1, - _ => unreachable!("Parser prevents this"), - }; - sign * (hours as i16 * 60 + minutes as i16) - }) - .verify(|minutes| ((-24 * 60)..=(24 * 60)).contains(minutes)) - .map(|minutes| Offset::Custom { minutes }), - )) - .context(Context::Expression("time offset")) +pub(crate) fn time_offset(input: &mut Input<'_>) -> PResult<Offset> { + trace( + "time-offset", + alt(( + one_of((b'Z', b'z')).value(Offset::Z), + ( + one_of((b'+', b'-')), + cut_err((time_hour, b':', time_minute)), + ) + .map(|(sign, (hours, _, minutes))| { + let sign = match sign { + b'+' => 1, + b'-' => -1, + _ => unreachable!("Parser prevents this"), + }; + sign * (hours as i16 * 60 + minutes as i16) + }) + .verify(|minutes| ((-24 * 60)..=(24 * 60)).contains(minutes)) + .map(|minutes| Offset::Custom { minutes }), + )) + .context(StrContext::Label("time offset")), + ) .parse_next(input) } // date-fullyear = 4DIGIT -pub(crate) fn date_fullyear(input: Input<'_>) -> IResult<Input<'_>, u16, ParserError<'_>> { +pub(crate) fn date_fullyear(input: &mut Input<'_>) -> PResult<u16> { unsigned_digits::<4, 4> .map(|s: &str| s.parse::<u16>().expect("4DIGIT should match u8")) .parse_next(input) } // date-month = 2DIGIT ; 01-12 -pub(crate) fn date_month(input: Input<'_>) -> IResult<Input<'_>, u8, ParserError<'_>> { +pub(crate) fn date_month(input: &mut Input<'_>) -> PResult<u8> { unsigned_digits::<2, 2> .try_map(|s: &str| { let d = s.parse::<u8>().expect("2DIGIT should match u8"); @@ -116,7 +129,7 @@ pub(crate) fn date_month(input: Input<'_>) -> IResult<Input<'_>, u8, ParserError } // date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on month/year -pub(crate) fn date_mday(input: Input<'_>) -> IResult<Input<'_>, u8, ParserError<'_>> { +pub(crate) fn date_mday(input: &mut Input<'_>) -> PResult<u8> { unsigned_digits::<2, 2> .try_map(|s: &str| { let d = s.parse::<u8>().expect("2DIGIT should match u8"); @@ -130,14 +143,14 @@ pub(crate) fn date_mday(input: Input<'_>) -> IResult<Input<'_>, u8, ParserError< } // time-delim = "T" / %x20 ; T, t, or space -pub(crate) fn time_delim(input: Input<'_>) -> IResult<Input<'_>, u8, ParserError<'_>> { +pub(crate) fn time_delim(input: &mut Input<'_>) -> PResult<u8> { one_of(TIME_DELIM).parse_next(input) } const TIME_DELIM: (u8, u8, u8) = (b'T', b't', b' '); // time-hour = 2DIGIT ; 00-23 -pub(crate) fn time_hour(input: Input<'_>) -> IResult<Input<'_>, u8, ParserError<'_>> { +pub(crate) fn time_hour(input: &mut Input<'_>) -> PResult<u8> { unsigned_digits::<2, 2> .try_map(|s: &str| { let d = s.parse::<u8>().expect("2DIGIT should match u8"); @@ -151,7 +164,7 @@ pub(crate) fn time_hour(input: Input<'_>) -> IResult<Input<'_>, u8, ParserError< } // time-minute = 2DIGIT ; 00-59 -pub(crate) fn time_minute(input: Input<'_>) -> IResult<Input<'_>, u8, ParserError<'_>> { +pub(crate) fn time_minute(input: &mut Input<'_>) -> PResult<u8> { unsigned_digits::<2, 2> .try_map(|s: &str| { let d = s.parse::<u8>().expect("2DIGIT should match u8"); @@ -165,7 +178,7 @@ pub(crate) fn time_minute(input: Input<'_>) -> IResult<Input<'_>, u8, ParserErro } // time-second = 2DIGIT ; 00-58, 00-59, 00-60 based on leap second rules -pub(crate) fn time_second(input: Input<'_>) -> IResult<Input<'_>, u8, ParserError<'_>> { +pub(crate) fn time_second(input: &mut Input<'_>) -> PResult<u8> { unsigned_digits::<2, 2> .try_map(|s: &str| { let d = s.parse::<u8>().expect("2DIGIT should match u8"); @@ -179,7 +192,7 @@ pub(crate) fn time_second(input: Input<'_>) -> IResult<Input<'_>, u8, ParserErro } // time-secfrac = "." 1*DIGIT -pub(crate) fn time_secfrac(input: Input<'_>) -> IResult<Input<'_>, u32, ParserError<'_>> { +pub(crate) fn time_secfrac(input: &mut Input<'_>) -> PResult<u32> { static SCALE: [u32; 10] = [ 0, 100_000_000, @@ -214,9 +227,9 @@ pub(crate) fn time_secfrac(input: Input<'_>) -> IResult<Input<'_>, u32, ParserEr .parse_next(input) } -pub(crate) fn unsigned_digits<const MIN: usize, const MAX: usize>( - input: Input<'_>, -) -> IResult<Input<'_>, &str, ParserError<'_>> { +pub(crate) fn unsigned_digits<'i, const MIN: usize, const MAX: usize>( + input: &mut Input<'i>, +) -> PResult<&'i str> { take_while(MIN..=MAX, DIGIT) .map(|b: &[u8]| unsafe { from_utf8_unchecked(b, "`is_ascii_digit` filters out on-ASCII") }) .parse_next(input) diff --git a/vendor/toml_edit/src/parser/document.rs b/vendor/toml_edit/src/parser/document.rs index 791185b68..aa8fb1158 100644 --- a/vendor/toml_edit/src/parser/document.rs +++ b/vendor/toml_edit/src/parser/document.rs @@ -5,9 +5,9 @@ use winnow::combinator::eof; use winnow::combinator::opt; use winnow::combinator::peek; use winnow::combinator::repeat; -use winnow::error::FromExternalError; use winnow::token::any; use winnow::token::one_of; +use winnow::trace::trace; use crate::document::Document; use crate::key::Key; @@ -30,11 +30,11 @@ use crate::RawString; // ( ws keyval ws [ comment ] ) / // ( ws table ws [ comment ] ) / // ws ) -pub(crate) fn document(input: Input<'_>) -> IResult<Input<'_>, Document, ParserError<'_>> { +pub(crate) fn document(input: &mut Input<'_>) -> PResult<Document> { let state = RefCell::new(ParseState::default()); let state_ref = &state; - let (i, _o) = ( + let _o = ( // Remove BOM if present opt(b"\xEF\xBB\xBF"), parse_ws(state_ref), @@ -52,23 +52,15 @@ pub(crate) fn document(input: Input<'_>) -> IResult<Input<'_>, Document, ParserE eof, ) .parse_next(input)?; - state - .into_inner() - .into_document() - .map(|document| (i, document)) - .map_err(|err| { - winnow::error::ErrMode::Backtrack(ParserError::from_external_error( - i, - winnow::error::ErrorKind::Verify, - err, - )) - }) + state.into_inner().into_document().map_err(|err| { + winnow::error::ErrMode::from_external_error(input, winnow::error::ErrorKind::Verify, err) + }) } pub(crate) fn parse_comment<'s, 'i>( state: &'s RefCell<ParseState>, -) -> impl FnMut(Input<'i>) -> IResult<Input<'i>, (), ParserError<'_>> + 's { - move |i| { +) -> impl Parser<Input<'i>, (), ContextError> + 's { + move |i: &mut Input<'i>| { (comment, line_ending) .span() .map(|span| { @@ -80,8 +72,8 @@ pub(crate) fn parse_comment<'s, 'i>( pub(crate) fn parse_ws<'s, 'i>( state: &'s RefCell<ParseState>, -) -> impl FnMut(Input<'i>) -> IResult<Input<'i>, (), ParserError<'i>> + 's { - move |i| { +) -> impl Parser<Input<'i>, (), ContextError> + 's { + move |i: &mut Input<'i>| { ws.span() .map(|span| state.borrow_mut().on_ws(span)) .parse_next(i) @@ -90,8 +82,8 @@ pub(crate) fn parse_ws<'s, 'i>( pub(crate) fn parse_newline<'s, 'i>( state: &'s RefCell<ParseState>, -) -> impl FnMut(Input<'i>) -> IResult<Input<'i>, (), ParserError<'i>> + 's { - move |i| { +) -> impl Parser<Input<'i>, (), ContextError> + 's { + move |i: &mut Input<'i>| { newline .span() .map(|span| state.borrow_mut().on_ws(span)) @@ -101,8 +93,8 @@ pub(crate) fn parse_newline<'s, 'i>( pub(crate) fn keyval<'s, 'i>( state: &'s RefCell<ParseState>, -) -> impl FnMut(Input<'i>) -> IResult<Input<'i>, (), ParserError<'i>> + 's { - move |i| { +) -> impl Parser<Input<'i>, (), ContextError> + 's { + move |i: &mut Input<'i>| { parse_keyval .try_map(|(p, kv)| state.borrow_mut().on_keyval(p, kv)) .parse_next(i) @@ -110,39 +102,40 @@ pub(crate) fn keyval<'s, 'i>( } // keyval = key keyval-sep val -pub(crate) fn parse_keyval( - input: Input<'_>, -) -> IResult<Input<'_>, (Vec<Key>, TableKeyValue), ParserError<'_>> { - ( - key, - cut_err(( - one_of(KEYVAL_SEP) - .context(Context::Expected(ParserValue::CharLiteral('.'))) - .context(Context::Expected(ParserValue::CharLiteral('='))), - ( - ws.span(), - value(RecursionCheck::default()), - line_trailing - .context(Context::Expected(ParserValue::CharLiteral('\n'))) - .context(Context::Expected(ParserValue::CharLiteral('#'))), - ), - )), - ) - .try_map::<_, _, std::str::Utf8Error>(|(key, (_, v))| { - let mut path = key; - let key = path.pop().expect("grammar ensures at least 1"); +pub(crate) fn parse_keyval(input: &mut Input<'_>) -> PResult<(Vec<Key>, TableKeyValue)> { + trace( + "keyval", + ( + key, + cut_err(( + one_of(KEYVAL_SEP) + .context(StrContext::Expected(StrContextValue::CharLiteral('.'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('='))), + ( + ws.span(), + value(RecursionCheck::default()), + line_trailing + .context(StrContext::Expected(StrContextValue::CharLiteral('\n'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('#'))), + ), + )), + ) + .try_map::<_, _, std::str::Utf8Error>(|(key, (_, v))| { + let mut path = key; + let key = path.pop().expect("grammar ensures at least 1"); - let (pre, v, suf) = v; - let pre = RawString::with_span(pre); - let suf = RawString::with_span(suf); - let v = v.decorated(pre, suf); - Ok(( - path, - TableKeyValue { - key, - value: Item::Value(v), - }, - )) - }) - .parse_next(input) + let (pre, v, suf) = v; + let pre = RawString::with_span(pre); + let suf = RawString::with_span(suf); + let v = v.decorated(pre, suf); + Ok(( + path, + TableKeyValue { + key, + value: Item::Value(v), + }, + )) + }), + ) + .parse_next(input) } diff --git a/vendor/toml_edit/src/parser/errors.rs b/vendor/toml_edit/src/parser/errors.rs index 4e3825f99..859ed5334 100644 --- a/vendor/toml_edit/src/parser/errors.rs +++ b/vendor/toml_edit/src/parser/errors.rs @@ -4,7 +4,8 @@ use std::fmt::{Display, Formatter, Result}; use crate::parser::prelude::*; use crate::Key; -use winnow::BStr; +use winnow::error::ContextError; +use winnow::error::ParseError; /// Type representing a TOML parse error #[derive(Debug, Clone, Eq, PartialEq, Hash)] @@ -16,19 +17,18 @@ pub struct TomlError { } impl TomlError { - pub(crate) fn new(error: ParserError<'_>, original: Input<'_>) -> Self { - use winnow::stream::Offset; + pub(crate) fn new(error: ParseError<Input<'_>, ContextError>, mut original: Input<'_>) -> Self { use winnow::stream::Stream; - let offset = original.offset_to(&error.input); + let offset = error.offset(); let span = if offset == original.len() { offset..offset } else { offset..(offset + 1) }; - let message = error.to_string(); - let original = original.next_slice(original.eof_offset()).1; + let message = error.inner().to_string(); + let original = original.finish(); Self { message, @@ -146,166 +146,6 @@ impl StdError for TomlError { } } -#[derive(Debug)] -pub(crate) struct ParserError<'b> { - input: Input<'b>, - context: Vec<Context>, - cause: Option<Box<dyn std::error::Error + Send + Sync + 'static>>, -} - -impl<'b> winnow::error::ParseError<Input<'b>> for ParserError<'b> { - fn from_error_kind(input: Input<'b>, _kind: winnow::error::ErrorKind) -> Self { - Self { - input, - context: Default::default(), - cause: Default::default(), - } - } - - fn append(self, _input: Input<'b>, _kind: winnow::error::ErrorKind) -> Self { - self - } - - fn or(self, other: Self) -> Self { - other - } -} - -impl<'b> winnow::error::ParseError<&'b str> for ParserError<'b> { - fn from_error_kind(input: &'b str, _kind: winnow::error::ErrorKind) -> Self { - Self { - input: Input::new(BStr::new(input)), - context: Default::default(), - cause: Default::default(), - } - } - - fn append(self, _input: &'b str, _kind: winnow::error::ErrorKind) -> Self { - self - } - - fn or(self, other: Self) -> Self { - other - } -} - -impl<'b> winnow::error::ContextError<Input<'b>, Context> for ParserError<'b> { - fn add_context(mut self, _input: Input<'b>, ctx: Context) -> Self { - self.context.push(ctx); - self - } -} - -impl<'b, E: std::error::Error + Send + Sync + 'static> - winnow::error::FromExternalError<Input<'b>, E> for ParserError<'b> -{ - fn from_external_error(input: Input<'b>, _kind: winnow::error::ErrorKind, e: E) -> Self { - Self { - input, - context: Default::default(), - cause: Some(Box::new(e)), - } - } -} - -impl<'b, E: std::error::Error + Send + Sync + 'static> winnow::error::FromExternalError<&'b str, E> - for ParserError<'b> -{ - fn from_external_error(input: &'b str, _kind: winnow::error::ErrorKind, e: E) -> Self { - Self { - input: Input::new(BStr::new(input)), - context: Default::default(), - cause: Some(Box::new(e)), - } - } -} - -// For tests -impl<'b> std::cmp::PartialEq for ParserError<'b> { - fn eq(&self, other: &Self) -> bool { - self.input == other.input - && self.context == other.context - && self.cause.as_ref().map(ToString::to_string) - == other.cause.as_ref().map(ToString::to_string) - } -} - -impl<'a> std::fmt::Display for ParserError<'a> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let expression = self.context.iter().find_map(|c| match c { - Context::Expression(c) => Some(c), - _ => None, - }); - let expected = self - .context - .iter() - .filter_map(|c| match c { - Context::Expected(c) => Some(c), - _ => None, - }) - .collect::<Vec<_>>(); - - let mut newline = false; - - if let Some(expression) = expression { - newline = true; - - write!(f, "invalid {}", expression)?; - } - - if !expected.is_empty() { - if newline { - writeln!(f)?; - } - newline = true; - - write!(f, "expected ")?; - for (i, expected) in expected.iter().enumerate() { - if i != 0 { - write!(f, ", ")?; - } - write!(f, "{}", expected)?; - } - } - if let Some(cause) = &self.cause { - if newline { - writeln!(f)?; - } - write!(f, "{}", cause)?; - } - - Ok(()) - } -} - -#[derive(Copy, Clone, Debug, PartialEq)] -pub(crate) enum Context { - Expression(&'static str), - Expected(ParserValue), -} - -#[derive(Copy, Clone, Debug, PartialEq)] -pub(crate) enum ParserValue { - CharLiteral(char), - StringLiteral(&'static str), - Description(&'static str), -} - -impl std::fmt::Display for ParserValue { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - ParserValue::CharLiteral('\n') => "newline".fmt(f), - ParserValue::CharLiteral('`') => "'`'".fmt(f), - ParserValue::CharLiteral(c) if c.is_ascii_control() => { - write!(f, "`{}`", c.escape_debug()) - } - ParserValue::CharLiteral(c) => write!(f, "`{}`", c), - ParserValue::StringLiteral(c) => write!(f, "`{}`", c), - ParserValue::Description(c) => write!(f, "{}", c), - } - } -} - fn translate_position(input: &[u8], index: usize) -> (usize, usize) { if input.is_empty() { return (0, index); diff --git a/vendor/toml_edit/src/parser/inline_table.rs b/vendor/toml_edit/src/parser/inline_table.rs index 0a75c2104..994e00336 100644 --- a/vendor/toml_edit/src/parser/inline_table.rs +++ b/vendor/toml_edit/src/parser/inline_table.rs @@ -2,6 +2,7 @@ use winnow::combinator::cut_err; use winnow::combinator::delimited; use winnow::combinator::separated0; use winnow::token::one_of; +use winnow::trace::trace; use crate::key::Key; use crate::parser::errors::CustomError; @@ -17,19 +18,19 @@ use indexmap::map::Entry; // ;; Inline Table // inline-table = inline-table-open inline-table-keyvals inline-table-close -pub(crate) fn inline_table( +pub(crate) fn inline_table<'i>( check: RecursionCheck, -) -> impl FnMut(Input<'_>) -> IResult<Input<'_>, InlineTable, ParserError<'_>> { - move |input| { +) -> impl Parser<Input<'i>, InlineTable, ContextError> { + trace("inline-table", move |input: &mut Input<'i>| { delimited( INLINE_TABLE_OPEN, cut_err(inline_table_keyvals(check).try_map(|(kv, p)| table_from_pairs(kv, p))), cut_err(INLINE_TABLE_CLOSE) - .context(Context::Expression("inline table")) - .context(Context::Expected(ParserValue::CharLiteral('}'))), + .context(StrContext::Label("inline table")) + .context(StrContext::Expected(StrContextValue::CharLiteral('}'))), ) .parse_next(input) - } + }) } fn table_from_pairs( @@ -96,12 +97,10 @@ pub(crate) const KEYVAL_SEP: u8 = b'='; // ( key keyval-sep val inline-table-sep inline-table-keyvals-non-empty ) / // ( key keyval-sep val ) -fn inline_table_keyvals( +fn inline_table_keyvals<'i>( check: RecursionCheck, -) -> impl FnMut( - Input<'_>, -) -> IResult<Input<'_>, (Vec<(Vec<Key>, TableKeyValue)>, RawString), ParserError<'_>> { - move |input| { +) -> impl Parser<Input<'i>, (Vec<(Vec<Key>, TableKeyValue)>, RawString), ContextError> { + move |input: &mut Input<'i>| { let check = check.recursing(input)?; ( separated0(keyval(check), INLINE_TABLE_SEP), @@ -111,16 +110,16 @@ fn inline_table_keyvals( } } -fn keyval( +fn keyval<'i>( check: RecursionCheck, -) -> impl FnMut(Input<'_>) -> IResult<Input<'_>, (Vec<Key>, TableKeyValue), ParserError<'_>> { - move |input| { +) -> impl Parser<Input<'i>, (Vec<Key>, TableKeyValue), ContextError> { + move |input: &mut Input<'i>| { ( key, cut_err(( one_of(KEYVAL_SEP) - .context(Context::Expected(ParserValue::CharLiteral('.'))) - .context(Context::Expected(ParserValue::CharLiteral('='))), + .context(StrContext::Expected(StrContextValue::CharLiteral('.'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('='))), (ws.span(), value(check), ws.span()), )), ) diff --git a/vendor/toml_edit/src/parser/key.rs b/vendor/toml_edit/src/parser/key.rs index eda319307..12715da19 100644 --- a/vendor/toml_edit/src/parser/key.rs +++ b/vendor/toml_edit/src/parser/key.rs @@ -4,6 +4,7 @@ use winnow::combinator::peek; use winnow::combinator::separated1; use winnow::token::any; use winnow::token::take_while; +use winnow::trace::trace; use crate::key::Key; use crate::parser::errors::CustomError; @@ -16,51 +17,58 @@ use crate::RawString; // key = simple-key / dotted-key // dotted-key = simple-key 1*( dot-sep simple-key ) -pub(crate) fn key(input: Input<'_>) -> IResult<Input<'_>, Vec<Key>, ParserError<'_>> { - separated1( - (ws.span(), simple_key, ws.span()).map(|(pre, (raw, key), suffix)| { - Key::new(key) - .with_repr_unchecked(Repr::new_unchecked(raw)) - .with_decor(Decor::new( - RawString::with_span(pre), - RawString::with_span(suffix), - )) +pub(crate) fn key(input: &mut Input<'_>) -> PResult<Vec<Key>> { + trace( + "dotted-key", + separated1( + (ws.span(), simple_key, ws.span()).map(|(pre, (raw, key), suffix)| { + Key::new(key) + .with_repr_unchecked(Repr::new_unchecked(raw)) + .with_decor(Decor::new( + RawString::with_span(pre), + RawString::with_span(suffix), + )) + }), + DOT_SEP, + ) + .context(StrContext::Label("key")) + .try_map(|k: Vec<_>| { + // Inserting the key will require recursion down the line + RecursionCheck::check_depth(k.len())?; + Ok::<_, CustomError>(k) }), - DOT_SEP, ) - .context(Context::Expression("key")) - .try_map(|k: Vec<_>| { - // Inserting the key will require recursion down the line - RecursionCheck::check_depth(k.len())?; - Ok::<_, CustomError>(k) - }) .parse_next(input) } // simple-key = quoted-key / unquoted-key // quoted-key = basic-string / literal-string -pub(crate) fn simple_key( - input: Input<'_>, -) -> IResult<Input<'_>, (RawString, InternalString), ParserError<'_>> { - dispatch! {peek(any); - crate::parser::strings::QUOTATION_MARK => basic_string - .map(|s: std::borrow::Cow<'_, str>| s.as_ref().into()), - crate::parser::strings::APOSTROPHE => literal_string.map(|s: &str| s.into()), - _ => unquoted_key.map(|s: &str| s.into()), - } - .with_span() - .map(|(k, span)| { - let raw = RawString::with_span(span); - (raw, k) - }) +pub(crate) fn simple_key(input: &mut Input<'_>) -> PResult<(RawString, InternalString)> { + trace( + "simple-key", + dispatch! {peek(any); + crate::parser::strings::QUOTATION_MARK => basic_string + .map(|s: std::borrow::Cow<'_, str>| s.as_ref().into()), + crate::parser::strings::APOSTROPHE => literal_string.map(|s: &str| s.into()), + _ => unquoted_key.map(|s: &str| s.into()), + } + .with_span() + .map(|(k, span)| { + let raw = RawString::with_span(span); + (raw, k) + }), + ) .parse_next(input) } // unquoted-key = 1*( ALPHA / DIGIT / %x2D / %x5F ) ; A-Z / a-z / 0-9 / - / _ -fn unquoted_key(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> { - take_while(1.., UNQUOTED_CHAR) - .map(|b| unsafe { from_utf8_unchecked(b, "`is_unquoted_char` filters out on-ASCII") }) - .parse_next(input) +fn unquoted_key<'i>(input: &mut Input<'i>) -> PResult<&'i str> { + trace( + "unquoted-key", + take_while(1.., UNQUOTED_CHAR) + .map(|b| unsafe { from_utf8_unchecked(b, "`is_unquoted_char` filters out on-ASCII") }), + ) + .parse_next(input) } pub(crate) fn is_unquoted_char(c: u8) -> bool { diff --git a/vendor/toml_edit/src/parser/macros.rs b/vendor/toml_edit/src/parser/macros.rs deleted file mode 100644 index 93050f5ad..000000000 --- a/vendor/toml_edit/src/parser/macros.rs +++ /dev/null @@ -1,13 +0,0 @@ -macro_rules! dispatch { - ($match_parser: expr; $( $pat:pat $(if $pred:expr)? => $expr: expr ),+ $(,)? ) => { - move |i| - { - let (i, initial) = $match_parser.parse_next(i)?; - match initial { - $( - $pat $(if $pred)? => $expr.parse_next(i), - )* - } - } - } -} diff --git a/vendor/toml_edit/src/parser/mod.rs b/vendor/toml_edit/src/parser/mod.rs index b2ce4bc5e..1b3cc4f0c 100644 --- a/vendor/toml_edit/src/parser/mod.rs +++ b/vendor/toml_edit/src/parser/mod.rs @@ -1,8 +1,5 @@ #![allow(clippy::type_complexity)] -#[macro_use] -pub(crate) mod macros; - pub(crate) mod array; pub(crate) mod datetime; pub(crate) mod document; @@ -76,11 +73,13 @@ pub(crate) fn parse_value(raw: &str) -> Result<crate::Value, TomlError> { } pub(crate) mod prelude { - pub(crate) use super::errors::Context; - pub(crate) use super::errors::ParserError; - pub(crate) use super::errors::ParserValue; - pub(crate) use winnow::IResult; - pub(crate) use winnow::Parser as _; + pub(crate) use winnow::combinator::dispatch; + pub(crate) use winnow::error::ContextError; + pub(crate) use winnow::error::FromExternalError; + pub(crate) use winnow::error::StrContext; + pub(crate) use winnow::error::StrContextValue; + pub(crate) use winnow::PResult; + pub(crate) use winnow::Parser; pub(crate) type Input<'b> = winnow::Located<&'b winnow::BStr>; @@ -88,40 +87,6 @@ pub(crate) mod prelude { winnow::Located::new(winnow::BStr::new(s)) } - pub(crate) fn ok_error<I, O, E>( - res: IResult<I, O, E>, - ) -> Result<Option<(I, O)>, winnow::error::ErrMode<E>> { - match res { - Ok(ok) => Ok(Some(ok)), - Err(winnow::error::ErrMode::Backtrack(_)) => Ok(None), - Err(err) => Err(err), - } - } - - #[allow(dead_code)] - pub(crate) fn trace<I: std::fmt::Debug, O: std::fmt::Debug, E: std::fmt::Debug>( - context: impl std::fmt::Display, - mut parser: impl winnow::Parser<I, O, E>, - ) -> impl FnMut(I) -> IResult<I, O, E> { - static DEPTH: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); - move |input: I| { - let depth = DEPTH.fetch_add(1, std::sync::atomic::Ordering::SeqCst) * 2; - eprintln!("{:depth$}--> {} {:?}", "", context, input); - match parser.parse_next(input) { - Ok((i, o)) => { - DEPTH.fetch_sub(1, std::sync::atomic::Ordering::SeqCst); - eprintln!("{:depth$}<-- {} {:?}", "", context, i); - Ok((i, o)) - } - Err(err) => { - DEPTH.fetch_sub(1, std::sync::atomic::Ordering::SeqCst); - eprintln!("{:depth$}<-- {} {:?}", "", context, err); - Err(err) - } - } - } - } - #[cfg(not(feature = "unbounded"))] #[derive(Copy, Clone, Debug, Default)] pub(crate) struct RecursionCheck { @@ -140,18 +105,16 @@ pub(crate) mod prelude { pub(crate) fn recursing( mut self, - input: Input<'_>, - ) -> Result<Self, winnow::error::ErrMode<ParserError<'_>>> { + input: &mut Input<'_>, + ) -> Result<Self, winnow::error::ErrMode<ContextError>> { self.current += 1; if self.current < 128 { Ok(self) } else { - Err(winnow::error::ErrMode::Backtrack( - winnow::error::FromExternalError::from_external_error( - input, - winnow::error::ErrorKind::Eof, - super::errors::CustomError::RecursionLimitExceeded, - ), + Err(winnow::error::ErrMode::from_external_error( + input, + winnow::error::ErrorKind::Eof, + super::errors::CustomError::RecursionLimitExceeded, )) } } @@ -169,8 +132,8 @@ pub(crate) mod prelude { pub(crate) fn recursing( self, - _input: Input<'_>, - ) -> Result<Self, winnow::error::ErrMode<ParserError<'_>>> { + _input: &mut Input<'_>, + ) -> Result<Self, winnow::error::ErrMode<ContextError>> { Ok(self) } } diff --git a/vendor/toml_edit/src/parser/numbers.rs b/vendor/toml_edit/src/parser/numbers.rs index 803cc9d57..6e4757f06 100644 --- a/vendor/toml_edit/src/parser/numbers.rs +++ b/vendor/toml_edit/src/parser/numbers.rs @@ -10,6 +10,7 @@ use winnow::combinator::rest; use winnow::token::one_of; use winnow::token::tag; use winnow::token::take; +use winnow::trace::trace; use crate::parser::prelude::*; use crate::parser::trivia::from_utf8_unchecked; @@ -18,16 +19,16 @@ use crate::parser::trivia::from_utf8_unchecked; // boolean = true / false #[allow(dead_code)] // directly define in `fn value` -pub(crate) fn boolean(input: Input<'_>) -> IResult<Input<'_>, bool, ParserError<'_>> { - alt((true_, false_)).parse_next(input) +pub(crate) fn boolean(input: &mut Input<'_>) -> PResult<bool> { + trace("boolean", alt((true_, false_))).parse_next(input) } -pub(crate) fn true_(input: Input<'_>) -> IResult<Input<'_>, bool, ParserError<'_>> { +pub(crate) fn true_(input: &mut Input<'_>) -> PResult<bool> { (peek(TRUE[0]), cut_err(TRUE)).value(true).parse_next(input) } const TRUE: &[u8] = b"true"; -pub(crate) fn false_(input: Input<'_>) -> IResult<Input<'_>, bool, ParserError<'_>> { +pub(crate) fn false_(input: &mut Input<'_>) -> PResult<bool> { (peek(FALSE[0]), cut_err(FALSE)) .value(false) .parse_next(input) @@ -37,104 +38,119 @@ const FALSE: &[u8] = b"false"; // ;; Integer // integer = dec-int / hex-int / oct-int / bin-int -pub(crate) fn integer(input: Input<'_>) -> IResult<Input<'_>, i64, ParserError<'_>> { +pub(crate) fn integer(input: &mut Input<'_>) -> PResult<i64> { + trace("integer", dispatch! {peek(opt::<_, &[u8], _, _>(take(2usize))); Some(b"0x") => cut_err(hex_int.try_map(|s| i64::from_str_radix(&s.replace('_', ""), 16))), Some(b"0o") => cut_err(oct_int.try_map(|s| i64::from_str_radix(&s.replace('_', ""), 8))), Some(b"0b") => cut_err(bin_int.try_map(|s| i64::from_str_radix(&s.replace('_', ""), 2))), _ => dec_int.and_then(cut_err(rest .try_map(|s: &str| s.replace('_', "").parse()))) - } + }) .parse_next(input) } // dec-int = [ minus / plus ] unsigned-dec-int // unsigned-dec-int = DIGIT / digit1-9 1*( DIGIT / underscore DIGIT ) -pub(crate) fn dec_int(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> { - ( - opt(one_of((b'+', b'-'))), - alt(( - ( - one_of(DIGIT1_9), +pub(crate) fn dec_int<'i>(input: &mut Input<'i>) -> PResult<&'i str> { + trace( + "dec-int", + ( + opt(one_of((b'+', b'-'))), + alt(( + ( + one_of(DIGIT1_9), + repeat( + 0.., + alt(( + digit.value(()), + ( + one_of(b'_'), + cut_err(digit).context(StrContext::Expected( + StrContextValue::Description("digit"), + )), + ) + .value(()), + )), + ) + .map(|()| ()), + ) + .value(()), + digit.value(()), + )), + ) + .recognize() + .map(|b: &[u8]| unsafe { + from_utf8_unchecked(b, "`digit` and `_` filter out non-ASCII") + }) + .context(StrContext::Label("integer")), + ) + .parse_next(input) +} +const DIGIT1_9: RangeInclusive<u8> = b'1'..=b'9'; + +// hex-prefix = %x30.78 ; 0x +// hex-int = hex-prefix HEXDIG *( HEXDIG / underscore HEXDIG ) +pub(crate) fn hex_int<'i>(input: &mut Input<'i>) -> PResult<&'i str> { + trace( + "hex-int", + preceded( + HEX_PREFIX, + cut_err(( + hexdig, repeat( 0.., alt(( - digit.value(()), + hexdig.value(()), ( one_of(b'_'), - cut_err(digit) - .context(Context::Expected(ParserValue::Description("digit"))), + cut_err(hexdig).context(StrContext::Expected( + StrContextValue::Description("digit"), + )), ) .value(()), )), ) .map(|()| ()), - ) - .value(()), - digit.value(()), - )), - ) - .recognize() - .map(|b: &[u8]| unsafe { from_utf8_unchecked(b, "`digit` and `_` filter out non-ASCII") }) - .context(Context::Expression("integer")) - .parse_next(input) -} -const DIGIT1_9: RangeInclusive<u8> = b'1'..=b'9'; - -// hex-prefix = %x30.78 ; 0x -// hex-int = hex-prefix HEXDIG *( HEXDIG / underscore HEXDIG ) -pub(crate) fn hex_int(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> { - preceded( - HEX_PREFIX, - cut_err(( - hexdig, - repeat( - 0.., - alt(( - hexdig.value(()), - ( - one_of(b'_'), - cut_err(hexdig) - .context(Context::Expected(ParserValue::Description("digit"))), - ) - .value(()), - )), - ) - .map(|()| ()), - )) - .recognize(), + )) + .recognize(), + ) + .map(|b| unsafe { from_utf8_unchecked(b, "`hexdig` and `_` filter out non-ASCII") }) + .context(StrContext::Label("hexadecimal integer")), ) - .map(|b| unsafe { from_utf8_unchecked(b, "`hexdig` and `_` filter out non-ASCII") }) - .context(Context::Expression("hexadecimal integer")) .parse_next(input) } const HEX_PREFIX: &[u8] = b"0x"; // oct-prefix = %x30.6F ; 0o // oct-int = oct-prefix digit0-7 *( digit0-7 / underscore digit0-7 ) -pub(crate) fn oct_int(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> { - preceded( - OCT_PREFIX, - cut_err(( - one_of(DIGIT0_7), - repeat( - 0.., - alt(( - one_of(DIGIT0_7).value(()), - ( - one_of(b'_'), - cut_err(one_of(DIGIT0_7)) - .context(Context::Expected(ParserValue::Description("digit"))), - ) - .value(()), - )), - ) - .map(|()| ()), - )) - .recognize(), +pub(crate) fn oct_int<'i>(input: &mut Input<'i>) -> PResult<&'i str> { + trace( + "oct-int", + preceded( + OCT_PREFIX, + cut_err(( + one_of(DIGIT0_7), + repeat( + 0.., + alt(( + one_of(DIGIT0_7).value(()), + ( + one_of(b'_'), + cut_err(one_of(DIGIT0_7)).context(StrContext::Expected( + StrContextValue::Description("digit"), + )), + ) + .value(()), + )), + ) + .map(|()| ()), + )) + .recognize(), + ) + .map(|b| unsafe { from_utf8_unchecked(b, "`DIGIT0_7` and `_` filter out non-ASCII") }) + .context(StrContext::Label("octal integer")), ) - .map(|b| unsafe { from_utf8_unchecked(b, "`DIGIT0_7` and `_` filter out non-ASCII") }) - .context(Context::Expression("octal integer")) .parse_next(input) } const OCT_PREFIX: &[u8] = b"0o"; @@ -142,29 +158,33 @@ const DIGIT0_7: RangeInclusive<u8> = b'0'..=b'7'; // bin-prefix = %x30.62 ; 0b // bin-int = bin-prefix digit0-1 *( digit0-1 / underscore digit0-1 ) -pub(crate) fn bin_int(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> { - preceded( - BIN_PREFIX, - cut_err(( - one_of(DIGIT0_1), - repeat( - 0.., - alt(( - one_of(DIGIT0_1).value(()), - ( - one_of(b'_'), - cut_err(one_of(DIGIT0_1)) - .context(Context::Expected(ParserValue::Description("digit"))), - ) - .value(()), - )), - ) - .map(|()| ()), - )) - .recognize(), +pub(crate) fn bin_int<'i>(input: &mut Input<'i>) -> PResult<&'i str> { + trace( + "bin-int", + preceded( + BIN_PREFIX, + cut_err(( + one_of(DIGIT0_1), + repeat( + 0.., + alt(( + one_of(DIGIT0_1).value(()), + ( + one_of(b'_'), + cut_err(one_of(DIGIT0_1)).context(StrContext::Expected( + StrContextValue::Description("digit"), + )), + ) + .value(()), + )), + ) + .map(|()| ()), + )) + .recognize(), + ) + .map(|b| unsafe { from_utf8_unchecked(b, "`DIGIT0_1` and `_` filter out non-ASCII") }) + .context(StrContext::Label("binary integer")), ) - .map(|b| unsafe { from_utf8_unchecked(b, "`DIGIT0_1` and `_` filter out non-ASCII") }) - .context(Context::Expression("binary integer")) .parse_next(input) } const BIN_PREFIX: &[u8] = b"0b"; @@ -175,20 +195,26 @@ const DIGIT0_1: RangeInclusive<u8> = b'0'..=b'1'; // float = float-int-part ( exp / frac [ exp ] ) // float =/ special-float // float-int-part = dec-int -pub(crate) fn float(input: Input<'_>) -> IResult<Input<'_>, f64, ParserError<'_>> { - alt(( - float_.and_then(cut_err( - rest.try_map(|s: &str| s.replace('_', "").parse()) - .verify(|f: &f64| *f != f64::INFINITY), - )), - special_float, - )) - .context(Context::Expression("floating-point number")) +pub(crate) fn float(input: &mut Input<'_>) -> PResult<f64> { + trace( + "float", + alt(( + float_.and_then(cut_err( + rest.try_map(|s: &str| s.replace('_', "").parse()) + .verify(|f: &f64| *f != f64::INFINITY), + )), + special_float, + )) + .context(StrContext::Label("floating-point number")), + ) .parse_next(input) } -pub(crate) fn float_(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> { - (dec_int, alt((exp, (frac, opt(exp)).map(|_| "")))) +pub(crate) fn float_<'i>(input: &mut Input<'i>) -> PResult<&'i str> { + ( + dec_int, + alt((exp.void(), (frac.void(), opt(exp.void())).void())), + ) .recognize() .map(|b: &[u8]| unsafe { from_utf8_unchecked( @@ -201,10 +227,11 @@ pub(crate) fn float_(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<' // frac = decimal-point zero-prefixable-int // decimal-point = %x2E ; . -pub(crate) fn frac(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> { +pub(crate) fn frac<'i>(input: &mut Input<'i>) -> PResult<&'i str> { ( b'.', - cut_err(zero_prefixable_int).context(Context::Expected(ParserValue::Description("digit"))), + cut_err(zero_prefixable_int) + .context(StrContext::Expected(StrContextValue::Description("digit"))), ) .recognize() .map(|b: &[u8]| unsafe { @@ -217,7 +244,7 @@ pub(crate) fn frac(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_> } // zero-prefixable-int = DIGIT *( DIGIT / underscore DIGIT ) -pub(crate) fn zero_prefixable_int(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> { +pub(crate) fn zero_prefixable_int<'i>(input: &mut Input<'i>) -> PResult<&'i str> { ( digit, repeat( @@ -226,7 +253,8 @@ pub(crate) fn zero_prefixable_int(input: Input<'_>) -> IResult<Input<'_>, &str, digit.value(()), ( one_of(b'_'), - cut_err(digit).context(Context::Expected(ParserValue::Description("digit"))), + cut_err(digit) + .context(StrContext::Expected(StrContextValue::Description("digit"))), ) .value(()), )), @@ -240,7 +268,7 @@ pub(crate) fn zero_prefixable_int(input: Input<'_>) -> IResult<Input<'_>, &str, // exp = "e" float-exp-part // float-exp-part = [ minus / plus ] zero-prefixable-int -pub(crate) fn exp(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> { +pub(crate) fn exp<'i>(input: &mut Input<'i>) -> PResult<&'i str> { ( one_of((b'e', b'E')), opt(one_of([b'+', b'-'])), @@ -257,7 +285,7 @@ pub(crate) fn exp(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> } // special-float = [ minus / plus ] ( inf / nan ) -pub(crate) fn special_float(input: Input<'_>) -> IResult<Input<'_>, f64, ParserError<'_>> { +pub(crate) fn special_float(input: &mut Input<'_>) -> PResult<f64> { (opt(one_of((b'+', b'-'))), alt((inf, nan))) .map(|(s, f)| match s { Some(b'+') | None => f, @@ -267,24 +295,24 @@ pub(crate) fn special_float(input: Input<'_>) -> IResult<Input<'_>, f64, ParserE .parse_next(input) } // inf = %x69.6e.66 ; inf -pub(crate) fn inf(input: Input<'_>) -> IResult<Input<'_>, f64, ParserError<'_>> { +pub(crate) fn inf(input: &mut Input<'_>) -> PResult<f64> { tag(INF).value(f64::INFINITY).parse_next(input) } const INF: &[u8] = b"inf"; // nan = %x6e.61.6e ; nan -pub(crate) fn nan(input: Input<'_>) -> IResult<Input<'_>, f64, ParserError<'_>> { +pub(crate) fn nan(input: &mut Input<'_>) -> PResult<f64> { tag(NAN).value(f64::NAN).parse_next(input) } const NAN: &[u8] = b"nan"; // DIGIT = %x30-39 ; 0-9 -pub(crate) fn digit(input: Input<'_>) -> IResult<Input<'_>, u8, ParserError<'_>> { +pub(crate) fn digit(input: &mut Input<'_>) -> PResult<u8> { one_of(DIGIT).parse_next(input) } const DIGIT: RangeInclusive<u8> = b'0'..=b'9'; // HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F" -pub(crate) fn hexdig(input: Input<'_>) -> IResult<Input<'_>, u8, ParserError<'_>> { +pub(crate) fn hexdig(input: &mut Input<'_>) -> PResult<u8> { one_of(HEXDIG).parse_next(input) } pub(crate) const HEXDIG: (RangeInclusive<u8>, RangeInclusive<u8>, RangeInclusive<u8>) = diff --git a/vendor/toml_edit/src/parser/strings.rs b/vendor/toml_edit/src/parser/strings.rs index 2ce160506..26f9cc248 100644 --- a/vendor/toml_edit/src/parser/strings.rs +++ b/vendor/toml_edit/src/parser/strings.rs @@ -13,11 +13,13 @@ use winnow::combinator::repeat; use winnow::combinator::success; use winnow::combinator::terminated; use winnow::prelude::*; +use winnow::stream::Stream; use winnow::token::any; use winnow::token::none_of; use winnow::token::one_of; use winnow::token::tag; use winnow::token::take_while; +use winnow::trace::trace; use crate::parser::errors::CustomError; use crate::parser::numbers::HEXDIG; @@ -27,44 +29,48 @@ use crate::parser::trivia::{from_utf8_unchecked, newline, ws, ws_newlines, NON_A // ;; String // string = ml-basic-string / basic-string / ml-literal-string / literal-string -pub(crate) fn string(input: Input<'_>) -> IResult<Input<'_>, Cow<'_, str>, ParserError<'_>> { - alt(( - ml_basic_string, - basic_string, - ml_literal_string, - literal_string.map(Cow::Borrowed), - )) +pub(crate) fn string<'i>(input: &mut Input<'i>) -> PResult<Cow<'i, str>> { + trace( + "string", + alt(( + ml_basic_string, + basic_string, + ml_literal_string, + literal_string.map(Cow::Borrowed), + )), + ) .parse_next(input) } // ;; Basic String // basic-string = quotation-mark *basic-char quotation-mark -pub(crate) fn basic_string(input: Input<'_>) -> IResult<Input<'_>, Cow<'_, str>, ParserError<'_>> { - let (mut input, _) = one_of(QUOTATION_MARK).parse_next(input)?; +pub(crate) fn basic_string<'i>(input: &mut Input<'i>) -> PResult<Cow<'i, str>> { + trace("basic-string", |input: &mut Input<'i>| { + let _ = one_of(QUOTATION_MARK).parse_next(input)?; - let mut c = Cow::Borrowed(""); - if let Some((i, ci)) = ok_error(basic_chars.parse_next(input))? { - input = i; - c = ci; - } - while let Some((i, ci)) = ok_error(basic_chars.parse_next(input))? { - input = i; - c.to_mut().push_str(&ci); - } + let mut c = Cow::Borrowed(""); + if let Some(ci) = opt(basic_chars).parse_next(input)? { + c = ci; + } + while let Some(ci) = opt(basic_chars).parse_next(input)? { + c.to_mut().push_str(&ci); + } - let (input, _) = cut_err(one_of(QUOTATION_MARK)) - .context(Context::Expression("basic string")) - .parse_next(input)?; + let _ = cut_err(one_of(QUOTATION_MARK)) + .context(StrContext::Label("basic string")) + .parse_next(input)?; - Ok((input, c)) + Ok(c) + }) + .parse_next(input) } // quotation-mark = %x22 ; " pub(crate) const QUOTATION_MARK: u8 = b'"'; // basic-char = basic-unescaped / escaped -fn basic_chars(input: Input<'_>) -> IResult<Input<'_>, Cow<'_, str>, ParserError<'_>> { +fn basic_chars<'i>(input: &mut Input<'i>) -> PResult<Cow<'i, str>> { alt(( // Deviate from the official grammar by batching the unescaped chars so we build a string a // chunk at a time, rather than a `char` at a time. @@ -86,7 +92,7 @@ pub(crate) const BASIC_UNESCAPED: ( ) = (WSCHAR, 0x21, 0x23..=0x5B, 0x5D..=0x7E, NON_ASCII); // escaped = escape escape-seq-char -fn escaped(input: Input<'_>) -> IResult<Input<'_>, char, ParserError<'_>> { +fn escaped(input: &mut Input<'_>) -> PResult<char> { preceded(ESCAPE, escape_seq_char).parse_next(input) } @@ -102,37 +108,35 @@ pub(crate) const ESCAPE: u8 = b'\\'; // escape-seq-char =/ %x74 ; t tab U+0009 // escape-seq-char =/ %x75 4HEXDIG ; uXXXX U+XXXX // escape-seq-char =/ %x55 8HEXDIG ; UXXXXXXXX U+XXXXXXXX -fn escape_seq_char(input: Input<'_>) -> IResult<Input<'_>, char, ParserError<'_>> { +fn escape_seq_char(input: &mut Input<'_>) -> PResult<char> { dispatch! {any; b'b' => success('\u{8}'), b'f' => success('\u{c}'), b'n' => success('\n'), b'r' => success('\r'), b't' => success('\t'), - b'u' => cut_err(hexescape::<4>).context(Context::Expression("unicode 4-digit hex code")), - b'U' => cut_err(hexescape::<8>).context(Context::Expression("unicode 8-digit hex code")), + b'u' => cut_err(hexescape::<4>).context(StrContext::Label("unicode 4-digit hex code")), + b'U' => cut_err(hexescape::<8>).context(StrContext::Label("unicode 8-digit hex code")), b'\\' => success('\\'), b'"' => success('"'), _ => { cut_err(fail::<_, char, _>) - .context(Context::Expression("escape sequence")) - .context(Context::Expected(ParserValue::CharLiteral('b'))) - .context(Context::Expected(ParserValue::CharLiteral('f'))) - .context(Context::Expected(ParserValue::CharLiteral('n'))) - .context(Context::Expected(ParserValue::CharLiteral('r'))) - .context(Context::Expected(ParserValue::CharLiteral('t'))) - .context(Context::Expected(ParserValue::CharLiteral('u'))) - .context(Context::Expected(ParserValue::CharLiteral('U'))) - .context(Context::Expected(ParserValue::CharLiteral('\\'))) - .context(Context::Expected(ParserValue::CharLiteral('"'))) + .context(StrContext::Label("escape sequence")) + .context(StrContext::Expected(StrContextValue::CharLiteral('b'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('f'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('n'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('r'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('t'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('u'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('U'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('\\'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('"'))) } } .parse_next(input) } -pub(crate) fn hexescape<const N: usize>( - input: Input<'_>, -) -> IResult<Input<'_>, char, ParserError<'_>> { +pub(crate) fn hexescape<const N: usize>(input: &mut Input<'_>) -> PResult<char> { take_while(0..=N, HEXDIG) .verify(|b: &[u8]| b.len() == N) .map(|b: &[u8]| unsafe { from_utf8_unchecked(b, "`is_ascii_digit` filters out on-ASCII") }) @@ -145,13 +149,16 @@ pub(crate) fn hexescape<const N: usize>( // ml-basic-string = ml-basic-string-delim [ newline ] ml-basic-body // ml-basic-string-delim -fn ml_basic_string(input: Input<'_>) -> IResult<Input<'_>, Cow<'_, str>, ParserError<'_>> { - delimited( - ML_BASIC_STRING_DELIM, - preceded(opt(newline), cut_err(ml_basic_body)), - cut_err(ML_BASIC_STRING_DELIM), +fn ml_basic_string<'i>(input: &mut Input<'i>) -> PResult<Cow<'i, str>> { + trace( + "ml-basic-string", + delimited( + ML_BASIC_STRING_DELIM, + preceded(opt(newline), cut_err(ml_basic_body)), + cut_err(ML_BASIC_STRING_DELIM), + ) + .context(StrContext::Label("multiline basic string")), ) - .context(Context::Expression("multiline basic string")) .parse_next(input) } @@ -159,24 +166,20 @@ fn ml_basic_string(input: Input<'_>) -> IResult<Input<'_>, Cow<'_, str>, ParserE pub(crate) const ML_BASIC_STRING_DELIM: &[u8] = b"\"\"\""; // ml-basic-body = *mlb-content *( mlb-quotes 1*mlb-content ) [ mlb-quotes ] -fn ml_basic_body(mut input: Input<'_>) -> IResult<Input<'_>, Cow<'_, str>, ParserError<'_>> { +fn ml_basic_body<'i>(input: &mut Input<'i>) -> PResult<Cow<'i, str>> { let mut c = Cow::Borrowed(""); - if let Some((i, ci)) = ok_error(mlb_content.parse_next(input))? { - input = i; + if let Some(ci) = opt(mlb_content).parse_next(input)? { c = ci; } - while let Some((i, ci)) = ok_error(mlb_content.parse_next(input))? { - input = i; + while let Some(ci) = opt(mlb_content).parse_next(input)? { c.to_mut().push_str(&ci); } - while let Some((i, qi)) = ok_error(mlb_quotes(none_of(b'\"').value(())).parse_next(input))? { - if let Some((i, ci)) = ok_error(mlb_content.parse_next(i))? { - input = i; + while let Some(qi) = opt(mlb_quotes(none_of(b'\"').value(()))).parse_next(input)? { + if let Some(ci) = opt(mlb_content).parse_next(input)? { c.to_mut().push_str(qi); c.to_mut().push_str(&ci); - while let Some((i, ci)) = ok_error(mlb_content.parse_next(input))? { - input = i; + while let Some(ci) = opt(mlb_content).parse_next(input)? { c.to_mut().push_str(&ci); } } else { @@ -184,19 +187,16 @@ fn ml_basic_body(mut input: Input<'_>) -> IResult<Input<'_>, Cow<'_, str>, Parse } } - if let Some((i, qi)) = - ok_error(mlb_quotes(tag(ML_BASIC_STRING_DELIM).value(())).parse_next(input))? - { - input = i; + if let Some(qi) = opt(mlb_quotes(tag(ML_BASIC_STRING_DELIM).value(()))).parse_next(input)? { c.to_mut().push_str(qi); } - Ok((input, c)) + Ok(c) } // mlb-content = mlb-char / newline / mlb-escaped-nl // mlb-char = mlb-unescaped / escaped -fn mlb_content(input: Input<'_>) -> IResult<Input<'_>, Cow<'_, str>, ParserError<'_>> { +fn mlb_content<'i>(input: &mut Input<'i>) -> PResult<Cow<'i, str>> { alt(( // Deviate from the official grammar by batching the unescaped chars so we build a string a // chunk at a time, rather than a `char` at a time. @@ -213,17 +213,21 @@ fn mlb_content(input: Input<'_>) -> IResult<Input<'_>, Cow<'_, str>, ParserError // mlb-quotes = 1*2quotation-mark fn mlb_quotes<'i>( - mut term: impl winnow::Parser<Input<'i>, (), ParserError<'i>>, -) -> impl FnMut(Input<'i>) -> IResult<Input<'i>, &str, ParserError<'i>> { - move |input| { + mut term: impl winnow::Parser<Input<'i>, (), ContextError>, +) -> impl Parser<Input<'i>, &'i str, ContextError> { + move |input: &mut Input<'i>| { + let start = input.checkpoint(); let res = terminated(b"\"\"", peek(term.by_ref())) .map(|b| unsafe { from_utf8_unchecked(b, "`bytes` out non-ASCII") }) .parse_next(input); match res { - Err(winnow::error::ErrMode::Backtrack(_)) => terminated(b"\"", peek(term.by_ref())) - .map(|b| unsafe { from_utf8_unchecked(b, "`bytes` out non-ASCII") }) - .parse_next(input), + Err(winnow::error::ErrMode::Backtrack(_)) => { + input.reset(start); + terminated(b"\"", peek(term.by_ref())) + .map(|b| unsafe { from_utf8_unchecked(b, "`bytes` out non-ASCII") }) + .parse_next(input) + } res => res, } } @@ -243,7 +247,7 @@ pub(crate) const MLB_UNESCAPED: ( // it will be trimmed along with all whitespace // (including newlines) up to the next non-whitespace // character or closing delimiter. -fn mlb_escaped_nl(input: Input<'_>) -> IResult<Input<'_>, (), ParserError<'_>> { +fn mlb_escaped_nl(input: &mut Input<'_>) -> PResult<()> { repeat(1.., (ESCAPE, ws, ws_newlines)) .map(|()| ()) .value(()) @@ -253,14 +257,17 @@ fn mlb_escaped_nl(input: Input<'_>) -> IResult<Input<'_>, (), ParserError<'_>> { // ;; Literal String // literal-string = apostrophe *literal-char apostrophe -pub(crate) fn literal_string(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> { - delimited( - APOSTROPHE, - cut_err(take_while(0.., LITERAL_CHAR)), - cut_err(APOSTROPHE), +pub(crate) fn literal_string<'i>(input: &mut Input<'i>) -> PResult<&'i str> { + trace( + "literal-string", + delimited( + APOSTROPHE, + cut_err(take_while(0.., LITERAL_CHAR)), + cut_err(APOSTROPHE), + ) + .try_map(std::str::from_utf8) + .context(StrContext::Label("literal string")), ) - .try_map(std::str::from_utf8) - .context(Context::Expression("literal string")) .parse_next(input) } @@ -279,19 +286,22 @@ pub(crate) const LITERAL_CHAR: ( // ml-literal-string = ml-literal-string-delim [ newline ] ml-literal-body // ml-literal-string-delim -fn ml_literal_string(input: Input<'_>) -> IResult<Input<'_>, Cow<'_, str>, ParserError<'_>> { - delimited( - (ML_LITERAL_STRING_DELIM, opt(newline)), - cut_err(ml_literal_body.map(|t| { - if t.contains("\r\n") { - Cow::Owned(t.replace("\r\n", "\n")) - } else { - Cow::Borrowed(t) - } - })), - cut_err(ML_LITERAL_STRING_DELIM), +fn ml_literal_string<'i>(input: &mut Input<'i>) -> PResult<Cow<'i, str>> { + trace( + "ml-literal-string", + delimited( + (ML_LITERAL_STRING_DELIM, opt(newline)), + cut_err(ml_literal_body.map(|t| { + if t.contains("\r\n") { + Cow::Owned(t.replace("\r\n", "\n")) + } else { + Cow::Borrowed(t) + } + })), + cut_err(ML_LITERAL_STRING_DELIM), + ) + .context(StrContext::Label("multiline literal string")), ) - .context(Context::Expression("multiline literal string")) .parse_next(input) } @@ -299,7 +309,7 @@ fn ml_literal_string(input: Input<'_>) -> IResult<Input<'_>, Cow<'_, str>, Parse pub(crate) const ML_LITERAL_STRING_DELIM: &[u8] = b"'''"; // ml-literal-body = *mll-content *( mll-quotes 1*mll-content ) [ mll-quotes ] -fn ml_literal_body(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> { +fn ml_literal_body<'i>(input: &mut Input<'i>) -> PResult<&'i str> { ( repeat(0.., mll_content).map(|()| ()), repeat( @@ -318,7 +328,7 @@ fn ml_literal_body(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_> } // mll-content = mll-char / newline -fn mll_content(input: Input<'_>) -> IResult<Input<'_>, u8, ParserError<'_>> { +fn mll_content(input: &mut Input<'_>) -> PResult<u8> { alt((one_of(MLL_CHAR), newline)).parse_next(input) } @@ -332,17 +342,21 @@ const MLL_CHAR: ( // mll-quotes = 1*2apostrophe fn mll_quotes<'i>( - mut term: impl winnow::Parser<Input<'i>, (), ParserError<'i>>, -) -> impl FnMut(Input<'i>) -> IResult<Input<'i>, &str, ParserError<'i>> { - move |input| { + mut term: impl winnow::Parser<Input<'i>, (), ContextError>, +) -> impl Parser<Input<'i>, &'i str, ContextError> { + move |input: &mut Input<'i>| { + let start = input.checkpoint(); let res = terminated(b"''", peek(term.by_ref())) .map(|b| unsafe { from_utf8_unchecked(b, "`bytes` out non-ASCII") }) .parse_next(input); match res { - Err(winnow::error::ErrMode::Backtrack(_)) => terminated(b"'", peek(term.by_ref())) - .map(|b| unsafe { from_utf8_unchecked(b, "`bytes` out non-ASCII") }) - .parse_next(input), + Err(winnow::error::ErrMode::Backtrack(_)) => { + input.reset(start); + terminated(b"'", peek(term.by_ref())) + .map(|b| unsafe { from_utf8_unchecked(b, "`bytes` out non-ASCII") }) + .parse_next(input) + } res => res, } } diff --git a/vendor/toml_edit/src/parser/table.rs b/vendor/toml_edit/src/parser/table.rs index 9d2675868..0ace0c7d1 100644 --- a/vendor/toml_edit/src/parser/table.rs +++ b/vendor/toml_edit/src/parser/table.rs @@ -27,20 +27,20 @@ const ARRAY_TABLE_CLOSE: &[u8] = b"]]"; // std-table = std-table-open key *( table-key-sep key) std-table-close pub(crate) fn std_table<'s, 'i>( state: &'s RefCell<ParseState>, -) -> impl FnMut(Input<'i>) -> IResult<Input<'i>, (), ParserError<'i>> + 's { - move |i| { +) -> impl Parser<Input<'i>, (), ContextError> + 's { + move |i: &mut Input<'i>| { ( delimited( STD_TABLE_OPEN, cut_err(key), cut_err(STD_TABLE_CLOSE) - .context(Context::Expected(ParserValue::CharLiteral('.'))) - .context(Context::Expected(ParserValue::StringLiteral("]"))), + .context(StrContext::Expected(StrContextValue::CharLiteral('.'))) + .context(StrContext::Expected(StrContextValue::StringLiteral("]"))), ) .with_span(), cut_err(line_trailing) - .context(Context::Expected(ParserValue::CharLiteral('\n'))) - .context(Context::Expected(ParserValue::CharLiteral('#'))), + .context(StrContext::Expected(StrContextValue::CharLiteral('\n'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('#'))), ) .try_map(|((h, span), t)| state.borrow_mut().deref_mut().on_std_header(h, t, span)) .parse_next(i) @@ -52,20 +52,20 @@ pub(crate) fn std_table<'s, 'i>( // array-table = array-table-open key *( table-key-sep key) array-table-close pub(crate) fn array_table<'s, 'i>( state: &'s RefCell<ParseState>, -) -> impl FnMut(Input<'i>) -> IResult<Input<'i>, (), ParserError<'i>> + 's { - move |i| { +) -> impl Parser<Input<'i>, (), ContextError> + 's { + move |i: &mut Input<'i>| { ( delimited( ARRAY_TABLE_OPEN, cut_err(key), cut_err(ARRAY_TABLE_CLOSE) - .context(Context::Expected(ParserValue::CharLiteral('.'))) - .context(Context::Expected(ParserValue::StringLiteral("]]"))), + .context(StrContext::Expected(StrContextValue::CharLiteral('.'))) + .context(StrContext::Expected(StrContextValue::StringLiteral("]]"))), ) .with_span(), cut_err(line_trailing) - .context(Context::Expected(ParserValue::CharLiteral('\n'))) - .context(Context::Expected(ParserValue::CharLiteral('#'))), + .context(StrContext::Expected(StrContextValue::CharLiteral('\n'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('#'))), ) .try_map(|((h, span), t)| state.borrow_mut().deref_mut().on_array_header(h, t, span)) .parse_next(i) @@ -77,13 +77,13 @@ pub(crate) fn array_table<'s, 'i>( // table = std-table / array-table pub(crate) fn table<'s, 'i>( state: &'s RefCell<ParseState>, -) -> impl FnMut(Input<'i>) -> IResult<Input<'i>, (), ParserError<'i>> + 's { - move |i| { +) -> impl Parser<Input<'i>, (), ContextError> + 's { + move |i: &mut Input<'i>| { dispatch!(peek::<_, &[u8],_,_>(take(2usize)); b"[[" => array_table(state), _ => std_table(state), ) - .context(Context::Expression("table header")) + .context(StrContext::Label("table header")) .parse_next(i) } } diff --git a/vendor/toml_edit/src/parser/trivia.rs b/vendor/toml_edit/src/parser/trivia.rs index ba47dcde6..a359805b2 100644 --- a/vendor/toml_edit/src/parser/trivia.rs +++ b/vendor/toml_edit/src/parser/trivia.rs @@ -28,7 +28,7 @@ pub(crate) unsafe fn from_utf8_unchecked<'b>( pub(crate) const WSCHAR: (u8, u8) = (b' ', b'\t'); // ws = *wschar -pub(crate) fn ws(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> { +pub(crate) fn ws<'i>(input: &mut Input<'i>) -> PResult<&'i str> { take_while(0.., WSCHAR) .map(|b| unsafe { from_utf8_unchecked(b, "`is_wschar` filters out on-ASCII") }) .parse_next(input) @@ -48,7 +48,7 @@ pub(crate) const NON_EOL: (u8, RangeInclusive<u8>, RangeInclusive<u8>) = pub(crate) const COMMENT_START_SYMBOL: u8 = b'#'; // comment = comment-start-symbol *non-eol -pub(crate) fn comment(input: Input<'_>) -> IResult<Input<'_>, &[u8], ParserError<'_>> { +pub(crate) fn comment<'i>(input: &mut Input<'i>) -> PResult<&'i [u8]> { (COMMENT_START_SYMBOL, take_while(0.., NON_EOL)) .recognize() .parse_next(input) @@ -56,7 +56,7 @@ pub(crate) fn comment(input: Input<'_>) -> IResult<Input<'_>, &[u8], ParserError // newline = ( %x0A / ; LF // %x0D.0A ) ; CRLF -pub(crate) fn newline(input: Input<'_>) -> IResult<Input<'_>, u8, ParserError<'_>> { +pub(crate) fn newline(input: &mut Input<'_>) -> PResult<u8> { alt(( one_of(LF).value(b'\n'), (one_of(CR), one_of(LF)).value(b'\n'), @@ -67,7 +67,7 @@ pub(crate) const LF: u8 = b'\n'; pub(crate) const CR: u8 = b'\r'; // ws-newline = *( wschar / newline ) -pub(crate) fn ws_newline(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> { +pub(crate) fn ws_newline<'i>(input: &mut Input<'i>) -> PResult<&'i str> { repeat( 0.., alt((newline.value(&b"\n"[..]), take_while(1.., WSCHAR))), @@ -79,7 +79,7 @@ pub(crate) fn ws_newline(input: Input<'_>) -> IResult<Input<'_>, &str, ParserErr } // ws-newlines = newline *( wschar / newline ) -pub(crate) fn ws_newlines(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> { +pub(crate) fn ws_newlines<'i>(input: &mut Input<'i>) -> PResult<&'i str> { (newline, ws_newline) .recognize() .map(|b| unsafe { @@ -90,7 +90,7 @@ pub(crate) fn ws_newlines(input: Input<'_>) -> IResult<Input<'_>, &str, ParserEr // note: this rule is not present in the original grammar // ws-comment-newline = *( ws-newline-nonempty / comment ) -pub(crate) fn ws_comment_newline(input: Input<'_>) -> IResult<Input<'_>, &[u8], ParserError<'_>> { +pub(crate) fn ws_comment_newline<'i>(input: &mut Input<'i>) -> PResult<&'i [u8]> { repeat( 0.., alt(( @@ -109,15 +109,13 @@ pub(crate) fn ws_comment_newline(input: Input<'_>) -> IResult<Input<'_>, &[u8], // note: this rule is not present in the original grammar // line-ending = newline / eof -pub(crate) fn line_ending(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> { +pub(crate) fn line_ending<'i>(input: &mut Input<'i>) -> PResult<&'i str> { alt((newline.value("\n"), eof.value(""))).parse_next(input) } // note: this rule is not present in the original grammar // line-trailing = ws [comment] skip-line-ending -pub(crate) fn line_trailing( - input: Input<'_>, -) -> IResult<Input<'_>, std::ops::Range<usize>, ParserError<'_>> { +pub(crate) fn line_trailing(input: &mut Input<'_>) -> PResult<std::ops::Range<usize>> { terminated((ws, opt(comment)).span(), line_ending).parse_next(input) } diff --git a/vendor/toml_edit/src/parser/value.rs b/vendor/toml_edit/src/parser/value.rs index 19950585b..14cd951c4 100644 --- a/vendor/toml_edit/src/parser/value.rs +++ b/vendor/toml_edit/src/parser/value.rs @@ -1,7 +1,7 @@ -use winnow::branch::alt; -use winnow::bytes::any; +use winnow::combinator::alt; use winnow::combinator::fail; use winnow::combinator::peek; +use winnow::token::any; use crate::parser::array::array; use crate::parser::datetime::date_time; @@ -15,10 +15,8 @@ use crate::RawString; use crate::Value; // val = string / boolean / array / inline-table / date-time / float / integer -pub(crate) fn value( - check: RecursionCheck, -) -> impl FnMut(Input<'_>) -> IResult<Input<'_>, v::Value, ParserError<'_>> { - move |input| { +pub(crate) fn value<'i>(check: RecursionCheck) -> impl Parser<Input<'i>, v::Value, ContextError> { + move |input: &mut Input<'i>| { dispatch!{peek(any); crate::parser::strings::QUOTATION_MARK | crate::parser::strings::APOSTROPHE => string.map(|s| { @@ -44,43 +42,43 @@ pub(crate) fn value( b'_' => { integer .map(v::Value::from) - .context(Context::Expected(ParserValue::Description("leading digit"))) + .context(StrContext::Expected(StrContextValue::Description("leading digit"))) }, // Report as if they were numbers because its most likely a typo b'.' => { float .map(v::Value::from) - .context(Context::Expected(ParserValue::Description("leading digit"))) + .context(StrContext::Expected(StrContextValue::Description("leading digit"))) }, b't' => { crate::parser::numbers::true_.map(v::Value::from) - .context(Context::Expression("string")) - .context(Context::Expected(ParserValue::CharLiteral('"'))) - .context(Context::Expected(ParserValue::CharLiteral('\''))) + .context(StrContext::Label("string")) + .context(StrContext::Expected(StrContextValue::CharLiteral('"'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('\''))) }, b'f' => { crate::parser::numbers::false_.map(v::Value::from) - .context(Context::Expression("string")) - .context(Context::Expected(ParserValue::CharLiteral('"'))) - .context(Context::Expected(ParserValue::CharLiteral('\''))) + .context(StrContext::Label("string")) + .context(StrContext::Expected(StrContextValue::CharLiteral('"'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('\''))) }, b'i' => { crate::parser::numbers::inf.map(v::Value::from) - .context(Context::Expression("string")) - .context(Context::Expected(ParserValue::CharLiteral('"'))) - .context(Context::Expected(ParserValue::CharLiteral('\''))) + .context(StrContext::Label("string")) + .context(StrContext::Expected(StrContextValue::CharLiteral('"'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('\''))) }, b'n' => { crate::parser::numbers::nan.map(v::Value::from) - .context(Context::Expression("string")) - .context(Context::Expected(ParserValue::CharLiteral('"'))) - .context(Context::Expected(ParserValue::CharLiteral('\''))) + .context(StrContext::Label("string")) + .context(StrContext::Expected(StrContextValue::CharLiteral('"'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('\''))) }, _ => { fail - .context(Context::Expression("string")) - .context(Context::Expected(ParserValue::CharLiteral('"'))) - .context(Context::Expected(ParserValue::CharLiteral('\''))) + .context(StrContext::Label("string")) + .context(StrContext::Expected(StrContextValue::CharLiteral('"'))) + .context(StrContext::Expected(StrContextValue::CharLiteral('\''))) }, } .with_span() |