mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-30 06:21:13 +00:00
refactor(parser): Remove trivial deprecated 'tag' uses
This commit is contained in:
parent
88c702e6a8
commit
d171cdbaf1
@ -2,7 +2,7 @@ use std::collections::HashSet;
|
||||
use std::str;
|
||||
|
||||
use winnow::branch::alt;
|
||||
use winnow::bytes::complete::{tag, take_till};
|
||||
use winnow::bytes::complete::take_till;
|
||||
use winnow::character::complete::{char, digit1};
|
||||
use winnow::combinator::{consumed, cut, fail, map, not, opt, peek, recognize, value};
|
||||
use winnow::error::ErrorKind;
|
||||
@ -152,13 +152,8 @@ impl<'a> Expr<'a> {
|
||||
pub(super) fn parse(i: &'a str, level: Level) -> ParseResult<'a, WithSpan<'a, Self>> {
|
||||
let (_, level) = level.nest(i)?;
|
||||
let start = i;
|
||||
let range_right = move |i| {
|
||||
pair(
|
||||
ws(alt((tag("..="), tag("..")))),
|
||||
opt(move |i| Self::or(i, level)),
|
||||
)
|
||||
.parse_next(i)
|
||||
};
|
||||
let range_right =
|
||||
move |i| pair(ws(alt(("..=", ".."))), opt(move |i| Self::or(i, level))).parse_next(i);
|
||||
alt((
|
||||
map(range_right, |(op, right)| {
|
||||
WithSpan::new(Self::Range(op, None, right.map(Box::new)), start)
|
||||
@ -177,26 +172,15 @@ impl<'a> Expr<'a> {
|
||||
.parse_next(i)
|
||||
}
|
||||
|
||||
expr_prec_layer!(or, and, tag("||"));
|
||||
expr_prec_layer!(and, compare, tag("&&"));
|
||||
expr_prec_layer!(
|
||||
compare,
|
||||
bor,
|
||||
alt((
|
||||
tag("=="),
|
||||
tag("!="),
|
||||
tag(">="),
|
||||
tag(">"),
|
||||
tag("<="),
|
||||
tag("<"),
|
||||
))
|
||||
);
|
||||
expr_prec_layer!(bor, bxor, value("|", tag("bitor")));
|
||||
expr_prec_layer!(or, and, "||");
|
||||
expr_prec_layer!(and, compare, "&&");
|
||||
expr_prec_layer!(compare, bor, alt(("==", "!=", ">=", ">", "<=", "<",)));
|
||||
expr_prec_layer!(bor, bxor, value("|", "bitor"));
|
||||
expr_prec_layer!(bxor, band, token_xor);
|
||||
expr_prec_layer!(band, shifts, token_bitand);
|
||||
expr_prec_layer!(shifts, addsub, alt((tag(">>"), tag("<<"))));
|
||||
expr_prec_layer!(addsub, muldivmod, alt((tag("+"), tag("-"))));
|
||||
expr_prec_layer!(muldivmod, is_as, alt((tag("*"), tag("/"), tag("%"))));
|
||||
expr_prec_layer!(shifts, addsub, alt((">>", "<<")));
|
||||
expr_prec_layer!(addsub, muldivmod, alt(("+", "-")));
|
||||
expr_prec_layer!(muldivmod, is_as, alt(("*", "/", "%")));
|
||||
|
||||
fn is_as(i: &'a str, level: Level) -> ParseResult<'a, WithSpan<'a, Self>> {
|
||||
let start = i;
|
||||
@ -276,7 +260,7 @@ impl<'a> Expr<'a> {
|
||||
let (_, nested) = level.nest(i)?;
|
||||
let start = i;
|
||||
let (i, (ops, mut expr)) = pair(
|
||||
many0(ws(alt((tag("!"), tag("-"), tag("*"), tag("&"))))).map(|v: Vec<_>| v),
|
||||
many0(ws(alt(("!", "-", "*", "&")))).map(|v: Vec<_>| v),
|
||||
|i| Suffix::parse(i, nested),
|
||||
)
|
||||
.parse_next(i)?;
|
||||
|
@ -616,7 +616,7 @@ impl<'a> Char<'a> {
|
||||
),
|
||||
map(
|
||||
tuple((
|
||||
tag("u{"),
|
||||
"u{",
|
||||
take_while_m_n(1, 6, |c: char| c.is_ascii_hexdigit()),
|
||||
char('}'),
|
||||
)),
|
||||
@ -636,8 +636,8 @@ enum PathOrIdentifier<'a> {
|
||||
}
|
||||
|
||||
fn path_or_identifier(i: &str) -> ParseResult<'_, PathOrIdentifier<'_>> {
|
||||
let root = ws(opt(tag("::")));
|
||||
let tail = opt(many1(preceded(ws(tag("::")), identifier)).map(|v: Vec<_>| v));
|
||||
let root = ws(opt("::"));
|
||||
let tail = opt(many1(preceded(ws("::"), identifier)).map(|v: Vec<_>| v));
|
||||
|
||||
let (i, (root, start, rest)) = tuple((root, identifier, tail)).parse_next(i)?;
|
||||
let rest = rest.as_deref().unwrap_or_default();
|
||||
|
@ -797,7 +797,7 @@ impl<'a> Call<'a> {
|
||||
cut_node(
|
||||
Some("call"),
|
||||
tuple((
|
||||
opt(tuple((ws(identifier), ws(tag("::"))))),
|
||||
opt(tuple((ws(identifier), ws("::")))),
|
||||
ws(identifier),
|
||||
opt(ws(|nested| Expr::arguments(nested, s.level.get(), true))),
|
||||
opt(Whitespace::parse),
|
||||
|
@ -1,6 +1,5 @@
|
||||
use winnow::Parser;
|
||||
use winnow::branch::alt;
|
||||
use winnow::bytes::complete::tag;
|
||||
use winnow::character::complete::{char, one_of};
|
||||
use winnow::combinator::{consumed, map, map_res, opt};
|
||||
use winnow::multi::separated_list1;
|
||||
@ -32,8 +31,7 @@ impl<'a> Target<'a> {
|
||||
/// Parses multiple targets with `or` separating them
|
||||
pub(super) fn parse(i: &'a str, s: &State<'_>) -> ParseResult<'a, Self> {
|
||||
map(
|
||||
separated_list1(ws(tag("or")), |i| s.nest(i, |i| Self::parse_one(i, s)))
|
||||
.map(|v: Vec<_>| v),
|
||||
separated_list1(ws("or"), |i| s.nest(i, |i| Self::parse_one(i, s))).map(|v: Vec<_>| v),
|
||||
|mut opts| match opts.len() {
|
||||
1 => opts.pop().unwrap(),
|
||||
_ => Self::OrChain(opts),
|
||||
@ -177,7 +175,7 @@ impl<'a> Target<'a> {
|
||||
|
||||
fn rest(start: &'a str) -> ParseResult<'a, Self> {
|
||||
let (i, (ident, _)) =
|
||||
tuple((opt(tuple((identifier, ws(char('@'))))), tag(".."))).parse_next(start)?;
|
||||
tuple((opt(tuple((identifier, ws(char('@'))))), "..")).parse_next(start)?;
|
||||
Ok((
|
||||
i,
|
||||
Self::Rest(WithSpan::new(ident.map(|(ident, _)| ident), start)),
|
||||
|
Loading…
x
Reference in New Issue
Block a user