Skip to content

Commit

Permalink
parser: rename block to nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Jul 31, 2023
1 parent ee24662 commit 0c2b8ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
6 changes: 3 additions & 3 deletions askama_derive/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ impl<'a> Generator<'a> {

buf.writeln(" {")?;

arm_size += self.handle(ctx, &cond.block, buf, AstLevel::Nested)?;
arm_size += self.handle(ctx, &cond.nodes, buf, AstLevel::Nested)?;
arm_sizes.push(arm_size);
}
self.handle_ws(ws);
Expand Down Expand Up @@ -809,7 +809,7 @@ impl<'a> Generator<'a> {
self.visit_target(buf, true, true, &arm.target);
buf.writeln(" => {")?;

arm_size = self.handle(ctx, &arm.block, buf, AstLevel::Nested)?;
arm_size = self.handle(ctx, &arm.nodes, buf, AstLevel::Nested)?;
}

self.handle_ws(ws2);
Expand Down Expand Up @@ -881,7 +881,7 @@ impl<'a> Generator<'a> {

buf.writeln("if !_did_loop {")?;
self.locals.push();
let mut size_hint2 = self.handle(ctx, &loop_block.else_block, buf, AstLevel::Nested)?;
let mut size_hint2 = self.handle(ctx, &loop_block.else_nodes, buf, AstLevel::Nested)?;
self.handle_ws(loop_block.ws3);
size_hint2 += self.write_buf_writable(buf)?;
self.locals.pop();
Expand Down
8 changes: 5 additions & 3 deletions askama_derive/src/heritage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,20 @@ impl Context<'_> {
}
Node::Cond(branches, _) => {
for cond in branches {
nested.push(&cond.block);
nested.push(&cond.nodes);
}
}
Node::Loop(Loop {
body, else_block, ..
body,
else_nodes: else_block,
..
}) => {
nested.push(body);
nested.push(else_block);
}
Node::Match(_, _, arms, _) => {
for arm in arms {
nested.push(&arm.block);
nested.push(&arm.nodes);
}
}
_ => {}
Expand Down
25 changes: 13 additions & 12 deletions askama_parser/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,15 @@ impl<'a> Node<'a> {
))),
))),
));
let (i, (pws1, cond, (nws1, _, (block, elifs, (_, pws2, _, nws2))))) = p(i)?;

let (i, (pws1, cond, (nws1, _, (nodes, elifs, (_, pws2, _, nws2))))) = p(i)?;
let mut res = vec![Cond {
ws: Ws(pws1, nws1),
cond: Some(cond),
block,
nodes,
}];
res.extend(elifs);

Ok((i, Self::Cond(res, Ws(pws2, nws2))))
}

Expand Down Expand Up @@ -219,7 +220,7 @@ impl<'a> Node<'a> {
cond,
body,
ws2: Ws(pws2, nws3),
else_block,
else_nodes: else_block,
ws3: Ws(pws3, nws2),
}),
))
Expand Down Expand Up @@ -582,7 +583,7 @@ impl<'a> Target<'a> {
pub struct When<'a> {
pub ws: Ws,
pub target: Target<'a>,
pub block: Vec<Node<'a>>,
pub nodes: Vec<Node<'a>>,
}

impl<'a> When<'a> {
Expand All @@ -597,13 +598,13 @@ impl<'a> When<'a> {
cut(|i| Node::many(i, s)),
))),
));
let (i, (_, pws, _, (nws, _, block))) = p(i)?;
let (i, (_, pws, _, (nws, _, nodes))) = p(i)?;
Ok((
i,
Self {
ws: Ws(pws, nws),
target: Target::Name("_"),
block,
nodes,
},
))
}
Expand All @@ -621,13 +622,13 @@ impl<'a> When<'a> {
cut(|i| Node::many(i, s)),
))),
));
let (i, (_, pws, _, (target, nws, _, block))) = p(i)?;
let (i, (_, pws, _, (target, nws, _, nodes))) = p(i)?;
Ok((
i,
Self {
ws: Ws(pws, nws),
target,
block,
nodes,
},
))
}
Expand All @@ -637,7 +638,7 @@ impl<'a> When<'a> {
pub struct Cond<'a> {
pub ws: Ws,
pub cond: Option<CondTest<'a>>,
pub block: Vec<Node<'a>>,
pub nodes: Vec<Node<'a>>,
}

impl<'a> Cond<'a> {
Expand All @@ -653,13 +654,13 @@ impl<'a> Cond<'a> {
cut(|i| Node::many(i, s)),
))),
));
let (i, (_, pws, _, (cond, nws, _, block))) = p(i)?;
let (i, (_, pws, _, (cond, nws, _, nodes))) = p(i)?;
Ok((
i,
Self {
ws: Ws(pws, nws),
cond,
block,
nodes,
},
))
}
Expand Down Expand Up @@ -721,7 +722,7 @@ pub struct Loop<'a> {
pub cond: Option<Expr<'a>>,
pub body: Vec<Node<'a>>,
pub ws2: Ws,
pub else_block: Vec<Node<'a>>,
pub else_nodes: Vec<Node<'a>>,
pub ws3: Ws,
}

Expand Down

0 comments on commit 0c2b8ac

Please sign in to comment.