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

Function alias_line

codegraph-kernel/src/cfnptr.rs:733–790  ·  view source on GitHub ↗
(line: &[u8])

Source from the content-addressed store, hash-verified

731 i
732}
733
734fn alias_line(line: &[u8]) -> Option<&[u8]> {
735 let mut i = skip_sp_tab(line, 0);
736 if line.get(i) != Some(&b'#') {
737 return None;
738 }
739 i = skip_sp_tab(line, i + 1);
740 if line.len() < i + 6 || &line[i..i + 6] != b"define" {
741 return None;
742 }
743 i += 6;
744 let w = skip_sp_tab(line, i);
745 if w == i || !is_word_at(line, w) {
746 return None;
747 }
748 let name_end = word_end(line, w);
749 let name = &line[w..name_end];
750 let v0 = skip_sp_tab(line, name_end);
751 if v0 == name_end {
752 return None; // [ \t]+ before the value
753 }
754 // (?:(?:struct|union)[ \t]+)* greedy, k-descending on value failure.
755 let mut stack = vec![v0];
756 loop {
757 let cur = *stack.last().unwrap();
758 let keyword_len = if line.len() >= cur + 6 && &line[cur..cur + 6] == b"struct" {
759 Some(6)
760 } else if line.len() >= cur + 5 && &line[cur..cur + 5] == b"union" {
761 Some(5)
762 } else {
763 None
764 };
765 if let Some(keyword_len) = keyword_len {
766 let e = cur + keyword_len;
767 let w2 = skip_sp_tab(line, e);
768 if w2 > e {
769 stack.push(w2);
770 continue;
771 }
772 }
773 break;
774 }
775 for &vp in stack.iter().rev() {
776 let Some(&b0) = line.get(vp) else { continue };
777 if !(b0.is_ascii_alphabetic() || b0 == b'_') {
778 continue; // value must start [A-Za-z_]
779 }
780 let ve = word_end(line, vp);
781 // [ \t\r]*$
782 let mut t = ve;
783 while t < line.len() && (line[t] == b' ' || line[t] == b'\t' || line[t] == b'\r') {
784 t += 1;
785 }
786 if t == line.len() {
787 return Some(name);
788 }
789 }
790 None

Callers 1

scan_alias_namesFunction · 0.85

Calls 7

skip_sp_tabFunction · 0.85
is_word_atFunction · 0.85
lenMethod · 0.80
pushMethod · 0.80
word_endFunction · 0.70
getMethod · 0.65
unwrapMethod · 0.60

Tested by

no test coverage detected