MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / scan_dispatch

Function scan_dispatch

codegraph-kernel/src/cfnptr.rs:860–902  ·  view source on GitHub ↗

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>)

Source from the content-addressed store, hash-verified

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

Callers 1

scan_fileFunction · 0.85

Calls 10

is_wordFunction · 0.85
is_word_atFunction · 0.85
subscript_spanFunction · 0.85
skip_jswsFunction · 0.85
arrow_tailFunction · 0.85
close_call_tailFunction · 0.85
push_strFunction · 0.85
lenMethod · 0.80
pushMethod · 0.80
word_endFunction · 0.70

Tested by

no test coverage detected