diff --git a/parser/src/ast.rs b/parser/src/ast.rs index 5028788..7478c7a 100644 --- a/parser/src/ast.rs +++ b/parser/src/ast.rs @@ -64,7 +64,7 @@ pub enum Statement { // let/const/var x = ... VarDecl { - kind: VarKind, + mutable: bool, name: String, init: Option, type_: Option, @@ -90,7 +90,7 @@ pub enum Statement { // for (...) stmt For { - init: (VarKind, String, Option), + init: (bool, String, Option), condition: Option, update: Option>, body: Box, @@ -115,10 +115,3 @@ pub enum Expression { postfixes: Vec, }, } - -#[derive(Debug, Clone, Serialize)] -pub enum VarKind { - Let, - Const, - Var, -} diff --git a/parser/src/lib.rs b/parser/src/lib.rs index f71ad03..e9e15b8 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -188,7 +188,7 @@ impl From> for Statement { let init = inner.next().map(Expression::from); Statement::VarDecl { - kind: VarKind::Var, + mutable: false, name: name.as_str().to_string(), init, type_, @@ -243,19 +243,12 @@ impl From> for Statement { Rule::var_decl => { let mut it = p.into_inner(); - let kind = match it.next().unwrap().as_str() { - "let" => VarKind::Let, - "const" => VarKind::Const, - "var" => VarKind::Var, - _ => unreachable!(), - }; - let name = it.next().unwrap().as_str().to_string(); let init_expr = it .next() .map(|e| Expression::from(e.into_inner().next().unwrap())); - (kind, name, init_expr) + (false, name, init_expr) } _ => unimplemented!( "For loop init parsing not implemented yet: {:?}", diff --git a/src/codegen.rs b/src/codegen.rs index 6df61fc..04dcfce 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -1,4 +1,4 @@ -use parser::ast::{BinaryOp, Block, Expression, Postfix, Statement, TopLevel, TypeExpr, VarKind}; +use parser::ast::{BinaryOp, Block, Expression, Postfix, Statement, TopLevel, TypeExpr}; pub struct RustCodegen { output: String, @@ -129,15 +129,12 @@ impl RustCodegen { } Statement::VarDecl { - kind, + mutable, name, init, type_, } => { - let mutability = match kind { - VarKind::Var => "mut ", - _ => "", - }; + let mutability = if *mutable { "mut " } else { "" }; let ty = type_ .as_ref()