Skip to content

Commit

Permalink
refine error message from parsing; bump 0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Jul 24, 2021
1 parent a788a3c commit e98860d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
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 <[email protected]>"]
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(())
}

0 comments on commit e98860d

Please sign in to comment.