(file_path: &str, source: &str)
| 144 | } |
| 145 | |
| 146 | pub fn extract(file_path: &str, source: &str) -> Result<EmitOut, String> { |
| 147 | let grammar = crate::langs::grammar_for("kotlin").ok_or("no kotlin grammar")?; |
| 148 | let t0 = std::time::Instant::now(); |
| 149 | let mut parser = Parser::new(); |
| 150 | parser |
| 151 | .set_language(&grammar) |
| 152 | .map_err(|e| format!("set_language(kotlin) failed: {e}"))?; |
| 153 | let tree = parser |
| 154 | .parse(source, None) |
| 155 | .ok_or_else(|| "parser returned null tree".to_string())?; |
| 156 | if tree.root_node().has_error() { |
| 157 | // Includes the PHANTOM errors (complete CSTs with hasError set) and |
| 158 | // every fun-interface misparse — trust the flag, wasm is canonical. |
| 159 | return Err("defer: parse tree contains errors — wasm recovery is canonical".to_string()); |
| 160 | } |
| 161 | |
| 162 | let mut w = Walker { |
| 163 | src: source, |
| 164 | file_path, |
| 165 | line_starts: util::line_starts(source), |
| 166 | arena: Arena::default(), |
| 167 | tables: Tables::default(), |
| 168 | stack: Vec::new(), |
| 169 | node_ids: Vec::new(), |
| 170 | nodes_meta: Vec::new(), |
| 171 | defined_fn_names: HashSet::new(), |
| 172 | imported_names: HashSet::new(), |
| 173 | fn_ref_cands: Vec::new(), |
| 174 | fs_values: HashMap::new(), |
| 175 | fs_value_counts: HashMap::new(), |
| 176 | value_scopes: Vec::new(), |
| 177 | }; |
| 178 | |
| 179 | let line_count = source.bytes().filter(|b| *b == b'\n').count() as u32 + 1; |
| 180 | let base_name = file_path.rsplit(['/', '\\']).next().unwrap_or(file_path); |
| 181 | let mut flags = BoolFlags::default(); |
| 182 | flags.set(FLAG_IS_EXPORTED, false); |
| 183 | let file_id = w.arena.put(&ids::file_node_id(file_path)); |
| 184 | let name_ref = w.arena.put(base_name); |
| 185 | let qn_ref = w.arena.put(file_path); |
| 186 | w.tables.push_node(&NodeRow { |
| 187 | kind: node_kind_index("file").unwrap(), |
| 188 | visibility: 0, |
| 189 | flags, |
| 190 | start_line: 1, |
| 191 | end_line: line_count, |
| 192 | start_column: 0, |
| 193 | end_column: 0, |
| 194 | name: name_ref, |
| 195 | qualified_name: qn_ref, |
| 196 | id: file_id, |
| 197 | docstring: NONE_STR, |
| 198 | signature: NONE_STR, |
| 199 | decorators: NONE_STR, |
| 200 | type_parameters: NONE_STR, |
| 201 | return_type: NONE_STR, |
| 202 | extra_json: NONE_STR, |
| 203 | }); |
nothing calls this directly
no test coverage detected