diff --git a/fmt/src/gen/mod.rs b/fmt/src/gen/mod.rs index 05f8760..44b276f 100644 --- a/fmt/src/gen/mod.rs +++ b/fmt/src/gen/mod.rs @@ -1,7 +1,7 @@ use std::borrow::BorrowMut; use dprint_core::formatting::PrintItems; -use whistle_ast::{IdentType, IdentTyped, ProgramStmt, Stmt}; +use whistle_ast::*; use crate::{config::Configuration, ParsedSource}; @@ -22,9 +22,9 @@ pub fn generate(parsed_source: &ParsedSource, _config: &Configuration) -> PrintI items.borrow_mut(), export, inline, - ident, - params, - ret_type, + ident.clone(), + params.to_vec(), + &mut ret_type.clone(), stmt, ), _ => panic!("Unimplemented"), @@ -34,12 +34,52 @@ pub fn generate(parsed_source: &ParsedSource, _config: &Configuration) -> PrintI } pub fn gen_fn( - _items: &mut PrintItems, - _export: &bool, + items: &mut PrintItems, + export: &bool, _inline: &bool, - _ident: &str, - _params: &Vec, - _ret_type: &IdentType, - _stmts: &Vec, + ident: String, + params: Vec, + ret_type: &mut IdentType, + stmts: &Vec, ) { + if *export { + items.push_str("export "); + } + items.push_str("fn "); + items.push_string(ident); + items.push_str("("); + for (i, param) in params.iter().enumerate() { + if i > 0 { + items.push_str(", "); + } + items.push_string(param.ident.clone()); + items.push_str(": "); + match param.type_ident.to_type() { + Type::Ident(ident) => { + items.push_string(ident); + } + _ => panic!("Unimplemented"), + } + } + items.push_str(")"); + items.push_str(": "); + match ret_type.borrow_mut().to_type() { + Type::Ident(ident) => { + items.push_string(ident); + } + _ => panic!("Unimplemented"), + } + // items.push_str(&ret_type.to_type().type_id()); + + items.push_str(" {\n"); + for stmt in stmts { + gen_stmt(items, stmt); + } + items.push_str("}\n"); +} + +pub fn gen_stmt(_items: &mut PrintItems, stmt: &Stmt) { + match stmt { + _ => panic!("Unimplemented"), + } }