| 12 | impl<'a> Tok<'a> { |
| 13 | #[inline(never)] |
| 14 | fn chew(&mut self) -> Option<&'a str> { |
| 15 | let mut eating = false; |
| 16 | let mut eating_idx = 0usize; |
| 17 | let mut comment = false; |
| 18 | for (i, c) in self.cur.char_indices() { |
| 19 | self.col += 1; |
| 20 | let whitespace = c.is_whitespace(); |
| 21 | if eating { |
| 22 | if c == '\n' { |
| 23 | // newline while eating, don't consume it |
| 24 | let item = &self.cur[eating_idx..i]; |
| 25 | self.cur = &self.cur[i..]; |
| 26 | self.col = 0; |
| 27 | return Some(item); |
| 28 | } |
| 29 | if whitespace { |
| 30 | let item = &self.cur[eating_idx..i]; |
| 31 | self.cur = &self.cur[i+1..]; |
| 32 | return Some(item); |
| 33 | } |
| 34 | if c == ':' || c == '=' { |
| 35 | let item = &self.cur[eating_idx..i]; |
| 36 | self.cur = &self.cur[i..]; |
| 37 | return Some(item); |
| 38 | } |
| 39 | } else { |
| 40 | if c == '\n' { |
| 41 | // newline while not eating |
| 42 | self.cur = &self.cur[i+1..]; |
| 43 | self.col = 0; |
| 44 | self.line += 1; |
| 45 | return None; |
| 46 | } |
| 47 | if c == '#' { |
| 48 | comment = true; |
| 49 | } |
| 50 | |
| 51 | if !comment { |
| 52 | if c == '>' { |
| 53 | // switch modes |
| 54 | self.cur = &self.cur[i+1..]; |
| 55 | return Some(">"); |
| 56 | } else if !whitespace { |
| 57 | eating = true; |
| 58 | eating_idx = i; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | // nothing interesting in the whole string |
| 64 | self.cur = ""; |
| 65 | None |
| 66 | } |
| 67 | |
| 68 | // Tokenizer used in maps. |
| 69 | #[inline(never)] |