Skip to content

Commit

Permalink
fix block operations error (#56)
Browse files Browse the repository at this point in the history
turns out `chumsky::error::Simple`, when displayed, doesn't take
`self.reason` into account:
https://docs.rs/chumsky/0.9.2/src/chumsky/error.rs.html#358-396. so
custom errors, which use `self.reason`, are never shown.

closes #39
  • Loading branch information
ahdinosaur committed Sep 17, 2023
1 parent e28fe9f commit 021664d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions parse/src/error.rs
@@ -1,3 +1,4 @@
use chumsky::error::SimpleReason;
use rimu_meta::ErrorReport;

use crate::compiler::CompilerError;
Expand Down Expand Up @@ -39,7 +40,11 @@ impl From<Error> for ErrorReport {
Error::Lexer(LexerError::Line(error)) => ErrorReport {
message: "Lexer: Unexpected character".into(),
span: error.span(),
labels: vec![(error.span(), format!("{}", error))],
labels: if let SimpleReason::Custom(msg) = error.reason() {
vec![(error.span(), msg.to_string())]
} else {
vec![(error.span(), format!("{}", error))]
},
notes: if let Some(e) = error.label() {
vec![format!("Label is `{}`", e)]
} else {
Expand All @@ -49,7 +54,11 @@ impl From<Error> for ErrorReport {
Error::Compiler(error) => ErrorReport {
message: "Compiler: Unexpected token".into(),
span: error.span(),
labels: vec![(error.span(), format!("{}", error))],
labels: if let SimpleReason::Custom(msg) = error.reason() {
vec![(error.span(), msg.to_string())]
} else {
vec![(error.span(), format!("{}", error))]
},
notes: if let Some(e) = error.label() {
vec![format!("Label is `{}`", e)]
} else {
Expand Down

1 comment on commit 021664d

@vercel
Copy link

@vercel vercel bot commented on 021664d Sep 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

rimu-docs – ./docs

rimu-docs-git-main-ahdinosaur.vercel.app
rimu-docs.vercel.app
rimu-docs-ahdinosaur.vercel.app

Please sign in to comment.