From 0adbd20ff8b4d4f8156ee941d3d0b17e80c3a80f Mon Sep 17 00:00:00 2001
From: bnewbold <bnewbold@robocracy.org>
Date: Mon, 19 Dec 2016 09:21:35 +0000
Subject: tweaks to work with modelica-parser-lalrpop

---
 src/modelica_model.rs   | 8 ++++----
 src/transpile_js.rs     | 7 ++++++-
 src/transpile_scheme.rs | 7 ++++++-
 3 files changed, 16 insertions(+), 6 deletions(-)

(limited to 'src')

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()),
         }
     }
 }
-- 
cgit v1.2.3