(&mut self, begin: usize, stdlib: &StandardLibrary)
| 76 | } |
| 77 | |
| 78 | fn parse(&mut self, begin: usize, stdlib: &StandardLibrary) -> Result<(), Vec<Diagnostic>> { |
| 79 | let mut diagnostics = vec![]; |
| 80 | let mut comment = 0; |
| 81 | let mut i = begin; |
| 82 | while i < self.text.len() { |
| 83 | if 0 < comment { |
| 84 | if self.text[i..].starts_with(b"\n%") { |
| 85 | i += b"\n%".len(); |
| 86 | self.text[i - 1] = b'#'; |
| 87 | if self.text[i..].starts_with(b"if") { |
| 88 | comment += 1; |
| 89 | } else if self.text[i..].starts_with(b"endif") { |
| 90 | comment -= 1; |
| 91 | } |
| 92 | } else if self.text[i..].starts_with(b"\n") { |
| 93 | i += 1; |
| 94 | if i < self.text.len() { |
| 95 | self.text[i] = b'#'; |
| 96 | } |
| 97 | } else { |
| 98 | i += 1; |
| 99 | } |
| 100 | } else { |
| 101 | let mut begin = false; |
| 102 | if self.text[i..].starts_with(b"\n%") { |
| 103 | i += b"\n%".len(); |
| 104 | begin = true; |
| 105 | } else if i == 0 && self.text.starts_with(b"%") { |
| 106 | i += b"%".len(); |
| 107 | begin = true; |
| 108 | } |
| 109 | if begin { |
| 110 | if self.text[i..].starts_with(b"include") { |
| 111 | self.text[i - 1] = b'#'; |
| 112 | i += b"include".len(); |
| 113 | let path = self.text[i..] |
| 114 | .split(|c| *c == b'\n' || *c == b'\r') |
| 115 | .next() |
| 116 | .unwrap(); |
| 117 | let path_span = i..(i + path.len()); |
| 118 | i += path.len(); |
| 119 | if self.text[i..].starts_with(b"\r") { |
| 120 | i += 1; |
| 121 | } |
| 122 | if self.text[i..].starts_with(b"\n") { |
| 123 | i += 1; |
| 124 | } |
| 125 | let path = str::from_utf8(path).unwrap().trim().to_owned(); |
| 126 | if !self.included.contains(&path) { |
| 127 | if let Err(err) = self.include(&path, path_span, i, stdlib) { |
| 128 | diagnostics.push(err); |
| 129 | } |
| 130 | self.included.insert(path); |
| 131 | } |
| 132 | if self.text[i..].starts_with(b"%") { |
| 133 | i -= 1; |
| 134 | } |
| 135 | } else if self.text[i..].starts_with(b"define") { |
no test coverage detected