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

Function init_body

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

577/// `\s*(?:MOD\s+)*(?:struct\s+)?(\w+)\s+(\w+)\s*(\[[^\]]*\])?\s*=\s*\{`
578/// Backtracks: modifier count (desc), `struct` with/without, bracket
579/// with/without — exactly the observable dimensions of the JS engine.
580fn init_body(s: &[u8], p: usize) -> Option<(String, usize)> {
581 let i = skip_jsws(s, p);
582 let mods = modifier_positions(s, i);
583 for &pos in mods.iter().rev() {
584 for keyword in [Some(b"struct".as_slice()), Some(b"union".as_slice()), None] {
585 let q = if let Some(keyword) = keyword {
586 if s.len() >= pos + keyword.len() && &s[pos..pos + keyword.len()] == keyword {
587 let e = pos + keyword.len();
588 let w = skip_jsws(s, e);
589 if w == e {
590 continue;
591 }
592 w
593 } else {
594 continue;
595 }
596 } else {
597 pos
598 };
599 if !is_word_at(s, q) {
600 continue;
601 }
602 let te = word_end(s, q);
603 let w = skip_jsws(s, te);
604 if w == te {
605 continue; // \s+ needs ≥1
606 }
607 if !is_word_at(s, w) {
608 continue;
609 }
610 let ne = word_end(s, w);
611 let r = skip_jsws(s, ne);
612 for with_bracket in [true, false] {
613 let r2 = if with_bracket {
614 match bracket_span(s, r) {
615 Some(e) => e,
616 None => continue,
617 }
618 } else {
619 r
620 };
621 let r3 = skip_jsws(s, r2);
622 if s.get(r3) != Some(&b'=') {
623 continue;
624 }
625 let r4 = skip_jsws(s, r3 + 1);
626 if s.get(r4) != Some(&b'{') {
627 continue;
628 }
629 return Some((bytes_to_string(&s[q..te]), r4 + 1));
630 }
631 }
632 }
633 None
634}
635
636/// 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
word_endFunction · 0.85
bracket_spanFunction · 0.85
bytes_to_stringFunction · 0.85
lenMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected