MCPcopy Create free account
hub / github.com/Houseofmvps/codesight / parse_and_then

Function parse_and_then

plugins/ast/python/src/lib.rs:113–147  ·  view source on GitHub ↗

Decode UTF-8 source, parse with [`parse_module`], run `extract`, serialize, and `report`. Returns 0 on invalid UTF-8, a syntax error, or an empty result (host falls back).

(
    source: *const u8,
    length: usize,
    extract: impl Fn(&[Statement]) -> Vec<T>,
)

Source from the content-addressed store, hash-verified

111/// `report`. Returns 0 on invalid UTF-8, a syntax error, or an empty result (host
112/// falls back).
113unsafe fn parse_and_then<T: serde::Serialize>(
114 source: *const u8,
115 length: usize,
116 extract: impl Fn(&[Statement]) -> Vec<T>,
117) -> u64 {
118 let bytes = unsafe {
119 core::slice::from_raw_parts(source, length)
120 };
121
122 let Ok(source) = core::str::from_utf8(bytes) else {
123 return 0;
124 };
125
126 let Ok(parsed) = parse_module(source).map(Parsed::into_syntax) else {
127 return 0;
128 };
129
130 let Ok(extracted) = serde_json::to_string(&extract(&parsed.body)) else {
131 return 0;
132 };
133
134 if extracted.is_empty()
135 || extracted
136 .split_ascii_whitespace()
137 .collect::<Vec<_>>()
138 .join("")
139 == "[]"
140 {
141 return 0;
142 }
143
144 unsafe {
145 report(extracted.as_bytes())
146 }
147}
148
149/// Copy `bytes` into a fresh host-owned allocation and pack (ptr << 32) | len.
150unsafe fn report(bytes: &[u8]) -> u64 {

Callers 3

parseRoutesFunction · 0.70
parseSchemasFunction · 0.70
parseImportsFunction · 0.70

Calls 1

reportFunction · 0.70

Tested by

no test coverage detected