diff options
Diffstat (limited to '')
-rw-r--r-- | askama_parser/src/node.rs | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/askama_parser/src/node.rs b/askama_parser/src/node.rs index f15aa5a..972314e 100644 --- a/askama_parser/src/node.rs +++ b/askama_parser/src/node.rs @@ -28,7 +28,7 @@ pub enum Node<'a> { Extends(&'a str), BlockDef(Ws, &'a str, Vec<Node<'a>>, Ws), Include(Ws, &'a str), - Import(Ws, &'a str, &'a str), + Import(Import<'a>), Macro(Macro<'a>), Raw(Ws, &'a str, &'a str, &'a str, Ws), Break(Ws), @@ -76,7 +76,7 @@ impl<'a> Node<'a> { |i| Self::r#match(i, s), Self::extends, Self::include, - Self::import, + map(Import::parse, Self::Import), |i| Self::block(i, s), map(|i| Macro::parse(i, s), Self::Macro), |i| Self::raw(i, s), @@ -301,20 +301,6 @@ impl<'a> Node<'a> { )) } - fn import(i: &'a str) -> IResult<&'a str, Self> { - let mut p = tuple(( - opt(Whitespace::parse), - ws(keyword("import")), - cut(tuple(( - ws(str_lit), - ws(keyword("as")), - cut(pair(ws(identifier), opt(Whitespace::parse))), - ))), - )); - let (i, (pws, _, (name, _, (scope, nws)))) = p(i)?; - Ok((i, Self::Import(Ws(pws, nws), name, scope))) - } - fn raw(i: &'a str, s: &State<'_>) -> IResult<&'a str, Self> { let endraw = tuple(( |i| s.tag_block_start(i), @@ -728,6 +714,36 @@ impl<'a> Macro<'a> { } } +#[derive(Debug, PartialEq)] +pub struct Import<'a> { + pub ws: Ws, + pub path: &'a str, + pub scope: &'a str, +} + +impl<'a> Import<'a> { + fn parse(i: &'a str) -> IResult<&'a str, Self> { + let mut p = tuple(( + opt(Whitespace::parse), + ws(keyword("import")), + cut(tuple(( + ws(str_lit), + ws(keyword("as")), + cut(pair(ws(identifier), opt(Whitespace::parse))), + ))), + )); + let (i, (pws, _, (path, _, (scope, nws)))) = p(i)?; + Ok(( + i, + Self { + ws: Ws(pws, nws), + path, + scope, + }, + )) + } +} + /// 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". |