From 6768cebc48f78c657bc73b6e81fa499e99a52cdd Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 11 May 2018 01:07:18 -0700 Subject: [PATCH] Literals --- schala-lang/src/eval.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 332b562..fdabd4e 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -321,7 +321,17 @@ impl<'a> State<'a> { impl Expr { fn to_repl(&self) -> String { - format!("{:?}", self) + use self::Lit::*; + match self { + Expr::Lit(ref l) => match l { + Nat(n) => format!("{}", n), + Int(i) => format!("{}", i), + Float(f) => format!("{}", f), + Bool(b) => format!("{}", b), + StringLit(s) => format!("{}", s), + }, + _ => format!("{:?}", self), + } } } @@ -343,7 +353,22 @@ impl<'a> State<'a> { acc } - fn statement(&mut self, stmt: ::ast_reducing::Stmt) -> Result, String> { - Ok(Some(Expr::Lit(Lit::Int(1)))) + fn statement(&mut self, stmt: Stmt) -> Result, String> { + match stmt { + Stmt::Binding { .. } => { + //TODO mutate some state here + Ok(None) + }, + Stmt::Expr(expr) => self.expression(expr), + } + } + + fn expression(&mut self, expr: Expr) -> Result, String> { + use self::Expr::*; + use self::Lit::*; + match expr { + literal @ Lit(_) => Ok(Some(literal)), + _ => Err(format!("NOT IMPLEMENTED YET")) + } } }