Anchor-skeleton driver shared by INIT_RE and ARRAY_TABLE_RE: both match `(?:^|[;{}])` then a body, and resume from the end of each match. `body` returns (token, match_end) when the body matches at the position after the anchor.
(s: &[u8], mut body: F, out: &mut Vec<String>)
| 547 | /// `(?:^|[;{}])` then a body, and resume from the end of each match. `body` |
| 548 | /// returns (token, match_end) when the body matches at the position after the |
| 549 | /// anchor. |
| 550 | fn scan_anchored<F>(s: &[u8], mut body: F, out: &mut Vec<String>) |
| 551 | where |
| 552 | F: FnMut(&[u8], usize) -> Option<(String, usize)>, |
| 553 | { |
| 554 | let mut last = 0usize; |
| 555 | // The `^` branch consumes nothing and only exists at position 0. |
| 556 | if last == 0 { |
| 557 | if let Some((tok, end)) = body(s, 0) { |
| 558 | out.push(tok); |
| 559 | last = end; |
| 560 | } |
| 561 | } |
| 562 | let mut p = last; |
| 563 | while p < s.len() { |
| 564 | let ch = s[p]; |
| 565 | if ch == b';' || ch == b'{' || ch == b'}' { |
| 566 | if let Some((tok, end)) = body(s, p + 1) { |
| 567 | out.push(tok); |
| 568 | p = end; |
| 569 | continue; |
| 570 | } |
| 571 | } |
| 572 | p += 1; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | /// INIT_RE body after the anchor: |