Skip to content

Commit

Permalink
Add parsers for break, continue and return expressions. (#21)
Browse files Browse the repository at this point in the history
Added parsers for break, continue and return
  • Loading branch information
gregkatz authored and dtolnay committed Oct 1, 2016
1 parent de20622 commit fd6935d
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,12 @@ pub mod parsing {
expr_block
// TODO: Path
// TODO: AddrOf
// TODO: Break
// TODO: Continue
// TODO: Ret
|
expr_break
|
expr_continue
|
expr_ret
// TODO: Mac
// TODO: Struct
// TODO: Repeat
Expand Down Expand Up @@ -570,6 +573,30 @@ pub mod parsing {
))
));

named!(expr_continue -> Expr, do_parse!(
keyword!("continue") >>
lbl: option!(label) >>
(Expr::Continue(
lbl,
))
));

named!(expr_break -> Expr, do_parse!(
keyword!("break") >>
lbl: option!(label) >>
(Expr::Break(
lbl,
))
));

named!(expr_ret -> Expr, do_parse!(
keyword!("return") >>
ret_value: option!(expr) >>
(Expr::Ret(
ret_value.map(Box::new),
))
));

named!(expr_block -> Expr, map!(block, |b| Expr::Block(Box::new(b))));

named!(block -> Block, do_parse!(
Expand Down

0 comments on commit fd6935d

Please sign in to comment.