Skip to content

Commit

Permalink
fix(error)!: Rename kinds Tag->Literal, Many->Repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jan 3, 2025
1 parent f3e8d45 commit 32770f9
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 170 deletions.
42 changes: 21 additions & 21 deletions src/ascii/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ use crate::Parser;
/// assert_eq!(parser.parse_peek("Hello, World!"), Ok((", World!", "Hello")));
/// assert_eq!(parser.parse_peek("hello, World!"), Ok((", World!", "hello")));
/// assert_eq!(parser.parse_peek("HeLlo, World!"), Ok((", World!", "HeLlo")));
/// assert_eq!(parser.parse_peek("Some"), Err(ErrMode::Backtrack(InputError::new("Some", ErrorKind::Tag))));
/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// assert_eq!(parser.parse_peek("Some"), Err(ErrMode::Backtrack(InputError::new("Some", ErrorKind::Literal))));
/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Literal))));
/// ```
#[derive(Copy, Clone, Debug)]
pub struct Caseless<T>(pub T);
Expand Down Expand Up @@ -83,8 +83,8 @@ impl Caseless<&str> {
/// }
///
/// assert_eq!(parser.parse_peek("\r\nc"), Ok(("c", "\r\n")));
/// assert_eq!(parser.parse_peek("ab\r\nc"), Err(ErrMode::Backtrack(InputError::new("ab\r\nc", ErrorKind::Tag))));
/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// assert_eq!(parser.parse_peek("ab\r\nc"), Err(ErrMode::Backtrack(InputError::new("ab\r\nc", ErrorKind::Literal))));
/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Literal))));
/// ```
///
/// ```
Expand All @@ -93,7 +93,7 @@ impl Caseless<&str> {
/// # use winnow::Partial;
/// # use winnow::ascii::crlf;
/// assert_eq!(crlf::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Ok((Partial::new("c"), "\r\n")));
/// assert_eq!(crlf::<_, InputError<_>>.parse_peek(Partial::new("ab\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("ab\r\nc"), ErrorKind::Tag))));
/// assert_eq!(crlf::<_, InputError<_>>.parse_peek(Partial::new("ab\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("ab\r\nc"), ErrorKind::Literal))));
/// assert_eq!(crlf::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(2))));
/// ```
#[inline(always)]
Expand Down Expand Up @@ -136,8 +136,8 @@ where
/// assert_eq!(parser.parse_peek("ab\nc"), Ok(("\nc", "ab")));
/// assert_eq!(parser.parse_peek("abc"), Ok(("", "abc")));
/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
/// assert_eq!(parser.parse_peek("a\rb\nc"), Err(ErrMode::Backtrack(InputError::new("\rb\nc", ErrorKind::Tag ))));
/// assert_eq!(parser.parse_peek("a\rbc"), Err(ErrMode::Backtrack(InputError::new("\rbc", ErrorKind::Tag ))));
/// assert_eq!(parser.parse_peek("a\rb\nc"), Err(ErrMode::Backtrack(InputError::new("\rb\nc", ErrorKind::Literal ))));
/// assert_eq!(parser.parse_peek("a\rbc"), Err(ErrMode::Backtrack(InputError::new("\rbc", ErrorKind::Literal ))));
/// ```
///
/// ```
Expand All @@ -148,8 +148,8 @@ where
/// assert_eq!(till_line_ending::<_, InputError<_>>.parse_peek(Partial::new("ab\r\nc")), Ok((Partial::new("\r\nc"), "ab")));
/// assert_eq!(till_line_ending::<_, InputError<_>>.parse_peek(Partial::new("abc")), Err(ErrMode::Incomplete(Needed::Unknown)));
/// assert_eq!(till_line_ending::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::Unknown)));
/// assert_eq!(till_line_ending::<_, InputError<_>>.parse_peek(Partial::new("a\rb\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\rb\nc"), ErrorKind::Tag ))));
/// assert_eq!(till_line_ending::<_, InputError<_>>.parse_peek(Partial::new("a\rbc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\rbc"), ErrorKind::Tag ))));
/// assert_eq!(till_line_ending::<_, InputError<_>>.parse_peek(Partial::new("a\rb\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\rb\nc"), ErrorKind::Literal ))));
/// assert_eq!(till_line_ending::<_, InputError<_>>.parse_peek(Partial::new("a\rbc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\rbc"), ErrorKind::Literal ))));
/// ```
#[inline(always)]
pub fn till_line_ending<Input, Error>(input: &mut Input) -> PResult<<Input as Stream>::Slice, Error>
Expand Down Expand Up @@ -193,7 +193,7 @@ where
return Err(ErrMode::Incomplete(Needed::Unknown));
}
CompareResult::Incomplete | CompareResult::Error => {
let e: ErrorKind = ErrorKind::Tag;
let e: ErrorKind = ErrorKind::Literal;
return Err(ErrMode::from_error_kind(input, e));
}
}
Expand Down Expand Up @@ -229,8 +229,8 @@ where
/// }
///
/// assert_eq!(parser.parse_peek("\r\nc"), Ok(("c", "\r\n")));
/// assert_eq!(parser.parse_peek("ab\r\nc"), Err(ErrMode::Backtrack(InputError::new("ab\r\nc", ErrorKind::Tag))));
/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// assert_eq!(parser.parse_peek("ab\r\nc"), Err(ErrMode::Backtrack(InputError::new("ab\r\nc", ErrorKind::Literal))));
/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Literal))));
/// ```
///
/// ```
Expand All @@ -239,7 +239,7 @@ where
/// # use winnow::Partial;
/// # use winnow::ascii::line_ending;
/// assert_eq!(line_ending::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Ok((Partial::new("c"), "\r\n")));
/// assert_eq!(line_ending::<_, InputError<_>>.parse_peek(Partial::new("ab\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("ab\r\nc"), ErrorKind::Tag))));
/// assert_eq!(line_ending::<_, InputError<_>>.parse_peek(Partial::new("ab\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("ab\r\nc"), ErrorKind::Literal))));
/// assert_eq!(line_ending::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
Expand Down Expand Up @@ -279,8 +279,8 @@ where
/// }
///
/// assert_eq!(parser.parse_peek("\nc"), Ok(("c", '\n')));
/// assert_eq!(parser.parse_peek("\r\nc"), Err(ErrMode::Backtrack(InputError::new("\r\nc", ErrorKind::Tag))));
/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// assert_eq!(parser.parse_peek("\r\nc"), Err(ErrMode::Backtrack(InputError::new("\r\nc", ErrorKind::Literal))));
/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Literal))));
/// ```
///
/// ```
Expand All @@ -289,7 +289,7 @@ where
/// # use winnow::Partial;
/// # use winnow::ascii::newline;
/// assert_eq!(newline::<_, InputError<_>>.parse_peek(Partial::new("\nc")), Ok((Partial::new("c"), '\n')));
/// assert_eq!(newline::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\r\nc"), ErrorKind::Tag))));
/// assert_eq!(newline::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\r\nc"), ErrorKind::Literal))));
/// assert_eq!(newline::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
Expand Down Expand Up @@ -330,8 +330,8 @@ where
/// }
///
/// assert_eq!(parser.parse_peek("\tc"), Ok(("c", '\t')));
/// assert_eq!(parser.parse_peek("\r\nc"), Err(ErrMode::Backtrack(InputError::new("\r\nc", ErrorKind::Tag))));
/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// assert_eq!(parser.parse_peek("\r\nc"), Err(ErrMode::Backtrack(InputError::new("\r\nc", ErrorKind::Literal))));
/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Literal))));
/// ```
///
/// ```
Expand All @@ -340,7 +340,7 @@ where
/// # use winnow::Partial;
/// # use winnow::ascii::tab;
/// assert_eq!(tab::<_, InputError<_>>.parse_peek(Partial::new("\tc")), Ok((Partial::new("c"), '\t')));
/// assert_eq!(tab::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\r\nc"), ErrorKind::Tag))));
/// assert_eq!(tab::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\r\nc"), ErrorKind::Literal))));
/// assert_eq!(tab::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
Expand Down Expand Up @@ -1458,7 +1458,7 @@ impl HexUint for u128 {
/// assert_eq!(parser.parse_peek("11e-1"), Ok(("", 1.1)));
/// assert_eq!(parser.parse_peek("123E-02"), Ok(("", 1.23)));
/// assert_eq!(parser.parse_peek("123K-01"), Ok(("K-01", 123.0)));
/// assert_eq!(parser.parse_peek("abc"), Err(ErrMode::Backtrack(InputError::new("abc", ErrorKind::Tag))));
/// assert_eq!(parser.parse_peek("abc"), Err(ErrMode::Backtrack(InputError::new("abc", ErrorKind::Literal))));
/// ```
///
/// ```rust
Expand All @@ -1476,7 +1476,7 @@ impl HexUint for u128 {
/// assert_eq!(parser.parse_peek(Partial::new("11e-1")), Err(ErrMode::Incomplete(Needed::new(1))));
/// assert_eq!(parser.parse_peek(Partial::new("123E-02")), Err(ErrMode::Incomplete(Needed::new(1))));
/// assert_eq!(parser.parse_peek(Partial::new("123K-01")), Ok((Partial::new("K-01"), 123.0)));
/// assert_eq!(parser.parse_peek(Partial::new("abc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("abc"), ErrorKind::Tag))));
/// assert_eq!(parser.parse_peek(Partial::new("abc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("abc"), ErrorKind::Literal))));
/// ```
#[inline(always)]
#[doc(alias = "f32")]
Expand Down
48 changes: 30 additions & 18 deletions src/ascii/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ mod complete {
till_line_ending.parse_peek(f),
Err(ErrMode::Backtrack(InputError::new(
&f[12..],
ErrorKind::Tag
ErrorKind::Literal
)))
);

Expand Down Expand Up @@ -367,25 +367,31 @@ mod complete {
crlf.parse_peek(&b"\r"[..]),
Err(ErrMode::Backtrack(error_position!(
&&b"\r"[..],
ErrorKind::Tag
ErrorKind::Literal
)))
);
assert_parse!(
crlf.parse_peek(&b"\ra"[..]),
Err(ErrMode::Backtrack(error_position!(
&&b"\ra"[..],
ErrorKind::Tag
ErrorKind::Literal
)))
);

assert_parse!(crlf.parse_peek("\r\na"), Ok(("a", "\r\n")));
assert_parse!(
crlf.parse_peek("\r"),
Err(ErrMode::Backtrack(error_position!(&"\r", ErrorKind::Tag)))
Err(ErrMode::Backtrack(error_position!(
&"\r",
ErrorKind::Literal
)))
);
assert_parse!(
crlf.parse_peek("\ra"),
Err(ErrMode::Backtrack(error_position!(&"\ra", ErrorKind::Tag)))
Err(ErrMode::Backtrack(error_position!(
&"\ra",
ErrorKind::Literal
)))
);
}

Expand All @@ -403,26 +409,32 @@ mod complete {
line_ending.parse_peek(&b"\r"[..]),
Err(ErrMode::Backtrack(error_position!(
&&b"\r"[..],
ErrorKind::Tag
ErrorKind::Literal
)))
);
assert_parse!(
line_ending.parse_peek(&b"\ra"[..]),
Err(ErrMode::Backtrack(error_position!(
&&b"\ra"[..],
ErrorKind::Tag
ErrorKind::Literal
)))
);

assert_parse!(line_ending.parse_peek("\na"), Ok(("a", "\n")));
assert_parse!(line_ending.parse_peek("\r\na"), Ok(("a", "\r\n")));
assert_parse!(
line_ending.parse_peek("\r"),
Err(ErrMode::Backtrack(error_position!(&"\r", ErrorKind::Tag)))
Err(ErrMode::Backtrack(error_position!(
&"\r",
ErrorKind::Literal
)))
);
assert_parse!(
line_ending.parse_peek("\ra"),
Err(ErrMode::Backtrack(error_position!(&"\ra", ErrorKind::Tag)))
Err(ErrMode::Backtrack(error_position!(
&"\ra",
ErrorKind::Literal
)))
);
}

Expand Down Expand Up @@ -810,15 +822,15 @@ mod complete {
esc(&b"AB\\"[..]),
Err(ErrMode::Backtrack(error_position!(
&&b""[..],
ErrorKind::Tag
ErrorKind::Literal
)))
);
assert_eq!(
esc(&b"AB\\A"[..]),
Err(ErrMode::Backtrack(error_node_position!(
&&b"AB\\A"[..],
ErrorKind::Eof,
error_position!(&&b"A"[..], ErrorKind::Tag)
error_position!(&&b"A"[..], ErrorKind::Literal)
)))
);

Expand Down Expand Up @@ -865,14 +877,14 @@ mod complete {
assert_eq!(esc("ab\\\"12"), Ok(("12", String::from("ab\""))));
assert_eq!(
esc("AB\\"),
Err(ErrMode::Backtrack(error_position!(&"", ErrorKind::Tag)))
Err(ErrMode::Backtrack(error_position!(&"", ErrorKind::Literal)))
);
assert_eq!(
esc("AB\\A"),
Err(ErrMode::Backtrack(error_node_position!(
&"AB\\A",
ErrorKind::Eof,
error_position!(&"A", ErrorKind::Tag)
error_position!(&"A", ErrorKind::Literal)
)))
);

Expand Down Expand Up @@ -1261,7 +1273,7 @@ mod partial {
till_line_ending.parse_peek(Partial::new(f)),
Err(ErrMode::Backtrack(InputError::new(
Partial::new(&f[12..]),
ErrorKind::Tag
ErrorKind::Literal
)))
);

Expand Down Expand Up @@ -1397,7 +1409,7 @@ mod partial {
crlf.parse_peek(Partial::new(&b"\ra"[..])),
Err(ErrMode::Backtrack(error_position!(
&Partial::new(&b"\ra"[..]),
ErrorKind::Tag
ErrorKind::Literal
)))
);

Expand All @@ -1413,7 +1425,7 @@ mod partial {
crlf.parse_peek(Partial::new("\ra")),
Err(ErrMode::Backtrack(error_position!(
&Partial::new("\ra"),
ErrorKind::Tag
ErrorKind::Literal
)))
);
}
Expand All @@ -1436,7 +1448,7 @@ mod partial {
line_ending.parse_peek(Partial::new(&b"\ra"[..])),
Err(ErrMode::Backtrack(error_position!(
&Partial::new(&b"\ra"[..]),
ErrorKind::Tag
ErrorKind::Literal
)))
);

Expand All @@ -1456,7 +1468,7 @@ mod partial {
line_ending.parse_peek(Partial::new("\ra")),
Err(ErrMode::Backtrack(error_position!(
&Partial::new("\ra"),
ErrorKind::Tag
ErrorKind::Literal
)))
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/binary/bits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ where
/// parser(0b000000_01, 2, (stream(&[0b111111_11]), 0)),
/// Err(winnow::error::ErrMode::Backtrack(InputError::new(
/// (stream(&[0b11111111]), 0),
/// ErrorKind::Tag
/// ErrorKind::Literal
/// )))
/// );
///
Expand All @@ -331,7 +331,7 @@ where
/// parser(0b11111110, 8, (stream(&[0b11111111]), 0)),
/// Err(winnow::error::ErrMode::Backtrack(InputError::new(
/// (stream(&[0b11111111]), 0),
/// ErrorKind::Tag
/// ErrorKind::Literal
/// )))
/// );
/// ```
Expand Down Expand Up @@ -363,7 +363,7 @@ where
input.reset(&start);
Err(ErrMode::Backtrack(Error::from_error_kind(
input,
ErrorKind::Tag,
ErrorKind::Literal,
)))
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/binary/bits/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn test_pattern_partial_err() {
result,
Err(crate::error::ErrMode::Backtrack(InputError::new(
(input, offset),
ErrorKind::Tag
ErrorKind::Literal
)))
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2460,7 +2460,7 @@ where
/// }
///
/// assert_eq!(parser(stream(b"\x00\x03abcefg")), Ok((stream(&b"efg"[..]), &b"abc"[..])));
/// assert_eq!(parser(stream(b"\x00\x03123123")), Err(ErrMode::Backtrack(InputError::new(complete_stream(&b"123"[..]), ErrorKind::Tag))));
/// assert_eq!(parser(stream(b"\x00\x03123123")), Err(ErrMode::Backtrack(InputError::new(complete_stream(&b"123"[..]), ErrorKind::Literal))));
/// assert_eq!(parser(stream(b"\x00\x03a")), Err(ErrMode::Incomplete(Needed::new(2))));
/// ```
pub fn length_and_then<Input, Output, Count, Error, CountParser, ParseNext>(
Expand Down Expand Up @@ -2512,7 +2512,7 @@ where
/// }
///
/// assert_eq!(parser(stream(b"\x02abcabcabc")), Ok((stream(b"abc"), vec![&b"abc"[..], &b"abc"[..]])));
/// assert_eq!(parser(stream(b"\x03123123123")), Err(ErrMode::Backtrack(InputError::new(stream(b"123123123"), ErrorKind::Tag))));
/// assert_eq!(parser(stream(b"\x03123123123")), Err(ErrMode::Backtrack(InputError::new(stream(b"123123123"), ErrorKind::Literal))));
/// # }
/// ```
pub fn length_repeat<Input, Output, Accumulator, Count, Error, CountParser, ParseNext>(
Expand Down
2 changes: 1 addition & 1 deletion src/binary/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ mod partial {
cnt(Partial::new(&b"2abcxxx"[..])),
Err(ErrMode::Backtrack(error_position!(
&Partial::new(&b"xxx"[..]),
ErrorKind::Tag
ErrorKind::Literal
)))
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/combinator/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub trait Permutation<I, O, E> {
///
/// // any parses 'a', then char('a') fails on 'b',
/// // even though char('a') followed by any would succeed
/// assert_eq!(parser("ab"), Err(ErrMode::Backtrack(InputError::new("b", ErrorKind::Tag))));
/// assert_eq!(parser("ab"), Err(ErrMode::Backtrack(InputError::new("b", ErrorKind::Literal))));
/// ```
///
#[inline(always)]
Expand Down
Loading

0 comments on commit 32770f9

Please sign in to comment.