From b5603ccd0d6cd0d2722d631e16e1c1cf3fbdbcf8 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 7 Aug 2021 21:28:49 +0100 Subject: [PATCH] ini: fixes Signed-off-by: Ian Jackson --- src/ini.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ini.rs b/src/ini.rs index 0d60b79..294bea3 100644 --- a/src/ini.rs +++ b/src/ini.rs @@ -13,7 +13,7 @@ use std::rc::Rc; pub struct Loc { pub file: Arc, pub lno: usize, - pub section: Option>, + pub section: Option>, } #[derive(Debug,Clone)] @@ -22,8 +22,9 @@ pub struct Val { pub loc: Loc, } -pub type Parsed = HashMap, Section>; +pub type Parsed = HashMap, Section>; +#[derive(Debug)] pub struct Section { /// Location of first encounter pub loc: Loc, @@ -35,6 +36,7 @@ impl Display for Loc { fn fmt(&self, f: &mut fmt::Formatter) { write!(f, "{:?}:{}", &self.file, self.lno)?; if let Some(s) = &self.section { + write!(f, " ")?; let dbg = format!("{:?}", &s); if let Some(mid) = (||{ let mid = dbg.strip_prefix(r#"""#)?; @@ -62,7 +64,7 @@ pub fn read(parsed: &mut Parsed, file: &mut dyn BufRead, path_for_loc: &Path) let line = line.trim(); if line.is_empty() { continue } - if regex_is_match!(r#"^ [;#] "#x, line) { continue } + if regex_is_match!(r#"^ [;\#] "#x, line) { continue } let loc = Loc { lno, @@ -74,7 +76,7 @@ pub fn read(parsed: &mut Parsed, file: &mut dyn BufRead, path_for_loc: &Path) if let Some((_,new,)) = regex_captures!(r#"^ \[ \s* (.+?) \s* \] $"#x, line) { - let new: Arc = new.to_owned().into(); + let new: Arc = new.to_owned().into(); section.take(); // drops previous RefCell borrow of parsed @@ -93,7 +95,7 @@ pub fn read(parsed: &mut Parsed, file: &mut dyn BufRead, path_for_loc: &Path) section = Some(new_section); } else if let Some((_, key, val)) = - regex_captures!(r#"^ ( [^\[] .*? ) \s* = \s* (.*) $"#, line) + regex_captures!(r#"^ ( [^\[] .*? ) \s* = \s* (.*) $"#x, line) { let val = Val { loc: loc.clone(), val: val.into() }; -- 2.30.2