DISPATCH_RE: /((?:\w+(?:\s*\[[^\][]*\])?\s*(?:->|\.)\s*)+)(\w+)\s*\)?\s*\(/g The `+` loop is consumed greedily, then the field tail is tried at each segment count k descending — the JS engine's observable backtracking. The per-segment optional subscript needs no cross-product: the with/without parses diverge at the arrow and at most one can complete a segment.
(s: &[u8], out: &mut Vec<String>)
| 848 | /// segment count k descending — the JS engine's observable backtracking. The |
| 849 | /// per-segment optional subscript needs no cross-product: the with/without |
| 850 | /// parses diverge at the arrow and at most one can complete a segment. |
| 851 | fn scan_dispatch(s: &[u8], out: &mut Vec<String>) { |
| 852 | let mut pos = 0usize; |
| 853 | while pos < s.len() { |
| 854 | if !is_word(s[pos]) { |
| 855 | pos += 1; |
| 856 | continue; |
| 857 | } |
| 858 | // Greedy segment loop. |
| 859 | let mut seg_ends: Vec<usize> = Vec::new(); |
| 860 | let mut cur = pos; |
| 861 | while is_word_at(s, cur) { |
| 862 | let we = word_end(s, cur); |
| 863 | let with_sub = subscript_span(s, skip_jsws(s, we)).and_then(|e| arrow_tail(s, e)); |
| 864 | let seg = with_sub.or_else(|| arrow_tail(s, we)); |
| 865 | match seg { |
| 866 | Some(e) => { |
| 867 | seg_ends.push(e); |
| 868 | cur = e; |
| 869 | } |
| 870 | None => break, |
| 871 | } |
| 872 | } |
| 873 | let mut matched = None; |
| 874 | for k in (1..=seg_ends.len()).rev() { |
| 875 | let fpos = seg_ends[k - 1]; |
| 876 | if !is_word_at(s, fpos) { |
| 877 | continue; |
| 878 | } |
| 879 | let fe = word_end(s, fpos); |
| 880 | if let Some(end) = close_call_tail(s, fe) { |
| 881 | matched = Some(((fpos, fe), end)); |
| 882 | break; |
| 883 | } |
| 884 | } |
| 885 | match matched { |
| 886 | Some(((fs_, fe), end)) => { |
| 887 | push_str(out, &s[fs_..fe]); |
| 888 | pos = end; |
| 889 | } |
| 890 | None => pos += 1, |
| 891 | } |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | /// `\[[^\][]*\]` at `i` (the DISPATCH subscript form — no nested brackets): |
no test coverage detected