From: Ian Jackson Date: Sat, 7 Aug 2021 19:55:02 +0000 (+0100) Subject: ini: wip new module X-Git-Tag: hippotat/1.0.0~260 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=e03d4afd6604b037ebe7551d4c9f8514973ba369;p=hippotat.git ini: wip new module Signed-off-by: Ian Jackson --- diff --git a/src/ini.rs b/src/ini.rs index 67817f5..107f4aa 100644 --- a/src/ini.rs +++ b/src/ini.rs @@ -50,7 +50,7 @@ impl Display for Loc { #[throws(AE)] pub fn read(parsed: &mut Parsed, file: &mut dyn BufRead, path_for_loc: &Path) { let path: Arc = path_for_loc.to_owned().into(); - let section: Option<&mut Section> = None; + let mut section: Option<&mut Section> = None; for (lno, line) in file.lines().enumerate() { let line = line.context("read")?; let line = line.trim(); @@ -58,10 +58,10 @@ pub fn read(parsed: &mut Parsed, file: &mut dyn BufRead, path_for_loc: &Path) { if line.is_empty() { continue } if regex_is_match!(r#"^ [;#] "#x, line) { continue } - let mut loc = Loc { + let loc = Loc { lno, file: path.clone(), - section: section.as_ref().map(|s| s.loc.section.unwrap().clone()), + section: section.as_ref().map(|s| s.loc.section.as_ref().unwrap().clone()), }; (|| Ok::<(),AE>({ @@ -73,7 +73,7 @@ pub fn read(parsed: &mut Parsed, file: &mut dyn BufRead, path_for_loc: &Path) { parsed.entry(new.clone()) .or_insert_with(|| { Section { - loc: Loc { section: Some(new), ..loc }, + loc: Loc { section: Some(new), file: path.clone(), lno }, values: default(), } }) @@ -82,7 +82,7 @@ pub fn read(parsed: &mut Parsed, file: &mut dyn BufRead, path_for_loc: &Path) { } else if let Some((_, key, val)) = regex_captures!(r#"^ ( [^\[] .*? ) \s* = \s* (.*) $"#, line) { - let val = Val { loc, val: val.into() }; + let val = Val { loc: loc.clone(), val: val.into() }; section .as_mut()