diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-04-02 12:40:52 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-04-10 15:57:57 +0300 |
commit | c9627df005b5344f437c9eaaa98bb5fe00c47313 (patch) | |
tree | 2ef11b14d1c6f3600fe3e806720d324b38b4d7fe /src/typeset.rs | |
parent | 85212e8ddc54c6ede71912127eaf84aac403f10d (diff) | |
download | subplot-c9627df005b5344f437c9eaaa98bb5fe00c47313.tar.gz |
feat: make typesetting issues into warnings
Sponsored-by: author
Diffstat (limited to 'src/typeset.rs')
-rw-r--r-- | src/typeset.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/typeset.rs b/src/typeset.rs index c6301e4..49b8aed 100644 --- a/src/typeset.rs +++ b/src/typeset.rs @@ -5,6 +5,7 @@ use crate::ScenarioStep; use crate::StepKind; use crate::SubplotError; use crate::{DotMarkup, GraphMarkup, PikchrMarkup, PlantumlMarkup}; +use crate::{Warning, Warnings}; use pandoc_ast::Attr; use pandoc_ast::Block; @@ -53,13 +54,13 @@ pub fn file_block(attr: &Attr, text: &str) -> Block { /// /// The snippet is given as a text string, which is parsed. It need /// not be a complete scenario, but it should consist of complete steps. -pub fn scenario_snippet(bindings: &Bindings, snippet: &str) -> Block { +pub fn scenario_snippet(bindings: &Bindings, snippet: &str, warnings: &mut Warnings) -> Block { let lines = parse_scenario_snippet(snippet); let mut steps = vec![]; let mut prevkind: Option<StepKind> = None; for line in lines { - let (this, thiskind) = step(bindings, line, prevkind); + let (this, thiskind) = step(bindings, line, prevkind, warnings); steps.push(this); prevkind = thiskind; } @@ -71,6 +72,7 @@ fn step( bindings: &Bindings, text: &str, prevkind: Option<StepKind>, + warnings: &mut Warnings, ) -> (Vec<Inline>, Option<StepKind>) { let step = ScenarioStep::new_from_str(text, prevkind); if step.is_err() { @@ -84,11 +86,9 @@ fn step( let m = match bindings.find("", &step) { Ok(m) => m, Err(e) => { - eprintln!("Could not select binding: {:?}", e); - return ( - error_msg(&format!("Could not select binding for: {}", text)), - prevkind, - ); + let w = Warning::UnknownBinding(format!("{}", e)); + warnings.push(w.clone()); + return (error_msg(&format!("{}", w)), prevkind); } }; |