1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use crate::{builtins::PyBaseExceptionRef, convert::ToPyException, VirtualMachine};

#[cfg(feature = "rustpython-codegen")]
pub use rustpython_codegen::CompileOpts;
#[cfg(feature = "rustpython-compiler")]
pub use rustpython_compiler::*;

#[cfg(not(feature = "rustpython-compiler"))]
pub use rustpython_compiler_core as core;

#[cfg(all(not(feature = "rustpython-compiler"), feature = "rustpython-parser"))]
pub use rustpython_parser_core as parser;

#[cfg(not(feature = "rustpython-compiler"))]
mod error {
    #[cfg(all(feature = "rustpython-parser", feature = "rustpython-codegen"))]
    panic!("Use --features=compiler to enable both parser and codegen");

    #[derive(Debug, thiserror::Error)]
    pub enum CompileErrorType {
        #[cfg(feature = "rustpython-codegen")]
        #[error(transparent)]
        Codegen(#[from] rustpython_codegen::error::CodegenErrorType),
        #[cfg(feature = "rustpython-parser")]
        #[error(transparent)]
        Parse(#[from] rustpython_parser::error::ParseErrorType),
    }

    pub type CompileError = rustpython_compiler_core::CompileError<CompileErrorType>;
}
#[cfg(not(feature = "rustpython-compiler"))]
pub use error::{CompileError, CompileErrorType};

impl ToPyException for (CompileError, Option<&str>) {
    fn to_pyexception(&self, vm: &VirtualMachine) -> PyBaseExceptionRef {
        vm.new_syntax_error(&self.0, self.1)
    }
}