Skip to main content

dk_engine/parser/langs/
php.rs

1//! PHP language configuration for the query-driven parser.
2
3use crate::parser::lang_config::{CommentStyle, LanguageConfig};
4use dk_core::Visibility;
5use tree_sitter::Language;
6
7/// PHP language configuration for [`QueryDrivenParser`](crate::parser::engine::QueryDrivenParser).
8///
9/// Uses `LANGUAGE_PHP` (includes `<?php` tag handling). PHP files must
10/// start with `<?php` for parsing to succeed.
11pub struct PhpConfig;
12
13impl LanguageConfig for PhpConfig {
14    fn language(&self) -> Language {
15        tree_sitter_php::LANGUAGE_PHP.into()
16    }
17
18    fn extensions(&self) -> &'static [&'static str] {
19        &["php"]
20    }
21
22    fn symbols_query(&self) -> &'static str {
23        include_str!("../queries/php_symbols.scm")
24    }
25
26    fn calls_query(&self) -> &'static str {
27        include_str!("../queries/php_calls.scm")
28    }
29
30    fn imports_query(&self) -> &'static str {
31        include_str!("../queries/php_imports.scm")
32    }
33
34    fn comment_style(&self) -> CommentStyle {
35        CommentStyle::SlashSlash
36    }
37
38    fn resolve_visibility(&self, modifiers: Option<&str>, _name: &str) -> Visibility {
39        match modifiers {
40            Some(m) if m.contains("private") => Visibility::Private,
41            Some(m) if m.contains("protected") => Visibility::Public,
42            // public or no modifier → Public (PHP convention)
43            _ => Visibility::Public,
44        }
45    }
46
47    fn is_external_import(&self, _module_path: &str) -> bool {
48        // PHP `use` statements are always fully qualified namespace paths.
49        // Without Composer/autoloader context we can't distinguish internal
50        // vs external, so treat all as external.
51        true
52    }
53}