Skip to content

Commit

Permalink
Merge pull request #79 from epage/drop
Browse files Browse the repository at this point in the history
refactor(chumsky): Remove extraneous dep
  • Loading branch information
epage authored Nov 1, 2024
2 parents e29f183 + 1fa673d commit f88d915
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 65 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/chumsky-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ name = "chumsky-app"
path = "app.rs"

[dependencies]
ariadne = "0.4.1"
chumsky = "0.9.3"
66 changes: 3 additions & 63 deletions examples/chumsky-app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod parser;

use std::{env, fs};

use ariadne::{Color, Fmt, Label, Report, ReportKind, Source};
use chumsky::Parser;

fn main() {
Expand All @@ -22,66 +21,7 @@ fn main() {
{
std::hint::black_box(json);
}
errs.into_iter().for_each(|e| {
let msg = if let chumsky::error::SimpleReason::Custom(msg) = e.reason() {
msg.clone()
} else {
format!(
"{}{}, expected {}",
if e.found().is_some() {
"Unexpected token"
} else {
"Unexpected end of input"
},
if let Some(label) = e.label() {
format!(" while parsing {}", label)
} else {
String::new()
},
if e.expected().len() == 0 {
"something else".to_string()
} else {
e.expected()
.map(|expected| match expected {
Some(expected) => expected.to_string(),
None => "end of input".to_string(),
})
.collect::<Vec<_>>()
.join(", ")
},
)
};

let report = Report::build(ReportKind::Error, (), e.span().start)
.with_code(3)
.with_message(msg)
.with_label(
Label::new(e.span())
.with_message(match e.reason() {
chumsky::error::SimpleReason::Custom(msg) => msg.clone(),
_ => format!(
"Unexpected {}",
e.found()
.map(|c| format!("token {}", c.fg(Color::Red)))
.unwrap_or_else(|| "end of input".to_string())
),
})
.with_color(Color::Red),
);

let report = match e.reason() {
chumsky::error::SimpleReason::Unclosed { span, delimiter } => report.with_label(
Label::new(span.clone())
.with_message(format!(
"Unclosed delimiter {}",
delimiter.fg(Color::Yellow)
))
.with_color(Color::Yellow),
),
chumsky::error::SimpleReason::Unexpected => report,
chumsky::error::SimpleReason::Custom(_) => report,
};

report.finish().print(Source::from(&src)).unwrap();
});
for err in errs {
eprintln!("{err}");
}
}

0 comments on commit f88d915

Please sign in to comment.