Print file path in error message
This commit is contained in:
parent
2724d2aefe
commit
747e6db8a5
2 changed files with 6 additions and 3 deletions
|
|
@ -15,7 +15,7 @@ pub struct Opt {
|
|||
fn main() -> anyhow::Result<()> {
|
||||
let opt = Opt::from_args();
|
||||
let content = fs::read_to_string(&opt.file)?;
|
||||
let commands = parse::parse(&content)?;
|
||||
let commands = parse::parse(&opt.file, &content)?;
|
||||
println!("{:#?}", commands);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use std::path::Path;
|
||||
use std::result;
|
||||
|
||||
use chrono::NaiveDate;
|
||||
|
|
@ -215,12 +216,14 @@ fn parse_command(p: Pair<Rule>) -> Result<Command> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse(input: &str) -> Result<Vec<Command>> {
|
||||
pub fn parse(path: &Path, input: &str) -> Result<Vec<Command>> {
|
||||
let path = path.to_string_lossy();
|
||||
let mut pairs = TodayfileParser::parse(Rule::file, input)?;
|
||||
let file = pairs.next().unwrap();
|
||||
file.into_inner()
|
||||
// For some reason, the EOI in `file` always gets captured
|
||||
.take_while(|p| p.as_rule() == Rule::command)
|
||||
.map(parse_command)
|
||||
.collect()
|
||||
.collect::<Result<_>>()
|
||||
.map_err(|e| e.with_path(&path))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue