refactor(parser): Remove extraneous tag/one_of

These were needed in 0.3 to use `Parser` trait methods on `&str` /
`char` but 0.4 fixed the bounds so that is no longer needed.
This commit is contained in:
Ed Page 2024-07-17 15:29:11 -05:00
parent 9fa2ba225b
commit 0b36317951
2 changed files with 13 additions and 20 deletions

View File

@ -8,7 +8,7 @@ use winnow::combinator::{
terminated,
};
use winnow::error::{ErrorKind, ParserError as _};
use winnow::token::{one_of, tag, take_till0};
use winnow::token::take_till0;
use crate::{
CharLit, ErrorContext, Level, Num, ParseResult, PathOrIdentifier, StrLit, WithSpan, char_lit,
@ -172,7 +172,7 @@ impl<'a> Expr<'a> {
expr_prec_layer!(or, and, "||");
expr_prec_layer!(and, compare, "&&");
expr_prec_layer!(compare, bor, alt(("==", "!=", ">=", ">", "<=", "<",)));
expr_prec_layer!(bor, bxor, tag("bitor").value("|"));
expr_prec_layer!(bor, bxor, "bitor".value("|"));
expr_prec_layer!(bxor, band, token_xor);
expr_prec_layer!(band, shifts, token_bitand);
expr_prec_layer!(shifts, addsub, alt((">>", "<<")));
@ -399,7 +399,7 @@ impl<'a> Expr<'a> {
}
fn token_xor(i: &str) -> ParseResult<'_> {
let (i, good) = alt((keyword("xor").value(true), one_of('^').value(false))).parse_next(i)?;
let (i, good) = alt((keyword("xor").value(true), '^'.value(false))).parse_next(i)?;
if good {
Ok((i, "^"))
} else {

View File

@ -371,16 +371,9 @@ fn num_lit<'a>(start: &'a str) -> ParseResult<'a, Num<'a>> {
// Equivalent to <https://github.com/rust-lang/rust/blob/e3f909b2bbd0b10db6f164d466db237c582d3045/compiler/rustc_lexer/src/lib.rs#L587-L620>.
let int_with_base = (opt('-'), |i| {
let (i, (base, kind)) = preceded(
'0',
alt((
one_of('b').value(2),
one_of('o').value(8),
one_of('x').value(16),
)),
)
.with_recognized()
.parse_next(i)?;
let (i, (base, kind)) = preceded('0', alt(('b'.value(2), 'o'.value(8), 'x'.value(16))))
.with_recognized()
.parse_next(i)?;
match opt(separated_digits(base, false)).parse_next(i)? {
(i, Some(_)) => Ok((i, ())),
(_, None) => Err(winnow::error::ErrMode::Cut(ErrorContext::new(
@ -589,14 +582,14 @@ impl<'a> Char<'a> {
(
'\\',
alt((
one_of('n').value(Self::Escaped),
one_of('r').value(Self::Escaped),
one_of('t').value(Self::Escaped),
one_of('\\').value(Self::Escaped),
one_of('0').value(Self::Escaped),
one_of('\'').value(Self::Escaped),
'n'.value(Self::Escaped),
'r'.value(Self::Escaped),
't'.value(Self::Escaped),
'\\'.value(Self::Escaped),
'0'.value(Self::Escaped),
'\''.value(Self::Escaped),
// Not useful but supported by rust.
one_of('"').value(Self::Escaped),
'"'.value(Self::Escaped),
('x', take_while(2, |c: char| c.is_ascii_hexdigit()))
.map(|(_, s)| Self::AsciiEscape(s)),
(