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

Function scan_dispatch

codegraph-kernel/src/cfnptr.rs:850–892  ·  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

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.
851fn 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):

Callers 1

scan_fileFunction · 0.85

Calls 9

is_wordFunction · 0.85
is_word_atFunction · 0.85
word_endFunction · 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

Tested by

no test coverage detected