From 27abec50cbcc3e18b375bca050fc280cf089b55c Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sat, 3 Apr 2021 18:39:18 -0600 Subject: handle comments better in confusing situations --- src/makefile/input.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/makefile') diff --git a/src/makefile/input.rs b/src/makefile/input.rs index 7c699f1..d6f6254 100644 --- a/src/makefile/input.rs +++ b/src/makefile/input.rs @@ -265,30 +265,30 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> { return Some((line_number, Ok(line.join(escaped_newline_replacement)))); } while let Some((line_number, line)) = self.lines_iter.next() { - let mut line = match line { + let line = match line { Ok(x) => x, Err(err) => return Some((line_number, Err(err))), }; + // handle comments + lazy_static! { + static ref COMMENT: Regex = Regex::new("#.*$").unwrap(); + } + let line = COMMENT.replace(&line, "").into_owned(); // handle escaped newlines let mut line_pieces = vec![line]; while line_pieces.last().map_or(false, |p| p.ends_with('\\')) { line_pieces.last_mut().map(|x| x.pop()); if let Some((n, x)) = self.lines_iter.next() { - let x = match x { + let line = match x { Ok(x) => x, Err(err) => return Some((n, Err(err))), }; - line_pieces.push(x.trim_start().to_string()); + let line = COMMENT.replace(&line, ""); + line_pieces.push(line.trim_start().to_string()); } } - line = line_pieces.join(escaped_newline_replacement); - - // handle comments - lazy_static! { - static ref COMMENT: Regex = Regex::new("#.*$").unwrap(); - } - let line = COMMENT.replace(&line, "").into_owned(); + let line = line_pieces.join(escaped_newline_replacement); #[cfg(feature = "full")] { @@ -369,6 +369,7 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> { }) { let mut line = x?; if !line.is_empty() { + assert!(line.starts_with('\t')); line.remove(0); } if line.is_empty() { -- cgit v1.2.3