diff options
author | bnewbold <bnewbold@robocracy.org> | 2016-12-27 20:58:51 +0100 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2016-12-27 20:58:51 +0100 |
commit | 4e2937fc614538fd73363a41667c9472fb6ff5f3 (patch) | |
tree | 7eb354f663d6ee89549e657174ac9e257dd02095 /src/transpile_js.rs | |
parent | d4e49815052a24e050aaf5a59214bab18bf1ede1 (diff) | |
download | modelthing-4e2937fc614538fd73363a41667c9472fb6ff5f3.tar.gz modelthing-4e2937fc614538fd73363a41667c9472fb6ff5f3.zip |
refactor error handling with error_chain
Diffstat (limited to 'src/transpile_js.rs')
-rw-r--r-- | src/transpile_js.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/transpile_js.rs b/src/transpile_js.rs index 5ca16e6..269e900 100644 --- a/src/transpile_js.rs +++ b/src/transpile_js.rs @@ -2,14 +2,15 @@ extern crate modelica_parser; use self::modelica_parser::*; +use errors::Result; pub trait TranspileJS { - fn repr_js(&self) -> Result<String, String>; + fn repr_js(&self) -> Result<String>; } impl TranspileJS for ModelicaModel { - fn repr_js(&self) -> Result<String, String> { + fn repr_js(&self) -> Result<String> { let mut constants = vec![]; for (c, e) in self.get_constant_vars() { if let Some(v) = e { @@ -23,8 +24,7 @@ impl TranspileJS for ModelicaModel { binds.push(format!("var {} = {};", symb, try!(eq.rhs.repr_js()))); outputs.push(symb.to_string()); } else { - return Err("Expected an identifier on LHS (in this partial implementation)" - .to_string()); + bail!("Expected an identifier on LHS (in this partial implementation)") } } let args: Vec<String> = self.get_free_vars().iter().map(|s| s.clone()).collect(); @@ -42,7 +42,7 @@ impl TranspileJS for ModelicaModel { } impl TranspileJS for Expr { - fn repr_js(&self) -> Result<String, String> { + fn repr_js(&self) -> Result<String> { use modelica_parser::Expr::*; match *self { Integer(e) => Ok(format!("{}", e)), @@ -57,7 +57,7 @@ impl TranspileJS for Expr { BinExpr(op, ref l, ref r) => { Ok(format!("({} {:?} {})", try!(l.repr_js()), op, try!(r.repr_js()))) } - Array(_) => Err("Array unimplemented".to_string()), + Array(_) => bail!("Array unimplemented"), } } } |