- Split parser core and compiler core. Fix #14 - AST int type to `u32` - Updated asdl_rs.py and update_asdl.sh fix #6 - Use `ruff_python_ast::SourceLocation` for Python source location. Deleted our own Location. - Renamed ast::Located to ast::Attributed to distinguish terms for TextSize and SourceLocation - `ast::<Node>`s for TextSize located ast. `ast::located::<Node>` for Python source located ast. - And also strictly renaming `located` to refer only python location related interfaces. - `SourceLocator` to convert locations. - New `source-code` features of to disable python locations when unnecessary. - Also including fully merging https://github.com/astral-sh/RustPython/pull/4 closes #9
65 lines
1.2 KiB
Rust
65 lines
1.2 KiB
Rust
use crate::text_size::TextSize;
|
|
use std::fmt::Display;
|
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
|
pub struct BaseError<T> {
|
|
pub error: T,
|
|
pub offset: TextSize,
|
|
pub source_path: String,
|
|
}
|
|
|
|
impl<T> std::ops::Deref for BaseError<T> {
|
|
type Target = T;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.error
|
|
}
|
|
}
|
|
|
|
impl<T> std::error::Error for BaseError<T>
|
|
where
|
|
T: std::error::Error + 'static,
|
|
{
|
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
|
Some(&self.error)
|
|
}
|
|
}
|
|
|
|
impl<T> Display for BaseError<T>
|
|
where
|
|
T: std::fmt::Display,
|
|
{
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
write!(
|
|
f,
|
|
"{} at byte offset {}",
|
|
&self.error,
|
|
u32::from(self.offset)
|
|
)
|
|
}
|
|
}
|
|
|
|
impl<T> BaseError<T> {
|
|
pub fn error(self) -> T {
|
|
self.error
|
|
}
|
|
|
|
pub fn from<U>(obj: BaseError<U>) -> Self
|
|
where
|
|
U: Into<T>,
|
|
{
|
|
Self {
|
|
error: obj.error.into(),
|
|
offset: obj.offset,
|
|
source_path: obj.source_path,
|
|
}
|
|
}
|
|
|
|
pub fn into<U>(self) -> BaseError<U>
|
|
where
|
|
T: Into<U>,
|
|
{
|
|
BaseError::from(self)
|
|
}
|
|
}
|