Fix error.rs
This commit is contained in:
parent
ff1d4ef7bb
commit
e6a9811ee5
@ -7,24 +7,20 @@ use crate::{
|
|||||||
|
|
||||||
pub struct SchalaError {
|
pub struct SchalaError {
|
||||||
errors: Vec<Error>,
|
errors: Vec<Error>,
|
||||||
//TODO unify these sometime
|
|
||||||
formatted_parse_error: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SchalaError {
|
impl SchalaError {
|
||||||
pub(crate) fn display(&self) -> String {
|
pub(crate) fn display(&self) -> String {
|
||||||
if let Some(ref err) = self.formatted_parse_error {
|
match self.errors[0] {
|
||||||
err.clone()
|
Error::Parse(ref parse_err) => parse_err.to_string(),
|
||||||
} else {
|
Error::Standard { ref text, .. } => text.as_ref().cloned().unwrap_or_default(),
|
||||||
self.errors[0].text.as_ref().cloned().unwrap_or_default()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) fn from_type_error(err: TypeError) -> Self {
|
pub(crate) fn from_type_error(err: TypeError) -> Self {
|
||||||
Self {
|
Self {
|
||||||
formatted_parse_error: None,
|
errors: vec![Error::Standard { location: None, text: Some(err.msg), stage: Stage::Typechecking }],
|
||||||
errors: vec![Error { location: None, text: Some(err.msg), stage: Stage::Typechecking }],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,32 +28,29 @@ impl SchalaError {
|
|||||||
//TODO this could be better
|
//TODO this could be better
|
||||||
let errors = symbol_errs
|
let errors = symbol_errs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|_symbol_err| Error {
|
.map(|_symbol_err| Error::Standard {
|
||||||
location: None,
|
location: None,
|
||||||
text: Some("symbol table error".to_string()),
|
text: Some("symbol table error".to_string()),
|
||||||
stage: Stage::Symbols,
|
stage: Stage::Symbols,
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
Self { errors, formatted_parse_error: None }
|
Self { errors }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_string(text: String, stage: Stage) -> Self {
|
pub(crate) fn from_string(text: String, stage: Stage) -> Self {
|
||||||
Self { formatted_parse_error: None, errors: vec![Error { location: None, text: Some(text), stage }] }
|
Self { errors: vec![Error::Standard { location: None, text: Some(text), stage }] }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_parse_error(parse_error: ParseError, source_reference: &SourceReference) -> Self {
|
pub(crate) fn from_parse_error(parse_error: ParseError, source_reference: &SourceReference) -> Self {
|
||||||
Self {
|
let formatted_parse_error = format_parse_error(parse_error, source_reference);
|
||||||
formatted_parse_error: Some(format_parse_error(parse_error, source_reference)),
|
Self { errors: vec![Error::Parse(formatted_parse_error)] }
|
||||||
errors: vec![],
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
struct Error {
|
enum Error {
|
||||||
location: Option<Location>,
|
Standard { location: Option<Location>, text: Option<String>, stage: Stage },
|
||||||
text: Option<String>,
|
Parse(String),
|
||||||
stage: Stage,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_parse_error(error: ParseError, source_reference: &SourceReference) -> String {
|
fn format_parse_error(error: ParseError, source_reference: &SourceReference) -> String {
|
||||||
|
Loading…
Reference in New Issue
Block a user