Skip to content
Permalink
Browse files

[pt::Builder] add error handling

  • Loading branch information...
errordeveloper committed Jul 13, 2014
1 parent 8521da3 commit 5094694f0520876158c43f4514593a90dd6e4870
Showing with 10 additions and 8 deletions.
  1. +3 −3 macro/platformtree.rs
  2. +3 −3 platformtree/builder/mod.rs
  3. +4 −2 src/hal/lpc17xx/platformtree.rs
@@ -49,9 +49,9 @@ pub fn plugin_registrar(reg: &mut Registry) {
pub fn macro_platformtree(cx: &mut ExtCtxt, _: Span, tts: &[ast::TokenTree])
-> Box<MacResult> {
let pt = Parser::new(cx, tts).parse_platformtree();
let builder = Builder::build(cx, pt.unwrap());

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

@@ -38,11 +38,11 @@ pub struct 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());

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

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

builder
Some(builder)
}

fn walk_mutate(builder: &mut Builder, cx: &mut ExtCtxt, node: &Rc<node::Node>) {
@@ -114,8 +114,10 @@ mod test {
}
}
}", |cx, failed, pt| {
let builder = Builder::build(cx, pt);
let items = builder.emit_items(cx);
let items = Builder::build(cx, pt)
.expect(format!("Unexpected failure on {}", line!()).as_slice())
.emit_items(cx);

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

1 comment on commit 5094694

@farcaller

This comment has been minimized.

Copy link

commented on 5094694 Jul 13, 2014

r+

Please sign in to comment.
You can’t perform that action at this time.