1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Cursor navigation and character-level helper methods
// Included by parser.rs - shares parent module scope (no `use` imports here)
impl<'src> MakefileParser<'src> {
fn at_end(&self) -> bool {
self.cursor >= self.input.len()
}
fn peek(&self) -> Option<char> {
if self.cursor >= self.input.len() {
return None;
}
// Ensure we're at a char boundary
if !self.input.is_char_boundary(self.cursor) {
return None;
}
// Use string slicing to handle UTF-8 correctly
self.input[self.cursor..].chars().next()
}
fn advance(&mut self) {
// Check if we're at the end first
if self.cursor >= self.input.len() {
return;
}
if let Some(ch) = self.peek() {
let len = ch.len_utf8();
// Ensure we don't go past the end
self.cursor = (self.cursor + len).min(self.input.len());
if ch == '\n' {
self.line += 1;
self.column = 1;
} else {
self.column += 1;
}
}
}
fn skip_spaces(&mut self) {
while let Some(ch) = self.peek() {
if ch == ' ' || ch == '\r' {
self.advance();
} else {
break;
}
}
}
fn skip_whitespace_and_blank_lines(&mut self) {
while let Some(ch) = self.peek() {
if ch.is_whitespace() {
self.advance();
} else {
break;
}
}
}
fn skip_to_next_line(&mut self) {
while let Some(ch) = self.peek() {
if ch == '\n' {
self.advance();
break;
}
self.advance();
}
}
fn starts_with(&self, s: &str) -> bool {
if self.cursor >= self.input.len() {
return false;
}
// Ensure we're at a char boundary
if !self.input.is_char_boundary(self.cursor) {
return false;
}
self.input[self.cursor..].starts_with(s)
}
}