Unified · Split
| @@ -6,7 +6,7 @@ use winnow::{ · 5 unmodified lines | ||
| 6 | 6 | combinator::delimited, |
| 7 | 7 | combinator::fold_repeat, |
| 8 | 8 | combinator::opt, |
| 9 | − error::{ErrorKind, InputError as NomError}, | |
| 9 | + error::{ErrorKind, InputError as NomError, ParserError as _}, | |
| 10 | 10 | prelude::*, |
| 11 | 11 | stream::AsChar, |
| 12 | 12 | token::{one_of, take_till0, take_while}, |
| @@ -161,10 +161,7 @@ fn section_header(i: &[u8]) -> IResult<&[u8], section::Header<'_>> { · 148 unmodified lines | ||
| 161 | 161 | }; |
| 162 | 162 | |
| 163 | 163 | if header.name.is_empty() { |
| 164 | − return Err(winnow::error::ErrMode::Backtrack(NomError { | |
| 165 | − input: i, | |
| 166 | − kind: ErrorKind::Fail, | |
| 167 | − })); | |
| 164 | + return Err(winnow::error::ErrMode::from_error_kind(i, ErrorKind::Fail)); | |
| 168 | 165 | } |
| 169 | 166 | return Ok((i, header)); |
| 170 | 167 | } |
| @@ -202,39 +199,27 @@ fn sub_section_delegate<'a>(i: &'a [u8], push_byte: &mut dyn FnMut(u8)) -> IResu · 31 unmodified lines | ||
| 202 | 199 | while let Some(mut b) = bytes.next() { |
| 203 | 200 | cursor += 1; |
| 204 | 201 | if b == b'\n' || b == 0 { |
| 205 | − return Err(winnow::error::ErrMode::Backtrack(NomError { | |
| 206 | − input: &i[cursor..], | |
| 207 | − kind: ErrorKind::Fail, | |
| 208 | − })); | |
| 202 | + return Err(winnow::error::ErrMode::from_error_kind(&i[cursor..], ErrorKind::Fail)); | |
| 209 | 203 | } |
| 210 | 204 | if b == b'"' { |
| 211 | 205 | found_terminator = true; |
| 212 | 206 | break; |
| 213 | 207 | } |
| 214 | 208 | if b == b'\\' { |
| 215 | − b = bytes.next().ok_or_else(|| { | |
| 216 | − winnow::error::ErrMode::Backtrack(NomError { | |
| 217 | − input: &i[cursor..], | |
| 218 | − kind: ErrorKind::Fail, | |
| 219 | − }) | |
| 220 | − })?; | |
| 209 | + b = bytes | |
| 210 | + .next() | |
| 211 | + .ok_or_else(|| winnow::error::ErrMode::from_error_kind(&i[cursor..], ErrorKind::Fail))?; | |
| 221 | 212 | found_escape = true; |
| 222 | 213 | cursor += 1; |
| 223 | 214 | if b == b'\n' { |
| 224 | − return Err(winnow::error::ErrMode::Backtrack(NomError { | |
| 225 | − input: &i[cursor..], | |
| 226 | − kind: ErrorKind::Fail, | |
| 227 | − })); | |
| 215 | + return Err(winnow::error::ErrMode::from_error_kind(&i[cursor..], ErrorKind::Fail)); | |
| 228 | 216 | } |
| 229 | 217 | } |
| 230 | 218 | push_byte(b); |
| 231 | 219 | } |
| 232 | 220 | |
| 233 | 221 | if !found_terminator { |
| 234 | − return Err(winnow::error::ErrMode::Backtrack(NomError { | |
| 235 | − input: &i[cursor..], | |
| 236 | − kind: ErrorKind::Fail, | |
| 237 | − })); | |
| 222 | + return Err(winnow::error::ErrMode::from_error_kind(&i[cursor..], ErrorKind::Fail)); | |
| 238 | 223 | } |
| 239 | 224 | |
| 240 | 225 | Ok((&i[cursor - 1..], (found_escape, cursor - 1))) |
| @@ -264,17 +249,11 @@ fn key_value_pair<'a>( · 23 unmodified lines | ||
| 264 | 249 | /// trimmed of any leading whitespace. |
| 265 | 250 | fn config_name(i: &[u8]) -> IResult<&[u8], &BStr> { |
| 266 | 251 | if i.is_empty() { |
| 267 | − return Err(winnow::error::ErrMode::Backtrack(NomError { | |
| 268 | − input: i, | |
| 269 | − kind: ErrorKind::Fail, | |
| 270 | − })); | |
| 252 | + return Err(winnow::error::ErrMode::from_error_kind(i, ErrorKind::Fail)); | |
| 271 | 253 | } |
| 272 | 254 | |
| 273 | 255 | if !i[0].is_ascii_alphabetic() { |
| 274 | − return Err(winnow::error::ErrMode::Backtrack(NomError { | |
| 275 | − input: i, | |
| 276 | − kind: ErrorKind::Token, | |
| 277 | − })); | |
| 256 | + return Err(winnow::error::ErrMode::from_error_kind(i, ErrorKind::Token)); | |
| 278 | 257 | } |
| 279 | 258 | |
| 280 | 259 | let (i, name) = take_while(0.., |c: u8| c.is_ascii_alphanumeric() || c == b'-').parse_next(i)?; |
| @@ -303,7 +282,7 @@ fn config_value<'a>(i: &'a [u8], dispatch: &mut impl FnMut(Event<'a>)) -> IResul · 22 unmodified lines | ||
| 303 | 282 | /// line values as well as values that are continuations. |
| 304 | 283 | fn value_impl<'a>(i: &'a [u8], dispatch: &mut impl FnMut(Event<'a>)) -> IResult<&'a [u8], usize> { |
| 305 | 284 | let (i, value_end, newlines, mut dispatch) = { |
| 306 | − let new_err = |kind| winnow::error::ErrMode::Backtrack(NomError { input: i, kind }); | |
| 285 | + let new_err = |kind| winnow::error::ErrMode::from_error_kind(i, kind); | |
| 307 | 286 | let mut value_end = None::<usize>; |
| 308 | 287 | let mut value_start: usize = 0; |
| 309 | 288 | let mut newlines = 0; |
| @@ -419,10 +398,7 @@ fn value_impl<'a>(i: &'a [u8], dispatch: &mut impl FnMut(Event<'a>)) -> IResult< · 109 unmodified lines | ||
| 419 | 398 | fn take_spaces(i: &[u8]) -> IResult<&[u8], &BStr> { |
| 420 | 399 | let (i, v) = take_while(0.., |c: u8| c.is_ascii() && c.is_space()).parse_next(i)?; |
| 421 | 400 | if v.is_empty() { |
| 422 | − Err(winnow::error::ErrMode::Backtrack(NomError { | |
| 423 | − input: i, | |
| 424 | − kind: ErrorKind::Eof, | |
| 425 | − })) | |
| 401 | + Err(winnow::error::ErrMode::from_error_kind(i, ErrorKind::Eof)) | |
| 426 | 402 | } else { |
| 427 | 403 | Ok((i, v.as_bstr())) |
| 428 | 404 | } |
| @@ -453,10 +429,7 @@ fn take_newlines(i: &[u8]) -> IResult<&[u8], (&BStr, usize)> { · 24 unmodified lines | ||
| 453 | 429 | } |
| 454 | 430 | let (v, i) = i.split_at(consumed_bytes); |
| 455 | 431 | if v.is_empty() { |
| 456 | − Err(winnow::error::ErrMode::Backtrack(NomError { | |
| 457 | − input: i, | |
| 458 | − kind: ErrorKind::Eof, | |
| 459 | − })) | |
| 432 | + Err(winnow::error::ErrMode::from_error_kind(i, ErrorKind::Eof)) | |
| 460 | 433 | } else { |
| 461 | 434 | Ok((i, (v.as_bstr(), counter))) |
| 462 | 435 | } |