extern crate beam_file;
extern crate eetf;
extern crate num;
pub mod ast;
pub mod error;
pub mod format;
pub mod result;
use std::path::Path;
#[derive(Debug)]
#[allow(clippy::upper_case_acronyms)]
pub struct AST {
pub module: ast::ModuleDecl,
}
impl AST {
pub fn from_beam_file<P: AsRef<Path>>(beam_file: P) -> result::FromBeamResult<Self> {
let code = format::raw_abstract_v1::AbstractCode::from_beam_file(beam_file)?;
let forms = code.to_forms()?;
Ok(AST {
module: ast::ModuleDecl { forms },
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works_for_new_beam() {
let ast = AST::from_beam_file("src/testdata/test2.beam")
.map_err(|err| {
println!("[ERROR] {}", err);
"Failed"
})
.unwrap();
assert_eq!(format!("{:?}", ast), "AST { module: ModuleDecl { forms: [File(FileAttr { line: 1, original_file: \"test2.erl\", original_line: 1 }), Module(ModuleAttr { line: 1, name: \"test2\" }), Eof(Eof { line: 2 })] } }");
}
#[test]
fn it_works_for_old_beam() {
AST::from_beam_file("src/testdata/test.beam")
.map_err(|err| {
println!("[ERROR] {}", err);
"Failed"
})
.unwrap();
}
}