Expand errors
This commit is contained in:
parent
bd76622543
commit
7b25b593ef
@ -146,17 +146,63 @@ impl<'src> DustError<'src> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
report.push_str(&renderer.render(message).to_string());
|
report.push_str(&renderer.render(message).to_string());
|
||||||
report.push('\n');
|
report.push_str("\n\n");
|
||||||
}
|
}
|
||||||
DustError::Analysis {
|
DustError::Analysis {
|
||||||
analysis_errors,
|
analysis_errors,
|
||||||
source,
|
source,
|
||||||
} => todo!(),
|
} => {
|
||||||
|
for error in analysis_errors {
|
||||||
|
let position = error.position();
|
||||||
|
let label = error.to_string();
|
||||||
|
let message =
|
||||||
|
Level::Warning
|
||||||
|
.title("Analysis error")
|
||||||
|
.snippet(Snippet::source(source).fold(true).annotation(
|
||||||
|
Level::Warning.span(position.0..position.1).label(&label),
|
||||||
|
))
|
||||||
|
.footer(
|
||||||
|
Level::Warning
|
||||||
|
.title("This error was found without running the program."),
|
||||||
|
);
|
||||||
|
|
||||||
|
report.push_str(&renderer.render(message).to_string());
|
||||||
|
report.push_str("\n\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
DustError::Parse {
|
DustError::Parse {
|
||||||
parse_error,
|
parse_error,
|
||||||
source,
|
source,
|
||||||
} => todo!(),
|
} => {
|
||||||
DustError::Lex { lex_error, source } => todo!(),
|
if let ParseError::Lex(lex_error) = parse_error {
|
||||||
|
let lex_error_report = DustError::lex(lex_error.clone(), source).report();
|
||||||
|
|
||||||
|
report.push_str(&lex_error_report);
|
||||||
|
|
||||||
|
return report;
|
||||||
|
}
|
||||||
|
|
||||||
|
let position = parse_error.position();
|
||||||
|
let label = parse_error.to_string();
|
||||||
|
let message = Level::Error.title("Parse error").snippet(
|
||||||
|
Snippet::source(source)
|
||||||
|
.fold(true)
|
||||||
|
.annotation(Level::Error.span(position.0..position.1).label(&label)),
|
||||||
|
);
|
||||||
|
|
||||||
|
report.push_str(&renderer.render(message).to_string());
|
||||||
|
}
|
||||||
|
DustError::Lex { lex_error, source } => {
|
||||||
|
let position = lex_error.position();
|
||||||
|
let label = lex_error.to_string();
|
||||||
|
let message = Level::Error.title("Lex error").snippet(
|
||||||
|
Snippet::source(source)
|
||||||
|
.fold(true)
|
||||||
|
.annotation(Level::Error.span(position.0..position.1).label(&label)),
|
||||||
|
);
|
||||||
|
|
||||||
|
report.push_str(&renderer.render(message).to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
report
|
report
|
||||||
|
@ -297,8 +297,6 @@ impl<'src> Lexer<'src> {
|
|||||||
(Token::Colon, (self.position - 1, self.position))
|
(Token::Colon, (self.position - 1, self.position))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
self.position += 1;
|
|
||||||
|
|
||||||
return Err(LexError::UnexpectedCharacter {
|
return Err(LexError::UnexpectedCharacter {
|
||||||
actual: c,
|
actual: c,
|
||||||
position: self.position,
|
position: self.position,
|
||||||
@ -497,8 +495,8 @@ pub enum LexError {
|
|||||||
impl LexError {
|
impl LexError {
|
||||||
pub fn position(&self) -> Span {
|
pub fn position(&self) -> Span {
|
||||||
match self {
|
match self {
|
||||||
Self::ExpectedCharacter { position, .. } => (*position, *position + 1),
|
Self::ExpectedCharacter { position, .. } => (*position, *position),
|
||||||
Self::UnexpectedCharacter { position, .. } => (*position, *position + 1),
|
Self::UnexpectedCharacter { position, .. } => (*position, *position),
|
||||||
Self::UnexpectedEndOfFile { position } => (*position, *position),
|
Self::UnexpectedEndOfFile { position } => (*position, *position),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -508,19 +506,13 @@ impl Display for LexError {
|
|||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::ExpectedCharacter {
|
Self::ExpectedCharacter {
|
||||||
expected,
|
expected, actual, ..
|
||||||
actual,
|
} => write!(f, "Expected character '{expected}', found '{actual}'"),
|
||||||
position,
|
Self::UnexpectedCharacter { actual, .. } => {
|
||||||
} => write!(
|
write!(f, "Unexpected character '{actual}'")
|
||||||
f,
|
|
||||||
"Expected character '{}' at {:?}, found '{}'",
|
|
||||||
expected, position, actual
|
|
||||||
),
|
|
||||||
Self::UnexpectedCharacter { actual, position } => {
|
|
||||||
write!(f, "Unexpected character at {:?}: '{}'", position, actual)
|
|
||||||
}
|
}
|
||||||
Self::UnexpectedEndOfFile { position } => {
|
Self::UnexpectedEndOfFile { .. } => {
|
||||||
write!(f, "Unexpected end of file at {:?}", position)
|
write!(f, "Unexpected end of file")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user