Easy work

This commit is contained in:
greg 2018-05-09 03:04:01 -07:00
parent 6c718e5d4f
commit 30128d7d34
1 changed files with 11 additions and 3 deletions

View File

@ -16,7 +16,7 @@ pub enum Stmt {
#[derive(Debug)] #[derive(Debug)]
pub enum Expr { pub enum Expr {
Literal(Lit), Lit(Lit),
Func(Func), Func(Func),
Call { Call {
f: Func, f: Func,
@ -50,8 +50,16 @@ pub fn perform_ast_reduction(ast: &AST) -> Result<ReducedAST, String> {
} }
fn reduce_expr(expr: &Expression) -> Result<Stmt, String> { fn reduce_expr(expr: &Expression) -> Result<Stmt, String> {
Ok(Stmt::Expr(Expr::Literal(Lit::Int(0)))) use parsing::ExpressionType::*;
let ref input = expr.0;
let output_expr = match input {
&IntLiteral(ref n) => Expr::Lit(Lit::Int(*n)),
&StringLiteral(ref s) => Expr::Lit(Lit::StringLit(s.clone())),
&BoolLiteral(ref b) => Expr::Lit(Lit::Bool(*b)),
e => return Err(format!("{:?} not implemented in reduction", e))
};
Ok(Stmt::Expr(output_expr))
} }
fn reduce_decl(expr: &Declaration) -> Result<Stmt, String> { fn reduce_decl(expr: &Declaration) -> Result<Stmt, String> {
Ok(Stmt::Expr(Expr::Literal(Lit::Int(0)))) Ok(Stmt::Expr(Expr::Lit(Lit::Int(0))))
} }