(file_path: &str, source: &str)
| 287 | } |
| 288 | |
| 289 | pub fn extract(file_path: &str, source: &str) -> Result<EmitOut, String> { |
| 290 | let grammar = crate::langs::grammar_for("kotlin").ok_or("no kotlin grammar")?; |
| 291 | let t0 = std::time::Instant::now(); |
| 292 | let mut parser = Parser::new(); |
| 293 | parser |
| 294 | .set_language(&grammar) |
| 295 | .map_err(|e| format!("set_language(kotlin) failed: {e}"))?; |
| 296 | let tree = crate::parse_budget::parse(&mut parser, source)?; |
| 297 | if tree.root_node().has_error() { |
| 298 | // Includes the PHANTOM errors (complete CSTs with hasError set) and |
| 299 | // every fun-interface misparse — trust the flag, wasm is canonical. |
| 300 | return Err("defer: parse tree contains errors — wasm recovery is canonical".to_string()); |
| 301 | } |
| 302 | |
| 303 | let mut w = Walker { |
| 304 | src: source, |
| 305 | file_path, |
| 306 | line_starts: util::line_starts(source), |
| 307 | arena: Arena::default(), |
| 308 | node_id_allocator: ids::NodeIdAllocator::default(), |
| 309 | tables: Tables::default(), |
| 310 | stack: Vec::new(), |
| 311 | node_ids: Vec::new(), |
| 312 | nodes_meta: Vec::new(), |
| 313 | defined_fn_names: HashSet::new(), |
| 314 | imported_names: HashSet::new(), |
| 315 | fn_ref_cands: Vec::new(), |
| 316 | fs_values: HashMap::new(), |
| 317 | fs_value_counts: HashMap::new(), |
| 318 | value_scopes: Vec::new(), |
| 319 | }; |
| 320 | |
| 321 | let line_count = source.bytes().filter(|b| *b == b'\n').count() as u32 + 1; |
| 322 | let base_name = file_path.rsplit(['/', '\\']).next().unwrap_or(file_path); |
| 323 | let mut flags = BoolFlags::default(); |
| 324 | flags.set(FLAG_IS_EXPORTED, false); |
| 325 | let file_id = w.arena.put(&ids::file_node_id(file_path)); |
| 326 | let name_ref = w.arena.put(base_name); |
| 327 | let qn_ref = w.arena.put(file_path); |
| 328 | w.tables.push_node(&NodeRow { |
| 329 | kind: node_kind_index("file").unwrap(), |
| 330 | visibility: 0, |
| 331 | flags, |
| 332 | start_line: 1, |
| 333 | end_line: line_count, |
| 334 | start_column: 0, |
| 335 | end_column: 0, |
| 336 | name: name_ref, |
| 337 | qualified_name: qn_ref, |
| 338 | id: file_id, |
| 339 | docstring: NONE_STR, |
| 340 | signature: NONE_STR, |
| 341 | decorators: NONE_STR, |
| 342 | type_parameters: NONE_STR, |
| 343 | return_type: NONE_STR, |
| 344 | extra_json: NONE_STR, |
| 345 | }); |
| 346 | w.node_ids.push(ids::file_node_id(file_path)); |
nothing calls this directly
no test coverage detected