From 1521a08a20b6631b54d4ecbbbfcb4260e393bc97 Mon Sep 17 00:00:00 2001 From: René Kijewski Date: Tue, 1 Aug 2023 04:22:52 +0200 Subject: parser: add type for `Node::Extends` --- askama_parser/src/node.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'askama_parser/src/node.rs') diff --git a/askama_parser/src/node.rs b/askama_parser/src/node.rs index cb6da92..b955549 100644 --- a/askama_parser/src/node.rs +++ b/askama_parser/src/node.rs @@ -24,7 +24,7 @@ pub enum Node<'a> { If(If<'a>), Match(Match<'a>), Loop(Loop<'a>), - Extends(&'a str), + Extends(Extends<'a>), BlockDef(BlockDef<'a>), Include(Include<'a>), Import(Import<'a>), @@ -53,7 +53,7 @@ impl<'a> Node<'a> { map(|i| If::parse(i, s), Self::If), |i| Self::r#for(i, s), map(|i| Match::parse(i, s), Self::Match), - Self::extends, + map(Extends::parse, Self::Extends), map(Include::parse, Self::Include), map(Import::parse, Self::Import), map(|i| BlockDef::parse(i, s), Self::BlockDef), @@ -135,11 +135,6 @@ impl<'a> Node<'a> { )) } - fn extends(i: &'a str) -> IResult<&'a str, Self> { - let (i, (_, name)) = tuple((ws(keyword("extends")), ws(str_lit)))(i)?; - Ok((i, Self::Extends(name))) - } - fn r#break(i: &'a str, s: &State<'_>) -> IResult<&'a str, Self> { let mut p = tuple(( opt(Whitespace::parse), @@ -857,6 +852,18 @@ impl<'a> Include<'a> { } } +#[derive(Debug, PartialEq)] +pub struct Extends<'a> { + pub path: &'a str, +} + +impl<'a> Extends<'a> { + fn parse(i: &'a str) -> IResult<&'a str, Self> { + let (i, path) = preceded(ws(keyword("extends")), cut(ws(str_lit)))(i)?; + Ok((i, Self { path })) + } +} + /// First field is "minus/plus sign was used on the left part of the item". /// /// Second field is "minus/plus sign was used on the right part of the item". -- cgit