diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-16 12:50:52 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-16 12:50:52 +0200 |
commit | 05597b61daabfa1ab4c675c2943ceeefcb82db36 (patch) | |
tree | f38f80f0878de4cf88db34c2acf8a243e45a9c5e /askama_derive/src/parser.rs | |
parent | fb11c175b27564a208148c0734200af0d981a0c8 (diff) | |
download | askama-05597b61daabfa1ab4c675c2943ceeefcb82db36.tar.gz askama-05597b61daabfa1ab4c675c2943ceeefcb82db36.tar.bz2 askama-05597b61daabfa1ab4c675c2943ceeefcb82db36.zip |
Allow separation of variable declaration and defintion
Diffstat (limited to '')
-rw-r--r-- | askama_derive/src/parser.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/askama_derive/src/parser.rs b/askama_derive/src/parser.rs index 2a6a602..c6c437c 100644 --- a/askama_derive/src/parser.rs +++ b/askama_derive/src/parser.rs @@ -26,6 +26,7 @@ pub enum Node<'a> { Lit(&'a str, &'a str, &'a str), Comment(), Expr(WS, Expr<'a>), + LetDecl(WS, Target<'a>), Let(WS, Target<'a>, Expr<'a>), Cond(Vec<(WS, Option<Expr<'a>>, Vec<Node<'a>>)>, WS), Loop(WS, Target<'a>, Expr<'a>, Vec<Node<'a>>, WS), @@ -282,10 +283,17 @@ named!(block_let<Node>, do_parse!( pws: opt!(tag_s!("-")) >> ws!(tag_s!("let")) >> var: ws!(target_single) >> - ws!(tag_s!("=")) >> - val: ws!(expr_any) >> + val: opt!(do_parse!( + ws!(tag_s!("=")) >> + val: ws!(expr_any) >> + (val) + )) >> nws: opt!(tag_s!("-")) >> - (Node::Let(WS(pws.is_some(), nws.is_some()), var, val)) + (if val.is_some() { + Node::Let(WS(pws.is_some(), nws.is_some()), var, val.unwrap()) + } else { + Node::LetDecl(WS(pws.is_some(), nws.is_some()), var) + }) )); named!(block_for<Node>, do_parse!( |