mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-03 07:45:14 +00:00
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:
parent
9fa2ba225b
commit
0b36317951
@ -8,7 +8,7 @@ use winnow::combinator::{
|
|||||||
terminated,
|
terminated,
|
||||||
};
|
};
|
||||||
use winnow::error::{ErrorKind, ParserError as _};
|
use winnow::error::{ErrorKind, ParserError as _};
|
||||||
use winnow::token::{one_of, tag, take_till0};
|
use winnow::token::take_till0;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
CharLit, ErrorContext, Level, Num, ParseResult, PathOrIdentifier, StrLit, WithSpan, char_lit,
|
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!(or, and, "||");
|
||||||
expr_prec_layer!(and, compare, "&&");
|
expr_prec_layer!(and, compare, "&&");
|
||||||
expr_prec_layer!(compare, bor, alt(("==", "!=", ">=", ">", "<=", "<",)));
|
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!(bxor, band, token_xor);
|
||||||
expr_prec_layer!(band, shifts, token_bitand);
|
expr_prec_layer!(band, shifts, token_bitand);
|
||||||
expr_prec_layer!(shifts, addsub, alt((">>", "<<")));
|
expr_prec_layer!(shifts, addsub, alt((">>", "<<")));
|
||||||
@ -399,7 +399,7 @@ impl<'a> Expr<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn token_xor(i: &str) -> ParseResult<'_> {
|
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 {
|
if good {
|
||||||
Ok((i, "^"))
|
Ok((i, "^"))
|
||||||
} else {
|
} else {
|
||||||
|
@ -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>.
|
// 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 int_with_base = (opt('-'), |i| {
|
||||||
let (i, (base, kind)) = preceded(
|
let (i, (base, kind)) = preceded('0', alt(('b'.value(2), 'o'.value(8), 'x'.value(16))))
|
||||||
'0',
|
.with_recognized()
|
||||||
alt((
|
.parse_next(i)?;
|
||||||
one_of('b').value(2),
|
|
||||||
one_of('o').value(8),
|
|
||||||
one_of('x').value(16),
|
|
||||||
)),
|
|
||||||
)
|
|
||||||
.with_recognized()
|
|
||||||
.parse_next(i)?;
|
|
||||||
match opt(separated_digits(base, false)).parse_next(i)? {
|
match opt(separated_digits(base, false)).parse_next(i)? {
|
||||||
(i, Some(_)) => Ok((i, ())),
|
(i, Some(_)) => Ok((i, ())),
|
||||||
(_, None) => Err(winnow::error::ErrMode::Cut(ErrorContext::new(
|
(_, None) => Err(winnow::error::ErrMode::Cut(ErrorContext::new(
|
||||||
@ -589,14 +582,14 @@ impl<'a> Char<'a> {
|
|||||||
(
|
(
|
||||||
'\\',
|
'\\',
|
||||||
alt((
|
alt((
|
||||||
one_of('n').value(Self::Escaped),
|
'n'.value(Self::Escaped),
|
||||||
one_of('r').value(Self::Escaped),
|
'r'.value(Self::Escaped),
|
||||||
one_of('t').value(Self::Escaped),
|
't'.value(Self::Escaped),
|
||||||
one_of('\\').value(Self::Escaped),
|
'\\'.value(Self::Escaped),
|
||||||
one_of('0').value(Self::Escaped),
|
'0'.value(Self::Escaped),
|
||||||
one_of('\'').value(Self::Escaped),
|
'\''.value(Self::Escaped),
|
||||||
// Not useful but supported by rust.
|
// Not useful but supported by rust.
|
||||||
one_of('"').value(Self::Escaped),
|
'"'.value(Self::Escaped),
|
||||||
('x', take_while(2, |c: char| c.is_ascii_hexdigit()))
|
('x', take_while(2, |c: char| c.is_ascii_hexdigit()))
|
||||||
.map(|(_, s)| Self::AsciiEscape(s)),
|
.map(|(_, s)| Self::AsciiEscape(s)),
|
||||||
(
|
(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user