From 76e9ba39a483125e6a40536c9daaa638b5dd721a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 23 Jul 2021 23:28:10 +0100 Subject: [PATCH] wip parsing, record loc Signed-off-by: Ian Jackson --- src/config.rs | 19 ++++++++++--------- src/prelude.rs | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/config.rs b/src/config.rs index 31a0fb9..66325b7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -67,7 +67,7 @@ pub enum SectionName { } pub use SectionName as SN; -type SectionMap = HashMap>; +type SectionMap = HashMap, Arc)>; pub struct Config { opts: Opts, @@ -130,20 +130,21 @@ impl Aggregate { let mut ini = Ini::new_cs(); ini.set_default_section(OUTSIDE_SECTION); ini.read(s).map_err(|e| anyhow!("{}", e)).context("parse as INI")?; - let mut map = mem::take(ini.get_mut_map()); + let map = mem::take(ini.get_mut_map()); if map.get(OUTSIDE_SECTION).is_some() { throw!(anyhow!("INI file contains settings outside a section")); } - // xxx parse section names here - // xxx save Arc where we found each item + let loc = Arc::new(path.to_owned()); - for (sn, vars) in map.drain() { + for (sn, vars) in map { let sn = sn.parse().dcontext(&sn)?; - Extend::extend( - self.sections.entry(sn) - .or_default(), - vars); + self.sections.entry(sn) + .or_default() + .extend( + vars.into_iter() + .map(|(k,v)| (k, (v, loc.clone()))) + ); } None } diff --git a/src/prelude.rs b/src/prelude.rs index 18a4646..bac8d9d 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -10,6 +10,7 @@ pub use std::mem; pub use std::net::{IpAddr, Ipv4Addr}; pub use std::path::{Path, PathBuf}; pub use std::str::FromStr; +pub use std::sync::Arc; pub use anyhow::{anyhow, Context}; pub use extend::ext; -- 2.30.2