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

Function init_body

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

INIT_RE body after the anchor: `\s*(?:MOD\s+)*(?:struct\s+)?(\w+)\s+(\w+)\s*(\[[^\]]*\])?\s*=\s*\{` Backtracks: modifier count (desc), `struct` with/without, bracket with/without — exactly the observable dimensions of the JS engine.

(s: &[u8], p: usize)

Source from the content-addressed store, hash-verified

587/// `\s*(?:MOD\s+)*(?:struct\s+)?(\w+)\s+(\w+)\s*(\[[^\]]*\])?\s*=\s*\{`
588/// Backtracks: modifier count (desc), `struct` with/without, bracket
589/// with/without — exactly the observable dimensions of the JS engine.
590fn init_body(s: &[u8], p: usize) -> Option<(String, usize)> {
591 let i = skip_jsws(s, p);
592 let mods = modifier_positions(s, i);
593 for &pos in mods.iter().rev() {
594 for keyword in [Some(b"struct".as_slice()), Some(b"union".as_slice()), None] {
595 let q = if let Some(keyword) = keyword {
596 if s.len() >= pos + keyword.len() && &s[pos..pos + keyword.len()] == keyword {
597 let e = pos + keyword.len();
598 let w = skip_jsws(s, e);
599 if w == e {
600 continue;
601 }
602 w
603 } else {
604 continue;
605 }
606 } else {
607 pos
608 };
609 if !is_word_at(s, q) {
610 continue;
611 }
612 let te = word_end(s, q);
613 let w = skip_jsws(s, te);
614 if w == te {
615 continue; // \s+ needs ≥1
616 }
617 if !is_word_at(s, w) {
618 continue;
619 }
620 let ne = word_end(s, w);
621 let r = skip_jsws(s, ne);
622 for with_bracket in [true, false] {
623 let r2 = if with_bracket {
624 match bracket_span(s, r) {
625 Some(e) => e,
626 None => continue,
627 }
628 } else {
629 r
630 };
631 let r3 = skip_jsws(s, r2);
632 if s.get(r3) != Some(&b'=') {
633 continue;
634 }
635 let r4 = skip_jsws(s, r3 + 1);
636 if s.get(r4) != Some(&b'{') {
637 continue;
638 }
639 return Some((bytes_to_string(&s[q..te]), r4 + 1));
640 }
641 }
642 }
643 None
644}
645
646/// ARRAY_TABLE_RE body after the anchor:

Callers

nothing calls this directly

Calls 8

skip_jswsFunction · 0.85
modifier_positionsFunction · 0.85
is_word_atFunction · 0.85
bracket_spanFunction · 0.85
bytes_to_stringFunction · 0.85
lenMethod · 0.80
word_endFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected