dalet-rs/examples/daleth_lexer.rs

31 lines
956 B
Rust
Raw Permalink Normal View History

2024-08-08 12:25:12 +03:00
use ariadne::{Color, Label, Report, ReportKind, Source};
use chumsky::Parser;
use dalet::daleth::{format::format, lexer::full_lexer};
2024-08-08 12:25:12 +03:00
fn main() {
let src_file = "daleth.dlth";
let src = include_str!("./daleth.dlth");
let parsed = full_lexer().parse(src);
2024-08-08 12:25:12 +03:00
match parsed.into_result() {
Ok(t) => {
println!("{:#?}", t);
println!("{}", format(&t));
}
2024-08-08 12:25:12 +03:00
Err(e) => e.into_iter().for_each(|e| {
Report::build(ReportKind::Error, src_file, e.span().start)
.with_code("Lexer")
2024-08-08 12:25:12 +03:00
.with_message(e.to_string().clone())
.with_label(
Label::new((src_file, e.span().into_range()))
.with_message(e.to_string())
.with_color(Color::Red),
)
.finish()
.print((src_file, Source::from(&src)))
.unwrap()
}),
};
2024-08-08 12:25:12 +03:00
}