MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / parse_section

Function parse_section

build.rs:583–607  ·  view source on GitHub ↗

Parse one of the `const CLASSES = array(...)`, `const FUNCTIONS = array(...)`, or `const CONSTANTS = array(...)` sections from the PhpStormStubsMap.php file. Returns a `BTreeMap ` of `symbol_name → relative_file_path`.

(content: &str, section_name: &str)

Source from the content-addressed store, hash-verified

581///
582/// Returns a `BTreeMap<String, String>` of `symbol_name → relative_file_path`.
583fn parse_section(content: &str, section_name: &str) -> BTreeMap<String, String> {
584 let mut map = BTreeMap::new();
585
586 // Find the start: `const SECTION = array (`
587 let marker = format!("const {} = array (", section_name);
588 let start = match content.find(&marker) {
589 Some(pos) => pos + marker.len(),
590 None => return map,
591 };
592
593 // Walk line by line until we hit `);`
594 for line in content[start..].lines() {
595 let trimmed = line.trim();
596 if trimmed == ");" {
597 break;
598 }
599
600 // Lines look like: 'ClassName' => 'relative/path.php',
601 if let Some(entry) = parse_map_entry(trimmed) {
602 map.insert(entry.0, entry.1);
603 }
604 }
605
606 map
607}
608
609/// Parse a single `'key' => 'value',` line.
610fn parse_map_entry(line: &str) -> Option<(String, String)> {

Callers 1

mainFunction · 0.85

Calls 3

parse_map_entryFunction · 0.85
findMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected