pub use ast_to_hir_fold::Fold;
#[doc(inline)]
pub use branch_resolution::BranchResolver;
use crate::ast::Ast;
use crate::ast_lowering::ast_to_hir_fold::{DeclarationHandler, Global};
use crate::ast_lowering::error::Error;
use crate::ir::hir::Hir;
use crate::SourceMap;
#[cfg(test)]
mod test;
#[macro_use]
pub mod name_resolution;
pub mod ast_to_hir_fold;
mod branch_resolution;
pub mod error;
impl Ast {
pub fn lower(mut self) -> Result<Hir, (Vec<Error>, Self)> {
self.try_fold_to_hir().map_err(|err| (err, self))
}
pub fn lower_with_decl_handler(
mut self,
declaration_handler: &mut impl DeclarationHandler,
) -> Result<Hir, (Vec<Error>, Self)> {
self.try_fold_to_hir_with_decl_handler(declaration_handler)
.map_err(|err| (err, self))
}
pub fn lower_and_print_errors(
self,
source_map: &SourceMap,
translate_lines: bool,
) -> Option<Hir> {
self.lower()
.map_err(|(errors, ast)| {
errors
.into_iter()
.for_each(|err| err.print(source_map, &ast, translate_lines))
})
.ok()
}
pub fn lower_and_print_errors_with_var_decl_handle(
self,
source_map: &SourceMap,
translate_lines: bool,
declaration_handler: &mut impl DeclarationHandler,
) -> Option<Hir> {
self.lower_with_decl_handler(declaration_handler)
.map_err(|(errors, ast)| {
errors
.into_iter()
.for_each(|err| err.print(source_map, &ast, translate_lines))
})
.ok()
}
fn try_fold_to_hir(&mut self) -> Result<Hir, Vec<Error>> {
Ok(Global::new(self, &mut ()).fold()?.fold()?.fold()?)
}
fn try_fold_to_hir_with_decl_handler(
&mut self,
declaration_handler: &mut impl DeclarationHandler,
) -> Result<Hir, Vec<Error>> {
Ok(Global::new(self, declaration_handler)
.fold()?
.fold()?
.fold()?)
}
}