aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--src/modelica_model.rs8
-rw-r--r--src/transpile_js.rs7
-rw-r--r--src/transpile_scheme.rs7
4 files changed, 17 insertions, 6 deletions
diff --git a/Cargo.lock b/Cargo.lock
index afb3b0b..25a46e2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -433,6 +433,7 @@ dependencies = [
"colored 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lalrpop 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
"lalrpop-util 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
diff --git a/src/modelica_model.rs b/src/modelica_model.rs
index bcc00b1..36c5a2e 100644
--- a/src/modelica_model.rs
+++ b/src/modelica_model.rs
@@ -133,10 +133,10 @@ impl ModelicaModelExt for ModelicaModel {
// TODO: sort output equations by LHS
Ok(ModelicaModel{
name: self.name.clone(),
+ description: self.description.clone(),
components: self.components.clone(),
connections: vec![],
equations: solved,
- extends: vec![],
})
}
}
@@ -186,10 +186,10 @@ impl SimpleEquationExt for SimpleEquation {
use modelica_parser::ast::BinOperator::*;
match self.lhs {
Ident(ref s) if s == ident => Ok((*self).clone()),
- Ident(_) | Integer(_) | Float(_) =>
+ Ident(_) | Integer(_) | Float(_) | Boolean(_) | StringLiteral(_) =>
Err("SymbolicError: InternalError: expected var on LHS".to_string()),
- Der(_) | Abs(_) =>
- Err("SymbolicError: NaiveImplementation: can't simplify der() or abs()".to_string()),
+ Der(_) | MathUnaryExpr(_,_) | Sign(_) | Array(_) =>
+ Err("SymbolicError: NaiveImplementation: can't simplify".to_string()),
// TODO: create a macro for the below...
BinExpr(Multiply, ref a, ref b) if a.contains(ident) => {
SimpleEquation{
diff --git a/src/transpile_js.rs b/src/transpile_js.rs
index 7a2132f..d4ed5f7 100644
--- a/src/transpile_js.rs
+++ b/src/transpile_js.rs
@@ -49,14 +49,19 @@ impl TranspileJS for Expr {
match *self {
Integer(e) => Ok(format!("{}", e)),
Float(e) => Ok(format!("{}", e)),
+ Boolean(true) => Ok(format!("true")),
+ 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()))),
- Abs(ref e) => Ok(format!("abs({})", 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()))),
BinExpr(op, ref l, ref r) =>
Ok(format!("({} {:?} {})",
try!(l.repr_js()),
op,
try!(r.repr_js()))),
+ Array(_) => Err("Array unimplemented".to_string()),
}
}
}
diff --git a/src/transpile_scheme.rs b/src/transpile_scheme.rs
index 5c8bd66..79492d8 100644
--- a/src/transpile_scheme.rs
+++ b/src/transpile_scheme.rs
@@ -46,14 +46,19 @@ impl TranspileScheme for Expr {
match *self {
Integer(e) => Ok(format!("{}", e)),
Float(e) => Ok(format!("{}", e)),
+ Boolean(true) => Ok(format!("#t")),
+ Boolean(false) => Ok(format!("#f")),
+ StringLiteral(ref s) => Ok(format!("\"{}\"", s)),
Ident(ref e) => Ok(format!("{}", e)),
Der(ref e) => Ok(format!("(der {})", try!(e.repr_scheme()))),
- Abs(ref e) => Ok(format!("(abs {})", try!(e.repr_scheme()))),
+ Sign(ref e) => Ok(format!("(sign {})", try!(e.repr_scheme()))),
+ MathUnaryExpr(func, ref e) => Ok(format!("({:?} {})", func, try!(e.repr_scheme()))),
BinExpr(op, ref l, ref r) =>
Ok(format!("({:?} {} {})",
op,
try!(l.repr_scheme()),
try!(r.repr_scheme()))),
+ Array(_) => Err("Array unimplemented".to_string()),
}
}
}