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

Function scan_dispatch

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

830/// segment count k descending — the JS engine's observable backtracking. The
831/// per-segment optional subscript needs no cross-product: the with/without
832/// parses diverge at the arrow and at most one can complete a segment.
833fn scan_dispatch(s: &[u8], out: &mut Vec<String>) {
834 let mut pos = 0usize;
835 while pos < s.len() {
836 if !is_word(s[pos]) {
837 pos += 1;
838 continue;
839 }
840 // Greedy segment loop.
841 let mut seg_ends: Vec<usize> = Vec::new();
842 let mut cur = pos;
843 while is_word_at(s, cur) {
844 let we = word_end(s, cur);
845 let with_sub = subscript_span(s, skip_jsws(s, we)).and_then(|e| arrow_tail(s, e));
846 let seg = with_sub.or_else(|| arrow_tail(s, we));
847 match seg {
848 Some(e) => {
849 seg_ends.push(e);
850 cur = e;
851 }
852 None => break,
853 }
854 }
855 let mut matched = None;
856 for k in (1..=seg_ends.len()).rev() {
857 let fpos = seg_ends[k - 1];
858 if !is_word_at(s, fpos) {
859 continue;
860 }
861 let fe = word_end(s, fpos);
862 if let Some(end) = close_call_tail(s, fe) {
863 matched = Some(((fpos, fe), end));
864 break;
865 }
866 }
867 match matched {
868 Some(((fs_, fe), end)) => {
869 push_str(out, &s[fs_..fe]);
870 pos = end;
871 }
872 None => pos += 1,
873 }
874 }
875}
876
877/// `\[[^\][]*\]` 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