reic 0.1.0

A compiler that just works
Documentation
/// For project level generation

use std::{fs::read_to_string, path::Path};
use log::info;

/// Given a list of filepaths, reads them to strings and wraps them around in `mod filename {}`
pub fn open_project(filepaths: &[String]) -> String {
    // Read the file
    let mut files = vec![];

    for i in 1..filepaths.len() {
        let res = read_to_string(&filepaths[i]).expect("cannot read file");
        // get filename from path
        let path = &filepaths[i];
        let path = Path::new(&path);
        let mut filename = path.file_stem().unwrap().to_str().unwrap().to_owned();

        // for each file string, attach mod filename { to the start and append } to the end
        // NOTE: doesnt work for subdirectories, yet. For subdirs, maybe just prei
        // I guess we can also take the full path into account\

        info!("Filename: {filename}");

        // Is this somehow not working? So its treating hello_world as whitespace
        // and not skipping it either even if it was?
        // it should be an identifier
        filename = format!("mod {filename} {{\n") + &res;
        let updated_file = filename + "\n}";

        info!("Updated Mod:\n{updated_file}");

        files.push(updated_file);
    }

    // Combine file strings
    let res = combine_files(&files);

    res
}

pub fn open_project_file(filepath: &str) -> String {
    let x = [filepath.to_string()];
    open_project(&x)
}

/// Combine files into a single output file. NOTE: without prei, theres no distinction between `main()`. So there must be a file called main.rei to make an executable as preproc is done for the root{} module. Otherwise just compiles as a static library
pub fn combine_files(files: &Vec<String>) -> String {
    files.iter().fold("".to_owned(), |acc, next| acc + next)
}