use crate::prelude::*;
+use std::cell::{RefCell, RefMut};
use std::io::BufRead;
+use std::rc::Rc;
#[derive(Debug,Clone)]
#[derive(Hash,Eq,PartialEq,Ord,PartialOrd)]
}
}
+
#[throws(AE)]
-pub fn read(parsed: &mut Parsed, file: &mut dyn BufRead, path_for_loc: &Path) {
+pub fn read(parsed: &mut Parsed, file: &mut dyn BufRead, path_for_loc: &Path)
+//->Result<(), AE>
+{
+ let parsed = Rc::new(RefCell::new(parsed));
let path: Arc<PathBuf> = path_for_loc.to_owned().into();
- let mut section: Option<&mut Section> = None;
+ let mut section: Option<RefMut<Section>> = None;
for (lno, line) in file.lines().enumerate() {
let line = line.context("read")?;
let line = line.trim();
regex_captures!(r#"^ \[ \s* (.+?) \s* \] $"#x, line)
{
let new: Arc<String> = new.to_owned().into();
- section = Some(
- parsed.entry(new.clone())
+
+ section.take(); // drops previous RefCell borrow of parsed
+
+ let new_section = RefMut::map(parsed.borrow_mut(), |p| {
+
+ p.entry(new.clone())
.or_insert_with(|| {
Section {
loc: Loc { section: Some(new), file: path.clone(), lno },
values: default(),
- }
+ }
})
- );
+
+ });
+
+ section = Some(new_section);
} else if let Some((_, key, val)) =
regex_captures!(r#"^ ( [^\[] .*? ) \s* = \s* (.*) $"#, line)