From 3c6a6e08fdf797818bb22616dab1b8c62d6bccde Mon Sep 17 00:00:00 2001 From: Marcin Olichwiruk <21108638+olichwiruk@users.noreply.github.com> Date: Fri, 13 Dec 2024 11:04:31 +0100 Subject: [PATCH] feat: add build_from_ocafile function in facade::build module --- oca/src/facade/build.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/oca/src/facade/build.rs b/oca/src/facade/build.rs index 3f27348..acff19b 100644 --- a/oca/src/facade/build.rs +++ b/oca/src/facade/build.rs @@ -64,6 +64,35 @@ impl References for Box { } } +pub fn build_from_ocafile(ocafile: String) -> Result> { + let ast = oca_file::ocafile::parse_from_string(ocafile.clone()).map_err(|e| { + vec![Error::ValidationError(vec![ValidationError::OCAFileParse( + e, + )])] + })?; + match ast { + oca_file::ocafile::OCAAst::TransformationAst(t_ast) => { + let transformation = transformation_file::build::from_ast(&t_ast).map_err(|e| { + e.iter() + .map(|e| ValidationError::TransformationBuild(e.clone())) + .collect::>() + }) + .map_err(|errs| vec![Error::ValidationError(errs)])?; + Ok(BundleElement::Transformation(transformation)) + }, + oca_file::ocafile::OCAAst::SemanticsAst(ast) => { + let oca_build = oca_bundle_semantics::build::from_ast(None, &ast).map_err(|e| { + e.iter() + .map(|e| ValidationError::OCABundleBuild(e.clone())) + .collect::>() + }) + .map_err(|errs| vec![Error::ValidationError(errs)])?; + + Ok(BundleElement::Structural(oca_build.oca_bundle)) + } + } +} + impl Facade { #[cfg(not(feature = "local-references"))] pub fn validate_ocafile(&self, ocafile: String) -> Result> {