feat!(argus-parser): complete parser
This changes the API for `ExprBuilder`, but that is OK.
This commit is contained in:
parent
17042a2544
commit
2319668e2b
9 changed files with 545 additions and 146 deletions
31
argus-parser/examples/dump_expr.rs
Normal file
31
argus-parser/examples/dump_expr.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use std::env;
|
||||
|
||||
use argus_parser::parse_str;
|
||||
use ariadne::{sources, Color, Label, Report, ReportKind};
|
||||
|
||||
fn main() {
|
||||
let src = env::args().nth(1).expect("Expected expression");
|
||||
|
||||
match parse_str(&src) {
|
||||
Ok(expr) => println!("{:#?}", expr),
|
||||
Err(errs) => {
|
||||
errs.into_iter().for_each(|e| {
|
||||
Report::build(ReportKind::Error, src.clone(), e.span().start)
|
||||
.with_message(e.to_string())
|
||||
.with_label(
|
||||
Label::new((src.clone(), e.span().into_range()))
|
||||
.with_message(e.reason().to_string())
|
||||
.with_color(Color::Red),
|
||||
)
|
||||
.with_labels(e.contexts().map(|(label, span)| {
|
||||
Label::new((src.clone(), span.into_range()))
|
||||
.with_message(format!("while parsing this {}", label))
|
||||
.with_color(Color::Yellow)
|
||||
}))
|
||||
.finish()
|
||||
.print(sources([(src.clone(), src.clone())]))
|
||||
.unwrap()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue