Skip to content

Commit 48920a0

Browse files
authored
Merge pull request #10 from youknowone/remove-compile-error
Remove CompileError
2 parents 96eb80f + 13d6e27 commit 48920a0

File tree

3 files changed

+2
-58
lines changed

3 files changed

+2
-58
lines changed

core/src/error.rs

-56
Original file line numberDiff line numberDiff line change
@@ -58,59 +58,3 @@ impl<T> BaseError<T> {
5858
BaseError::from(self)
5959
}
6060
}
61-
62-
#[derive(Debug)]
63-
pub struct CompileError<T> {
64-
pub body: BaseError<T>,
65-
pub statement: Option<String>,
66-
}
67-
68-
impl<T: StdError + 'static> StdError for CompileError<T> {
69-
fn source(&self) -> Option<&(dyn StdError + 'static)> {
70-
self.body.source()
71-
}
72-
}
73-
74-
impl<T> std::ops::Deref for CompileError<T> {
75-
type Target = BaseError<T>;
76-
fn deref(&self) -> &Self::Target {
77-
&self.body
78-
}
79-
}
80-
81-
impl<T> std::fmt::Display for CompileError<T>
82-
where
83-
T: std::fmt::Display,
84-
{
85-
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
86-
let loc = self.location;
87-
if let Some(ref stmt) = self.statement {
88-
// visualize the error when location and statement are provided
89-
loc.fmt_with(f, &self.error)?;
90-
write!(f, "\n{stmt}{arrow:>pad$}", pad = loc.column(), arrow = "^")
91-
} else {
92-
loc.fmt_with(f, &self.error)
93-
}
94-
}
95-
}
96-
97-
impl<T> CompileError<T> {
98-
pub fn from<U>(error: BaseError<U>, source: &str) -> Self
99-
where
100-
T: From<U>,
101-
{
102-
let statement = get_statement(source, error.location);
103-
CompileError {
104-
body: error.into(),
105-
statement,
106-
}
107-
}
108-
}
109-
110-
fn get_statement(source: &str, loc: Location) -> Option<String> {
111-
if loc.column() == 0 || loc.row() == 0 {
112-
return None;
113-
}
114-
let line = source.split('\n').nth(loc.row() - 1)?.to_owned();
115-
Some(line + "\n")
116-
}

core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ pub mod marshal;
88
mod mode;
99

1010
pub use bytecode::*;
11-
pub use error::{BaseError, CompileError};
11+
pub use error::BaseError;
1212
pub use location::Location;
1313
pub use mode::Mode;

core/src/location.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl Default for Location {
1818
impl Location {
1919
pub fn fmt_with(
2020
&self,
21-
f: &mut std::fmt::Formatter,
21+
f: &mut impl std::fmt::Write,
2222
e: &impl std::fmt::Display,
2323
) -> std::fmt::Result {
2424
write!(f, "{} at line {} column {}", e, self.row(), self.column())

0 commit comments

Comments
 (0)