diff options
Diffstat (limited to 'modelica-parser-lalrpop/src/ast.rs')
-rw-r--r-- | modelica-parser-lalrpop/src/ast.rs | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/modelica-parser-lalrpop/src/ast.rs b/modelica-parser-lalrpop/src/ast.rs index 467c518..9a9f02d 100644 --- a/modelica-parser-lalrpop/src/ast.rs +++ b/modelica-parser-lalrpop/src/ast.rs @@ -69,11 +69,31 @@ pub enum Expr { Float(f64), Ident(String), Der(Box<Expr>), - Abs(Box<Expr>), + Sign(Box<Expr>), + MathUnaryExpr(MathUnaryFunc, Box<Expr>), BinExpr(BinOperator, Box<Expr>, Box<Expr>), } #[derive(Copy, Clone, PartialEq)] +pub enum MathUnaryFunc { + Abs, + Sqrt, + Sin, + Cos, + Tan, + Asin, + Acos, + Atan, + // TODO: atan2(x,y) + Sinh, + Cosh, + Tanh, + Exp, + Log, + Log10, +} + +#[derive(Copy, Clone, PartialEq)] pub enum BinOperator { Multiply, Divide, @@ -165,7 +185,8 @@ impl Expr { match *self { Integer(_) | Float(_) => vec![], Ident(ref s) => vec![s.clone()], - Der(ref e) | Abs(ref e) => e.identifiers(), + Der(ref e) | Sign(ref e) => e.identifiers(), + MathUnaryExpr(_, ref e) => e.identifiers(), BinExpr(_, ref e1, ref e2) => { union_strings(&e1.identifiers(), &e2.identifiers()) }, @@ -261,7 +282,8 @@ impl Debug for Expr { Float(e) => write!(fmt, "{}", e), Ident(ref e) => write!(fmt, "{}", e), Der(ref e) => write!(fmt, "der({:?})", e), - Abs(ref e) => write!(fmt, "abs({:?})", e), + Sign(ref e) => write!(fmt, "sign({:?})", e), + MathUnaryExpr(func, ref e) => write!(fmt, "{:?}({:?})", func, e), BinExpr(op, ref l, ref r) => write!(fmt, "({:?} {:?} {:?})", l, op, r), } } @@ -278,3 +300,25 @@ impl Debug for BinOperator { } } } + +impl Debug for MathUnaryFunc { + fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> { + use self::MathUnaryFunc::*; + match *self { + Abs => write!(fmt, "abs"), + Sqrt => write!(fmt, "sqrt"), + Sin => write!(fmt, "sin"), + Cos => write!(fmt, "cos"), + Tan => write!(fmt, "tan"), + Asin => write!(fmt, "asin"), + Acos => write!(fmt, "acos"), + Atan => write!(fmt, "atan"), + Sinh => write!(fmt, "sinh"), + Cosh => write!(fmt, "cosh"), + Tanh => write!(fmt, "tanh"), + Exp => write!(fmt, "exp"), + Log => write!(fmt, "log"), + Log10 => write!(fmt, "log10"), + } + } +} |