Unified · Split
| @@ -17,7 +17,7 @@ use winnow::{ · 16 unmodified lines | |||
| 17 | use crate::parse::{error::ParseNode, section, Comment, Error, Event}; | 17 | use crate::parse::{error::ParseNode, section, Comment, Error, Event}; |
| 18 | 18 | ||
| 19 | /// Attempt to zero-copy parse the provided bytes, passing results to `dispatch`. | 19 | /// Attempt to zero-copy parse the provided bytes, passing results to `dispatch`. |
| 20 | pub fn from_bytes<'a>(input: &'a [u8], mut dispatch: impl FnMut(Event<'a>)) -> Result<(), Error> { | 20 | pub fn from_bytes<'i>(input: &'i [u8], mut dispatch: impl FnMut(Event<'i>)) -> Result<(), Error> { |
| 21 | let bom = unicode_bom::Bom::from(input); | 21 | let bom = unicode_bom::Bom::from(input); |
| 22 | let mut newlines = 0; | 22 | let mut newlines = 0; |
| 23 | let (i, _) = fold_repeat( | 23 | let (i, _) = fold_repeat( |
| @@ -89,7 +89,7 @@ fn comment(i: &[u8]) -> IResult<&[u8], Comment<'_>> { · 65 unmodified lines | |||
| 89 | #[cfg(test)] | 89 | #[cfg(test)] |
| 90 | mod tests; | 90 | mod tests; |
| 91 | 91 | ||
| 92 | fn section<'a>(i: &'a [u8], node: &mut ParseNode, dispatch: &mut impl FnMut(Event<'a>)) -> IResult<&'a [u8], usize> { | 92 | fn section<'i>(i: &'i [u8], node: &mut ParseNode, dispatch: &mut impl FnMut(Event<'i>)) -> IResult<&'i [u8], usize> { |
| 93 | let (mut i, header) = section_header(i)?; | 93 | let (mut i, header) = section_header(i)?; |
| 94 | dispatch(Event::SectionHeader(header)); | 94 | dispatch(Event::SectionHeader(header)); |
| 95 | 95 | ||
| @@ -203,11 +203,11 @@ fn is_subsection_unescaped_char(c: u8) -> bool { · 107 unmodified lines | |||
| 203 | c != b'"' && c != b'\\' && c != b'\n' && c != 0 | 203 | c != b'"' && c != b'\\' && c != b'\n' && c != 0 |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | fn key_value_pair<'a>( | 206 | fn key_value_pair<'i>( |
| 207 | i: &'a [u8], | 207 | i: &'i [u8], |
| 208 | node: &mut ParseNode, | 208 | node: &mut ParseNode, |
| 209 | dispatch: &mut impl FnMut(Event<'a>), | 209 | dispatch: &mut impl FnMut(Event<'i>), |
| 210 | ) -> IResult<&'a [u8], usize> { | 210 | ) -> IResult<&'i [u8], usize> { |
| 211 | *node = ParseNode::Name; | 211 | *node = ParseNode::Name; |
| 212 | let (i, name) = config_name(i)?; | 212 | let (i, name) = config_name(i)?; |
| 213 | 213 | ||
| @@ -235,7 +235,7 @@ fn config_name(i: &[u8]) -> IResult<&[u8], &BStr> { · 21 unmodified lines | |||
| 235 | .parse_next(i) | 235 | .parse_next(i) |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | fn config_value<'a>(i: &'a [u8], dispatch: &mut impl FnMut(Event<'a>)) -> IResult<&'a [u8], usize> { | 238 | fn config_value<'i>(i: &'i [u8], dispatch: &mut impl FnMut(Event<'i>)) -> IResult<&'i [u8], usize> { |
| 239 | if let (i, Some(_)) = opt('=').parse_next(i)? { | 239 | if let (i, Some(_)) = opt('=').parse_next(i)? { |
| 240 | dispatch(Event::KeyValueSeparator); | 240 | dispatch(Event::KeyValueSeparator); |
| 241 | let (i, whitespace) = opt(take_spaces1).parse_next(i)?; | 241 | let (i, whitespace) = opt(take_spaces1).parse_next(i)?; |
| @@ -255,7 +255,7 @@ fn config_value<'a>(i: &'a [u8], dispatch: &mut impl FnMut(Event<'a>)) -> IResul · 13 unmodified lines | |||
| 255 | 255 | ||
| 256 | /// Handles parsing of known-to-be values. This function handles both single | 256 | /// Handles parsing of known-to-be values. This function handles both single |
| 257 | /// line values as well as values that are continuations. | 257 | /// line values as well as values that are continuations. |
| 258 | fn value_impl<'a>(i: &'a [u8], dispatch: &mut impl FnMut(Event<'a>)) -> IResult<&'a [u8], usize> { | 258 | fn value_impl<'i>(i: &'i [u8], dispatch: &mut impl FnMut(Event<'i>)) -> IResult<&'i [u8], usize> { |
| 259 | let (i, value_end, newlines, mut dispatch) = { | 259 | let (i, value_end, newlines, mut dispatch) = { |
| 260 | let new_err = |kind| winnow::error::ErrMode::from_error_kind(i, kind); | 260 | let new_err = |kind| winnow::error::ErrMode::from_error_kind(i, kind); |
| 261 | let mut value_end = None::<usize>; | 261 | let mut value_end = None::<usize>; |
| @@ -342,7 +342,7 @@ fn value_impl<'a>(i: &'a [u8], dispatch: &mut impl FnMut(Event<'a>)) -> IResult< · 80 unmodified lines | |||
| 342 | Some(idx) => idx, | 342 | Some(idx) => idx, |
| 343 | }; | 343 | }; |
| 344 | 344 | ||
| 345 | let dispatch = move |value: &'a [u8]| { | 345 | let dispatch = move |value: &'i [u8]| { |
| 346 | if partial_value_found { | 346 | if partial_value_found { |
| 347 | dispatch(Event::ValueDone(Cow::Borrowed(value.as_bstr()))); | 347 | dispatch(Event::ValueDone(Cow::Borrowed(value.as_bstr()))); |
| 348 | } else { | 348 | } else { |