Skip to content

Commit

Permalink
Don't wrap in StrLit just to extract the str imm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski authored and djc committed Jan 31, 2022
1 parent b42ff33 commit 0e9c9ae
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions askama_shared/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,42 +966,26 @@ fn block_include(i: &str) -> IResult<&str, Node<'_>> {
let mut p = tuple((
opt(char('-')),
ws(tag("include")),
cut(pair(ws(expr_str_lit), opt(char('-')))),
cut(pair(ws(str_lit), opt(char('-')))),
));
let (i, (pws, _, (name, nws))) = p(i)?;
Ok((
i,
Node::Include(
Ws(pws.is_some(), nws.is_some()),
match name {
Expr::StrLit(s) => s,
_ => panic!("include path must be a string literal"),
},
),
))
Ok((i, Node::Include(Ws(pws.is_some(), nws.is_some()), name)))
}

fn block_import(i: &str) -> IResult<&str, Node<'_>> {
let mut p = tuple((
opt(char('-')),
ws(tag("import")),
cut(tuple((
ws(expr_str_lit),
ws(str_lit),
ws(tag("as")),
cut(pair(ws(identifier), opt(char('-')))),
))),
));
let (i, (pws, _, (name, _, (scope, nws)))) = p(i)?;
Ok((
i,
Node::Import(
Ws(pws.is_some(), nws.is_some()),
match name {
Expr::StrLit(s) => s,
_ => panic!("import path must be a string literal"),
},
scope,
),
Node::Import(Ws(pws.is_some(), nws.is_some()), name, scope),
))
}

Expand Down

0 comments on commit 0e9c9ae

Please sign in to comment.