Skip to content

Commit

Permalink
refactor(parser): Update signature for 'Expr::filtered'
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Nov 22, 2024
1 parent 7294def commit d5c37dd
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions rinja_parser/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ impl<'a> Expr<'a> {

expr_prec_layer!(muldivmod, is_as, alt(("*", "/", "%")));

fn is_as(i: &'a str, level: Level) -> InputParseResult<'a, WithSpan<'a, Self>> {
fn is_as(mut i: &'a str, level: Level) -> InputParseResult<'a, WithSpan<'a, Self>> {
let start = i;
let (i, lhs) = Self::filtered(i, level)?;
let lhs = Self::filtered(&mut i, level)?;
let before_keyword = i;
let (i, rhs) = opt(ws(identifier)).parse_peek(i)?;
let i = match rhs {
Expand Down Expand Up @@ -367,18 +367,16 @@ impl<'a> Expr<'a> {
Ok((i, WithSpan::new(ctor(var_name), start)))
}

fn filtered(mut i: &'a str, mut level: Level) -> InputParseResult<'a, WithSpan<'a, Self>> {
let start = i;
let mut res = Self::prefix(&mut i, level)?;
while let (j, Some((name, args))) = opt(|i: &mut _| filter(i, &mut level)).parse_peek(i)? {
i = j;

fn filtered(i: &mut &'a str, mut level: Level) -> ParseResult<'a, WithSpan<'a, Self>> {
let start = *i;
let mut res = Self::prefix(i, level)?;
while let Some((name, args)) = opt(|i: &mut _| filter(i, &mut level)).parse_next(i)? {
let mut arguments = args.unwrap_or_else(|| Vec::with_capacity(1));
arguments.insert(0, res);

res = WithSpan::new(Self::Filter(Filter { name, arguments }), start);
}
Ok((i, res))
Ok(res)
}

fn prefix(i: &mut &'a str, mut level: Level) -> ParseResult<'a, WithSpan<'a, Self>> {
Expand Down

0 comments on commit d5c37dd

Please sign in to comment.