Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refine error message from parsing #9

Merged
merged 1 commit into from
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cirru_edn"
version = "0.1.4"
version = "0.1.5"
authors = ["jiyinyiyong <jiyinyiyong@gmail.com>"]
edition = "2018"
license = "MIT"
Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ fn extract_cirru_edn(node: &Cirru) -> Result<Edn, String> {
(Ok(k), Ok(v)) => {
zs.insert(k, v);
}
(e1, e2) => return Err(format!("invalid map entry pair: {:?} {:?}", e1, e2)),
(Err(e), _) => return Err(format!("invalid map entry `{}` from `{}`", e, &ys[0])),
(Ok(k), Err(e)) => return Err(format!("invalid map entry for `{}`, got {}", k, e)),
}
}
}
Expand Down Expand Up @@ -136,7 +137,10 @@ fn extract_cirru_edn(node: &Cirru) -> Result<Edn, String> {
fields.push(s.clone());
values.push(v);
}
(e1, e2) => return Err(format!("invalid map entry: {:?} {:?}", e1, e2)),
(Cirru::Leaf(s), Err(e)) => {
return Err(format!("invalid record value for `{}`, got: {}", s, e))
}
(Cirru::List(zs), _) => return Err(format!("invalid list as record key: {:?}", zs)),
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use std::fs;
use std::io::Error;

const DEMO_INVALID: &str = r#"
{}
:a $ {}
:b $ {}
:1 E
"#;

fn main() -> Result<(), Error> {
// let large_file_path = "/Users/chen/repo/calcit-lang/runner.rs/src/cirru/calcit-core.cirru";
let large_file_path = "/Users/chen/repo/cirru/calcit-editor/calcit.cirru";
Expand All @@ -9,5 +16,7 @@ fn main() -> Result<(), Error> {

println!("{}", cirru_edn::format(&d, true).unwrap());

println!("{:?}", cirru_edn::parse(DEMO_INVALID));

Ok(())
}