Skip to content

Commit

Permalink
[pt::Builder] add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Jul 13, 2014
1 parent 8521da3 commit 5094694
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions macro/platformtree.rs
Expand Up @@ -49,9 +49,9 @@ pub fn plugin_registrar(reg: &mut Registry) {
pub fn macro_platformtree(cx: &mut ExtCtxt, _: Span, tts: &[ast::TokenTree]) pub fn macro_platformtree(cx: &mut ExtCtxt, _: Span, tts: &[ast::TokenTree])
-> Box<MacResult> { -> Box<MacResult> {
let pt = Parser::new(cx, tts).parse_platformtree(); let pt = Parser::new(cx, tts).parse_platformtree();
let builder = Builder::build(cx, pt.unwrap()); let items = Builder::build(cx, pt.unwrap())

.expect(format!("Unexpected failure on {}", line!()).as_slice())
let items = builder.emit_items(cx); .emit_items(cx);
MacItems::new(items) MacItems::new(items)
} }


Expand Down
6 changes: 3 additions & 3 deletions platformtree/builder/mod.rs
Expand Up @@ -38,11 +38,11 @@ pub struct Builder {
} }


impl Builder { impl Builder {
pub fn build(cx: &mut ExtCtxt, pt: Rc<node::PlatformTree>) -> Builder { pub fn build(cx: &mut ExtCtxt, pt: Rc<node::PlatformTree>) -> Option<Builder> {
let mut builder = Builder::new(pt.clone()); let mut builder = Builder::new(pt.clone());


if !pt.expect_subnodes(cx, ["mcu", "os", "drivers"]) { if !pt.expect_subnodes(cx, ["mcu", "os", "drivers"]) {
return builder; // TODO(farcaller): report error? return None;
} }


match pt.get_by_path("mcu") { match pt.get_by_path("mcu") {
Expand Down Expand Up @@ -73,7 +73,7 @@ impl Builder {
} }
} }


builder Some(builder)
} }


fn walk_mutate(builder: &mut Builder, cx: &mut ExtCtxt, node: &Rc<node::Node>) { fn walk_mutate(builder: &mut Builder, cx: &mut ExtCtxt, node: &Rc<node::Node>) {
Expand Down
6 changes: 4 additions & 2 deletions src/hal/lpc17xx/platformtree.rs
Expand Up @@ -114,8 +114,10 @@ mod test {
} }
} }
}", |cx, failed, pt| { }", |cx, failed, pt| {
let builder = Builder::build(cx, pt); let items = Builder::build(cx, pt)
let items = builder.emit_items(cx); .expect(format!("Unexpected failure on {}", line!()).as_slice())
.emit_items(cx);

assert!(unsafe{*failed} == false); assert!(unsafe{*failed} == false);
assert!(items.len() == 3); assert!(items.len() == 3);


Expand Down

1 comment on commit 5094694

@farcaller
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

Please sign in to comment.