aboutsummaryrefslogtreecommitdiffstats
path: root/src/transpile_js.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/transpile_js.rs')
-rw-r--r--src/transpile_js.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/transpile_js.rs b/src/transpile_js.rs
index 4150b12..219364a 100644
--- a/src/transpile_js.rs
+++ b/src/transpile_js.rs
@@ -5,23 +5,23 @@ use self::modelica_parser::*;
use errors::Result;
pub trait TranspileJS {
- fn repr_js(&self) -> Result<String>;
+ fn transpile_js(&self) -> Result<String>;
}
impl TranspileJS for ModelicaModel {
- fn repr_js(&self) -> Result<String> {
+ fn transpile_js(&self) -> Result<String> {
let mut constants = vec![];
for (c, e) in self.get_constant_vars() {
if let Some(v) = e {
- constants.push(format!("var {} = {};", c, try!(v.repr_js())));
+ constants.push(format!("var {} = {};", c, try!(v.transpile_js())));
}
}
let mut binds = vec![];
let mut outputs = vec![];
for eq in self.equations.iter() {
if let Expr::Ident(ref symb) = eq.lhs {
- binds.push(format!("var {} = {};", symb, try!(eq.rhs.repr_js())));
+ binds.push(format!("var {} = {};", symb, try!(eq.rhs.transpile_js())));
outputs.push(symb.to_string());
} else {
bail!("Expected an identifier on LHS (in this partial implementation)")
@@ -42,7 +42,7 @@ impl TranspileJS for ModelicaModel {
}
impl TranspileJS for Expr {
- fn repr_js(&self) -> Result<String> {
+ fn transpile_js(&self) -> Result<String> {
use modelica_parser::Expr::*;
match *self {
Integer(e) => Ok(format!("{}", e)),
@@ -51,11 +51,11 @@ impl TranspileJS for Expr {
Boolean(false) => Ok(format!("false")),
StringLiteral(ref s) => Ok(format!("\"{}\"", s)),
Ident(ref e) => Ok(format!("{}", e)),
- Der(ref e) => Ok(format!("der({})", try!(e.repr_js()))),
- Sign(ref e) => Ok(format!("sign({})", try!(e.repr_js()))),
- MathUnaryExpr(func, ref e) => Ok(format!("{:?}({})", func, try!(e.repr_js()))),
+ Der(ref e) => Ok(format!("der({})", try!(e.transpile_js()))),
+ Sign(ref e) => Ok(format!("sign({})", try!(e.transpile_js()))),
+ MathUnaryExpr(func, ref e) => Ok(format!("{:?}({})", func, try!(e.transpile_js()))),
BinExpr(op, ref l, ref r) => {
- Ok(format!("({} {:?} {})", try!(l.repr_js()), op, try!(r.repr_js())))
+ Ok(format!("({} {:?} {})", try!(l.transpile_js()), op, try!(r.transpile_js())))
}
Array(_) => unimplemented!(),
}