From ec2c18171cd316a8b1f69baf92f67980820dfc9a Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Mon, 11 Nov 2024 00:07:33 -0700 Subject: overhaul macro inheritance i was really proud of the lifetimes i had going on in the previous code. i should not have been. --- src/main.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index d4c0cdc..0b3e9f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,7 @@ mod args; mod makefile; use args::Args; -use makefile::{Makefile, MakefileReader}; +use makefile::{MacroScopeStack, MacroSet, Makefile, MakefileReader}; const DEFAULT_PATHS: &[&str] = &[ #[cfg(feature = "full")] @@ -66,14 +66,16 @@ fn main() -> Result<()> { let mut makefile = Makefile::new(&args); let paths = Default::default(); for filename in &args.makefile { - let macros = makefile.macros.with_overlay(); + let stack = MacroScopeStack::default().with_scope(&makefile.macros); if filename == &PathBuf::from("-") { - let file = MakefileReader::read(&args, macros, stdin().lock(), "-", Rc::clone(&paths))? - .finish(); + let macros = MacroSet::new(); + let file = + MakefileReader::read(&args, stack, macros, stdin().lock(), "-", Rc::clone(&paths))? + .finish(); makefile.extend(file)?; } else { let file = - MakefileReader::read_file(&args, macros, filename, Rc::clone(&paths))?.finish(); + MakefileReader::read_file(&args, stack, filename, Rc::clone(&paths))?.finish(); makefile.extend(file)?; }; } @@ -91,9 +93,8 @@ fn main() -> Result<()> { for outdated in makefiles_outdated { eprintln!("makefile {} out of date, rebuilding", outdated); makefile.update_target(&outdated)?; - let macros = makefile.macros.with_overlay(); - let file = - MakefileReader::read_file(&args, macros, &outdated, Default::default())?.finish(); + let stack = MacroScopeStack::default().with_scope(&makefile.macros); + let file = MakefileReader::read_file(&args, stack, &outdated, Default::default())?.finish(); // TODO forget the stale data // TODO reread all the things, not just this one makefile.extend(file)?; -- cgit v1.2.3