use std::path::PathBuf;
use crate::analysis::AnalyzedGrammar;
use crate::lowering::{self, StateTable};
pub mod c;
pub mod common;
pub mod csharp;
pub mod go;
pub mod java;
pub mod python;
pub mod rust;
pub mod typescript;
#[derive(Clone, Debug)]
pub struct EmittedFile {
pub path: PathBuf,
pub contents: String,
}
pub type EmitFn = fn(&StateTable) -> Vec<EmittedFile>;
pub struct Backend {
pub name: &'static str,
pub emit: EmitFn,
}
pub const BACKENDS: &[Backend] = &[
Backend {
name: "rust",
emit: rust::emit,
},
Backend {
name: "python",
emit: python::emit,
},
Backend {
name: "typescript",
emit: typescript::emit,
},
Backend {
name: "go",
emit: go::emit,
},
Backend {
name: "java",
emit: java::emit,
},
Backend {
name: "csharp",
emit: csharp::emit,
},
Backend {
name: "c",
emit: c::emit,
},
];
pub fn find(name: &str) -> Option<&'static Backend> {
let n = name.to_ascii_lowercase();
BACKENDS.iter().find(|b| b.name == n)
}
pub fn emit(backend: &Backend, ag: &AnalyzedGrammar) -> Vec<EmittedFile> {
let st = lowering::lower(ag);
(backend.emit)(&st)
}