Replaced try!() macros with new ? operator.

This commit is contained in:
Nathan Vegdahl 2017-02-06 16:20:58 -08:00
parent f1e558de05
commit 746b3b0c1f
3 changed files with 16 additions and 20 deletions

View File

@ -25,7 +25,7 @@ impl<'a> DataTree<'a> {
let mut items = Vec::new(); let mut items = Vec::new();
let mut remaining_text = (0, source_text); let mut remaining_text = (0, source_text);
while let Some((item, text)) = try!(parse_node(remaining_text)) { while let Some((item, text)) = parse_node(remaining_text)? {
remaining_text = text; remaining_text = text;
items.push(item); items.push(item);
} }
@ -281,7 +281,7 @@ fn parse_node<'a>(source_text: (usize, &'a str)) -> ParseResult<'a> {
if let (Token::OpenInner, text3) = next_token(text2) { if let (Token::OpenInner, text3) = next_token(text2) {
let mut children = Vec::new(); let mut children = Vec::new();
let mut text_remaining = text3; let mut text_remaining = text3;
while let Some((node, text4)) = try!(parse_node(text_remaining)) { while let Some((node, text4)) = parse_node(text_remaining)? {
text_remaining = text4; text_remaining = text4;
children.push(node); children.push(node);
} }
@ -304,7 +304,7 @@ fn parse_node<'a>(source_text: (usize, &'a str)) -> ParseResult<'a> {
(Token::OpenInner, text2) => { (Token::OpenInner, text2) => {
let mut children = Vec::new(); let mut children = Vec::new();
let mut text_remaining = text2; let mut text_remaining = text2;
while let Some((node, text3)) = try!(parse_node(text_remaining)) { while let Some((node, text3)) = parse_node(text_remaining)? {
text_remaining = text3; text_remaining = text3;
children.push(node); children.push(node);
} }

View File

@ -49,23 +49,23 @@ pub fn parse_scene(tree: &DataTree) -> Result<Renderer, PsyParseError> {
} }
// Parse output info // Parse output info
let output_info = try!(parse_output_info(tree.iter_children_with_type("Output") let output_info = parse_output_info(tree.iter_children_with_type("Output")
.nth(0) .nth(0)
.unwrap())); .unwrap())?;
// Parse render settings // Parse render settings
let render_settings = try!(parse_render_settings(tree.iter_children_with_type("RenderSettings") let render_settings = parse_render_settings(tree.iter_children_with_type("RenderSettings")
.nth(0) .nth(0)
.unwrap())); .unwrap())?;
// Parse camera // Parse camera
let camera = try!(parse_camera(tree.iter_children_with_type("Camera").nth(0).unwrap())); let camera = parse_camera(tree.iter_children_with_type("Camera").nth(0).unwrap())?;
// Parse world // Parse world
let world = try!(parse_world(tree.iter_children_with_type("World").nth(0).unwrap())); let world = parse_world(tree.iter_children_with_type("World").nth(0).unwrap())?;
// Parse root scene assembly // Parse root scene assembly
let assembly = try!(parse_assembly(tree.iter_children_with_type("Assembly").nth(0).unwrap())); let assembly = parse_assembly(tree.iter_children_with_type("Assembly").nth(0).unwrap())?;
// Put scene together // Put scene together
let scene_name = if let &DataTree::Internal { ident, .. } = tree { let scene_name = if let &DataTree::Internal { ident, .. } = tree {

View File

@ -19,7 +19,7 @@ pub fn parse_assembly(tree: &DataTree) -> Result<Assembly, PsyParseError> {
// Sub-Assembly // Sub-Assembly
"Assembly" => { "Assembly" => {
if let &DataTree::Internal { ident: Some(ident), .. } = child { if let &DataTree::Internal { ident: Some(ident), .. } = child {
builder.add_assembly(ident, try!(parse_assembly(&child))); builder.add_assembly(ident, parse_assembly(&child)?);
} else { } else {
// TODO: error condition of some kind, because no ident // TODO: error condition of some kind, because no ident
panic!(); panic!();
@ -46,7 +46,7 @@ pub fn parse_assembly(tree: &DataTree) -> Result<Assembly, PsyParseError> {
// Get xforms // Get xforms
let mut xforms = Vec::new(); let mut xforms = Vec::new();
for (_, contents) in child.iter_leaf_children_with_type("Transform") { for (_, contents) in child.iter_leaf_children_with_type("Transform") {
xforms.push(try!(parse_matrix(contents))); xforms.push(parse_matrix(contents)?);
} }
// Add instance // Add instance
@ -62,10 +62,8 @@ pub fn parse_assembly(tree: &DataTree) -> Result<Assembly, PsyParseError> {
// MeshSurface // MeshSurface
"MeshSurface" => { "MeshSurface" => {
if let &DataTree::Internal { ident: Some(ident), .. } = child { if let &DataTree::Internal { ident: Some(ident), .. } = child {
builder.add_object( builder.add_object(ident,
ident, Object::Surface(Box::new(parse_mesh_surface(&child)?)));
Object::Surface(Box::new(try!(parse_mesh_surface(&child))))
);
} else { } else {
// TODO: error condition of some kind, because no ident // TODO: error condition of some kind, because no ident
panic!(); panic!();
@ -76,7 +74,7 @@ pub fn parse_assembly(tree: &DataTree) -> Result<Assembly, PsyParseError> {
"SphereLight" => { "SphereLight" => {
if let &DataTree::Internal { ident: Some(ident), .. } = child { if let &DataTree::Internal { ident: Some(ident), .. } = child {
builder.add_object(ident, builder.add_object(ident,
Object::Light(Box::new(try!(parse_sphere_light(&child))))); Object::Light(Box::new(parse_sphere_light(&child)?)));
} else { } else {
// TODO: error condition of some kind, because no ident // TODO: error condition of some kind, because no ident
panic!(); panic!();
@ -87,9 +85,7 @@ pub fn parse_assembly(tree: &DataTree) -> Result<Assembly, PsyParseError> {
"RectangleLight" => { "RectangleLight" => {
if let &DataTree::Internal { ident: Some(ident), .. } = child { if let &DataTree::Internal { ident: Some(ident), .. } = child {
builder.add_object(ident, builder.add_object(ident,
Object::Light(Box::new( Object::Light(Box::new(parse_rectangle_light(&child)?)));
try!(parse_rectangle_light(&child))
)));
} else { } else {
// TODO: error condition of some kind, because no ident // TODO: error condition of some kind, because no ident
panic!(); panic!();