aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-03 18:39:18 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-03 18:39:18 -0600
commit27abec50cbcc3e18b375bca050fc280cf089b55c (patch)
tree0fb7116bf2391593a6a3285f6033a8236d173c61
parent69ef7154ddcb4c57a882044e6351395fe56ef075 (diff)
downloadmakers-27abec50cbcc3e18b375bca050fc280cf089b55c.tar.gz
makers-27abec50cbcc3e18b375bca050fc280cf089b55c.zip
handle comments better in confusing situations
-rw-r--r--src/makefile/input.rs21
1 files changed, 11 insertions, 10 deletions
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() {