(file_path: &str, source: &str)
| 235 | } |
| 236 | |
| 237 | pub fn extract(file_path: &str, source: &str) -> Result<EmitOut, String> { |
| 238 | let grammar = crate::langs::grammar_for("swift").ok_or("no swift grammar")?; |
| 239 | let t0 = std::time::Instant::now(); |
| 240 | let mut parser = Parser::new(); |
| 241 | parser |
| 242 | .set_language(&grammar) |
| 243 | .map_err(|e| format!("set_language(swift) failed: {e}"))?; |
| 244 | let tree = crate::parse_budget::parse(&mut parser, source)?; |
| 245 | if tree.root_node().has_error() { |
| 246 | return Err("defer: parse tree contains errors — wasm recovery is canonical".to_string()); |
| 247 | } |
| 248 | |
| 249 | let mut w = Walker { |
| 250 | src: source, |
| 251 | file_path, |
| 252 | line_starts: util::line_starts(source), |
| 253 | arena: Arena::default(), |
| 254 | node_id_allocator: ids::NodeIdAllocator::default(), |
| 255 | tables: Tables::default(), |
| 256 | stack: Vec::new(), |
| 257 | node_ids: Vec::new(), |
| 258 | defined_fn_names: HashSet::new(), |
| 259 | imported_names: HashSet::new(), |
| 260 | fn_ref_cands: Vec::new(), |
| 261 | fs_values: HashMap::new(), |
| 262 | fs_value_counts: HashMap::new(), |
| 263 | value_scopes: Vec::new(), |
| 264 | }; |
| 265 | |
| 266 | let line_count = source.bytes().filter(|b| *b == b'\n').count() as u32 + 1; |
| 267 | let base_name = file_path.rsplit(['/', '\\']).next().unwrap_or(file_path); |
| 268 | let mut flags = BoolFlags::default(); |
| 269 | flags.set(FLAG_IS_EXPORTED, false); |
| 270 | let file_id = w.arena.put(&ids::file_node_id(file_path)); |
| 271 | let name_ref = w.arena.put(base_name); |
| 272 | let qn_ref = w.arena.put(file_path); |
| 273 | w.tables.push_node(&NodeRow { |
| 274 | kind: node_kind_index("file").unwrap(), |
| 275 | visibility: 0, |
| 276 | flags, |
| 277 | start_line: 1, |
| 278 | end_line: line_count, |
| 279 | start_column: 0, |
| 280 | end_column: 0, |
| 281 | name: name_ref, |
| 282 | qualified_name: qn_ref, |
| 283 | id: file_id, |
| 284 | docstring: NONE_STR, |
| 285 | signature: NONE_STR, |
| 286 | decorators: NONE_STR, |
| 287 | type_parameters: NONE_STR, |
| 288 | return_type: NONE_STR, |
| 289 | extra_json: NONE_STR, |
| 290 | }); |
| 291 | w.node_ids.push(ids::file_node_id(file_path)); |
| 292 | w.stack.push(Scope { row: 0, kind: "file", name: base_name.to_string() }); |
| 293 | |
| 294 | // No packageTypes — swift has no namespace node; top-level QNs are bare. |
nothing calls this directly
no test coverage detected