From 0e9c9aeb9ddf8b86eeb86e1822f7285f65bc0b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Mon, 31 Jan 2022 12:02:02 +0100 Subject: [PATCH] Don't wrap in StrLit just to extract the str imm. --- askama_shared/src/parser.rs | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index 97ccf6c0e..900e71ad7 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -966,19 +966,10 @@ 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<'_>> { @@ -986,7 +977,7 @@ fn block_import(i: &str) -> IResult<&str, Node<'_>> { opt(char('-')), ws(tag("import")), cut(tuple(( - ws(expr_str_lit), + ws(str_lit), ws(tag("as")), cut(pair(ws(identifier), opt(char('-')))), ))), @@ -994,14 +985,7 @@ fn block_import(i: &str) -> IResult<&str, Node<'_>> { 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), )) }