feat: starting to get pretty error messages
This commit is contained in:
@@ -14,6 +14,7 @@ authors = ["Lucas Rosa <x@rvcas.dev>", "Kasey White <kwhitemsg@gmail.com>"]
|
||||
chumsky = "0.8.0"
|
||||
internment = "0.7.0"
|
||||
miette = "5.2.0"
|
||||
thiserror = "1.0.37"
|
||||
vec1 = "1.8.0"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -498,6 +498,12 @@ pub struct Span {
|
||||
pub end: usize,
|
||||
}
|
||||
|
||||
impl From<Span> for miette::SourceSpan {
|
||||
fn from(span: Span) -> Self {
|
||||
Self::new(span.start.into(), span.end.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Span {
|
||||
pub fn empty() -> Self {
|
||||
use chumsky::Span;
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
use std::{collections::HashSet, fmt};
|
||||
|
||||
use miette::Diagnostic;
|
||||
|
||||
use crate::{ast::Span, token::Token};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Diagnostic, thiserror::Error)]
|
||||
#[error("{}", .kind)]
|
||||
pub struct ParseError {
|
||||
kind: ErrorKind,
|
||||
span: Span,
|
||||
pub kind: ErrorKind,
|
||||
#[label]
|
||||
pub span: Span,
|
||||
#[allow(dead_code)]
|
||||
while_parsing: Option<(Span, &'static str)>,
|
||||
expected: HashSet<Pattern>,
|
||||
@@ -63,19 +67,24 @@ impl<T: Into<Pattern>> chumsky::Error<T> for ParseError {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, PartialEq, Eq, Diagnostic, thiserror::Error)]
|
||||
pub enum ErrorKind {
|
||||
#[error("unexpected end")]
|
||||
UnexpectedEnd,
|
||||
#[error("unexpected {0}")]
|
||||
#[diagnostic(help("try removing it"))]
|
||||
Unexpected(Pattern),
|
||||
#[error("unclosed {start}")]
|
||||
Unclosed {
|
||||
start: Pattern,
|
||||
before_span: Span,
|
||||
before: Option<Pattern>,
|
||||
},
|
||||
#[error("no end branch")]
|
||||
NoEndBranch,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Diagnostic, thiserror::Error)]
|
||||
pub enum Pattern {
|
||||
Char(char),
|
||||
Token(Token),
|
||||
|
||||
Reference in New Issue
Block a user