chiark / gitweb /
ini: wip new module
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 19:55:02 +0000 (20:55 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 19:55:02 +0000 (20:55 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/ini.rs

index 67817f525e1401673c1f7d0c2f85532b5f3624a2..107f4aa125ae8e7c1ea9c7487aebc23e4b231153 100644 (file)
@@ -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<PathBuf> = 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()