Skip to main content

fncc_core/
lib.rs

1pub mod parser;
2pub mod codegen;
3pub mod config;
4
5pub use parser::parse;
6
7use std::path::Path;
8
9/// Main entry point: parse all .fui files under `ui_dir` and write
10/// generated Rust code into `out_file`.
11pub fn generate_all(ui_dir: &Path, out_file: &Path) {
12    let mut output = String::new();
13    output.push_str("// Generated by fncc-core. Do not edit.\n\n");
14
15    let entries = std::fs::read_dir(ui_dir).expect("failed to read ui dir");
16    for entry in entries {
17        let entry = entry.expect("failed to read entry");
18        let path = entry.path();
19        if path.extension().is_some_and(|ext| ext == "fui") {
20            let source = std::fs::read_to_string(&path)
21                .expect(&format!("failed to read {:?}", path));
22            let ast = parser::parse(&source)
23                .expect(&format!("failed to parse {:?}", path));
24            let generated = codegen::generate(&ast);
25            output.push_str(&generated);
26            output.push('\n');
27        }
28    }
29
30    std::fs::write(out_file, &output)
31        .expect("failed to write generated file");
32}