diff options
author | Bastien Orivel <bastien@technocreatives.com> | 2022-04-29 13:12:18 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2022-04-29 13:35:20 +0200 |
commit | ea66be1925456285f897bc00a076e4e7af94c313 (patch) | |
tree | b3ae55f1c8f175da0a210e83341514efa7c32920 /askama_shared | |
parent | c3196916710ad26fe5b3429bb1688060108b2f8b (diff) | |
download | askama-ea66be1925456285f897bc00a076e4e7af94c313.tar.gz askama-ea66be1925456285f897bc00a076e4e7af94c313.tar.bz2 askama-ea66be1925456285f897bc00a076e4e7af94c313.zip |
Allow `{% endmacro name %}`
Just migrated a repo from tera to askama and this was one of the only
things that was different. This is also coherent with `{% block %}` for
which I added the same feature years ago.
Diffstat (limited to 'askama_shared')
-rw-r--r-- | askama_shared/src/parser.rs | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index 624fbc6..19df795 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -996,7 +996,7 @@ fn block_import(i: &str) -> IResult<&str, Node<'_>> { } fn block_macro<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, Node<'a>> { - let mut p = tuple(( + let mut start = tuple(( opt(expr_handle_ws), ws(tag("macro")), cut(tuple(( @@ -1004,19 +1004,21 @@ fn block_macro<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, Node<'a>> { ws(parameters), opt(expr_handle_ws), |i| tag_block_end(i, s), - cut(tuple(( - |i| parse_template(i, s), - cut(tuple(( - |i| tag_block_start(i, s), - opt(expr_handle_ws), - ws(tag("endmacro")), - opt(expr_handle_ws), - ))), - ))), ))), )); + let (i, (pws1, _, (name, params, nws1, _))) = start(i)?; + + let mut end = cut(tuple(( + |i| parse_template(i, s), + cut(tuple(( + |i| tag_block_start(i, s), + opt(expr_handle_ws), + ws(tag("endmacro")), + cut(tuple((opt(ws(tag(name))), opt(expr_handle_ws)))), + ))), + ))); + let (i, (contents, (_, pws2, _, (_, nws2)))) = end(i)?; - let (i, (pws1, _, (name, params, nws1, _, (contents, (_, pws2, _, nws2))))) = p(i)?; assert_ne!(name, "super", "invalid macro name 'super'"); Ok(( |