aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-02-08 11:42:35 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-02-08 11:42:35 +0100
commitb1dc4d5057198330551879c48cb1b4dceb9f381e (patch)
tree763e9ba7fbd390ec33a953d758e5f36c44939d69
parentba399c91b5e0fd1acabd49e75ff32da7e273917e (diff)
downloadaskama-b1dc4d5057198330551879c48cb1b4dceb9f381e.tar.gz
askama-b1dc4d5057198330551879c48cb1b4dceb9f381e.tar.bz2
askama-b1dc4d5057198330551879c48cb1b4dceb9f381e.zip
Improve readability of parser macro invocations
Diffstat (limited to '')
-rw-r--r--askama/src/parser.rs41
1 files changed, 26 insertions, 15 deletions
diff --git a/askama/src/parser.rs b/askama/src/parser.rs
index bb59b48..f6a8726 100644
--- a/askama/src/parser.rs
+++ b/askama/src/parser.rs
@@ -62,7 +62,8 @@ fn take_content(i: &[u8]) -> IResult<&[u8], Node> {
named!(expr_str_lit<Expr>, map!(
delimited!(char!('"'), is_not!("\""), char!('"')),
- |s| Expr::StrLit(str::from_utf8(s).unwrap())));
+ |s| Expr::StrLit(str::from_utf8(s).unwrap())
+));
named!(expr_var<Expr>, map!(nom::alphanumeric, Expr::Var));
@@ -100,21 +101,25 @@ named!(expr_compare<Expr>, do_parse!(
)) >>
right: expr_filtered >>
(Expr::Compare(str::from_utf8(op).unwrap(),
- Box::new(left), Box::new(right)))));
+ Box::new(left), Box::new(right)))
+));
named!(expr_any<Expr>, alt!(
expr_compare |
expr_filtered |
- expr_str_lit));
+ expr_str_lit
+));
named!(expr_node<Node>, map!(
delimited!(tag_s!("{{"), ws!(expr_any), tag_s!("}}")),
- Node::Expr));
+ Node::Expr
+));
named!(cond_if<Expr>, do_parse!(
ws!(tag_s!("if")) >>
cond: ws!(expr_any) >>
- (cond)));
+ (cond)
+));
named!(cond_block<Cond>, do_parse!(
tag_s!("{%") >>
@@ -122,7 +127,8 @@ named!(cond_block<Cond>, do_parse!(
cond: opt!(cond_if) >>
tag_s!("%}") >>
block: parse_template >>
- (cond, block)));
+ (cond, block)
+));
named!(block_if<Node>, do_parse!(
tag_s!("{%") >>
@@ -134,11 +140,12 @@ named!(block_if<Node>, do_parse!(
ws!(tag_s!("endif")) >>
tag_s!("%}") >>
({
- let mut res = Vec::new();
- res.push((Some(cond), block));
- res.extend(elifs);
- Node::Cond(res)
- })));
+ let mut res = Vec::new();
+ res.push((Some(cond), block));
+ res.extend(elifs);
+ Node::Cond(res)
+ })
+));
named!(block_for<Node>, do_parse!(
tag_s!("{%") >>
@@ -151,14 +158,16 @@ named!(block_for<Node>, do_parse!(
tag_s!("{%") >>
ws!(tag_s!("endfor")) >>
tag_s!("%}") >>
- (Node::Loop(var, iter, block))));
+ (Node::Loop(var, iter, block))
+));
named!(block_extends<Node>, do_parse!(
tag_s!("{%") >>
ws!(tag_s!("extends")) >>
name: ws!(expr_str_lit) >>
tag_s!("%}") >>
- (Node::Extends(name))));
+ (Node::Extends(name))
+));
named!(block_block<Node>, do_parse!(
tag_s!("{%") >>
@@ -169,7 +178,8 @@ named!(block_block<Node>, do_parse!(
tag_s!("{%") >>
ws!(tag_s!("endblock")) >>
tag_s!("%}") >>
- (Node::BlockDef(str::from_utf8(name).unwrap(), contents))));
+ (Node::BlockDef(str::from_utf8(name).unwrap(), contents))
+));
named!(parse_template<Vec<Node<'a>>>, many0!(alt!(
take_content |
@@ -177,7 +187,8 @@ named!(parse_template<Vec<Node<'a>>>, many0!(alt!(
block_if |
block_for |
block_extends |
- block_block)));
+ block_block
+)));
pub fn parse(src: &str) -> Vec<Node> {
match parse_template(src.as_bytes()) {