mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
feat: make erg_compiler
available as a Python lib
This commit is contained in:
parent
22ccf4d870
commit
8b17c6cf6c
9 changed files with 152 additions and 4 deletions
|
@ -175,6 +175,23 @@ pub struct CompileError {
|
|||
|
||||
impl_display_and_error!(CompileError);
|
||||
|
||||
impl From<std::io::Error> for CompileError {
|
||||
fn from(value: std::io::Error) -> Self {
|
||||
Self {
|
||||
core: Box::new(ErrorCore::new(
|
||||
vec![SubMessage::only_loc(Location::Unknown)],
|
||||
value.to_string(),
|
||||
0,
|
||||
IoError,
|
||||
Location::Unknown,
|
||||
)),
|
||||
input: Input::str("".into()),
|
||||
caused_by: "".to_owned(),
|
||||
theme: THEME,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ParserRunnerError> for CompileError {
|
||||
fn from(err: ParserRunnerError) -> Self {
|
||||
Self {
|
||||
|
@ -201,6 +218,13 @@ impl From<CompileError> for ParserRunnerError {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "pylib")]
|
||||
impl std::convert::From<CompileError> for pyo3::PyErr {
|
||||
fn from(err: CompileError) -> pyo3::PyErr {
|
||||
pyo3::exceptions::PyOSError::new_err(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl ErrorDisplay for CompileError {
|
||||
fn core(&self) -> &ErrorCore {
|
||||
&self.core
|
||||
|
@ -521,6 +545,12 @@ impl std::error::Error for CompileErrors {}
|
|||
|
||||
impl_stream!(CompileErrors, CompileError);
|
||||
|
||||
impl From<std::io::Error> for CompileErrors {
|
||||
fn from(value: std::io::Error) -> Self {
|
||||
Self::from(vec![value.into()])
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ParserRunnerErrors> for CompileErrors {
|
||||
fn from(err: ParserRunnerErrors) -> Self {
|
||||
Self(err.into_iter().map(CompileError::from).collect())
|
||||
|
@ -557,6 +587,13 @@ impl From<CompileErrors> for ParseErrors {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "pylib")]
|
||||
impl std::convert::From<CompileErrors> for pyo3::PyErr {
|
||||
fn from(errs: CompileErrors) -> pyo3::PyErr {
|
||||
pyo3::exceptions::PyOSError::new_err(errs[0].to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl MultiErrorDisplay<CompileError> for CompileErrors {}
|
||||
|
||||
impl fmt::Display for CompileErrors {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue