rustpython_vm/
compiler.rs1#[cfg(feature = "rustpython-codegen")]
2pub use rustpython_codegen::CompileOpts;
3#[cfg(feature = "rustpython-compiler")]
4pub use rustpython_compiler::*;
5#[cfg(not(feature = "rustpython-compiler"))]
6pub use rustpython_compiler_core::Mode;
7
8#[cfg(not(feature = "rustpython-compiler"))]
9pub use rustpython_compiler_core as core;
10
11#[cfg(not(feature = "rustpython-compiler"))]
12pub use rustpython_parser_core as parser;
13
14#[cfg(not(feature = "rustpython-compiler"))]
15mod error {
16 #[cfg(all(feature = "rustpython-parser", feature = "rustpython-codegen"))]
17 panic!("Use --features=compiler to enable both parser and codegen");
18
19 #[derive(Debug, thiserror::Error)]
20 pub enum CompileErrorType {
21 #[cfg(feature = "rustpython-codegen")]
22 #[error(transparent)]
23 Codegen(#[from] rustpython_codegen::error::CodegenErrorType),
24 #[cfg(feature = "rustpython-parser")]
25 #[error(transparent)]
26 Parse(#[from] rustpython_parser::error::ParseErrorType),
27 }
28
29 pub type CompileError = rustpython_parser_core::source_code::LocatedError<CompileErrorType>;
30}
31#[cfg(not(feature = "rustpython-compiler"))]
32pub use error::{CompileError, CompileErrorType};
33
34#[cfg(any(feature = "rustpython-parser", feature = "rustpython-codegen"))]
35impl crate::convert::ToPyException for (CompileError, Option<&str>) {
36 fn to_pyexception(&self, vm: &crate::VirtualMachine) -> crate::builtins::PyBaseExceptionRef {
37 vm.new_syntax_error(&self.0, self.1)
38 }
39}