mirror of https://git.sr.ht/~garritfra/sabre
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
671 B
31 lines
671 B
use crate::generator::Generator; |
|
use crate::parser::node_type::*; |
|
|
|
pub struct JsGenerator; |
|
|
|
impl Generator for JsGenerator { |
|
fn generate(prog: Program) -> String { |
|
let mut code = prog |
|
.func |
|
.into_iter() |
|
.map(|f| generate_function(f)) |
|
.collect(); |
|
|
|
code += "main()"; |
|
|
|
return code; |
|
} |
|
} |
|
|
|
fn generate_function(func: Function) -> String { |
|
let arguments: String = func |
|
.arguments |
|
.into_iter() |
|
.map(|arg: Variable| format!("{},", arg.name)) |
|
.collect(); |
|
let mut raw = format!("function {N}({A}) ", N = func.name, A = arguments); |
|
|
|
raw += "{}\n"; |
|
|
|
raw |
|
}
|
|
|