diff options
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"), } } } |