swamp_script/
lib.rs

1/*
2 * Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/swamp/script
3 * Licensed under the MIT License. See LICENSE in the project root for license information.
4 */
5use swamp_script_analyzer::prelude::Error;
6use swamp_script_analyzer::prelude::Program;
7use swamp_script_dep_loader::DepLoaderError;
8use swamp_script_source_map::SourceMap;
9pub mod prelude;
10use swamp_script_eval_loader::EvalLoaderError;
11use swamp_script_semantic::SemanticError;
12
13#[derive(Debug)]
14pub enum ScriptError {
15    Error(Error),
16    DepLoaderError(DepLoaderError),
17}
18
19impl From<Error> for ScriptError {
20    fn from(err: Error) -> Self {
21        Self::Error(err)
22    }
23}
24
25impl From<DepLoaderError> for ScriptError {
26    fn from(err: DepLoaderError) -> Self {
27        Self::DepLoaderError(err)
28    }
29}
30
31#[derive(Debug)]
32pub enum LoaderErr {
33    CouldNotLoad,
34    SemanticError(SemanticError),
35    AnalyzerError(Error),
36}
37
38impl From<Error> for LoaderErr {
39    fn from(value: Error) -> Self {
40        LoaderErr::AnalyzerError(value)
41    }
42}
43
44pub fn compile_and_analyze(
45    module_path: &[String],
46    resolved_program: &mut Program,
47    source_map: &mut SourceMap,
48) -> Result<(), EvalLoaderError> {
49    swamp_script_eval_loader::compile_and_analyze_all_modules(
50        module_path,
51        resolved_program,
52        source_map,
53    )
54}