Skip to main content

dk_engine/parser/langs/
cpp.rs

1//! C++ 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/// C++ language configuration for [`QueryDrivenParser`](crate::parser::engine::QueryDrivenParser).
8pub struct CppConfig;
9
10impl LanguageConfig for CppConfig {
11    fn language(&self) -> Language {
12        tree_sitter_cpp::LANGUAGE.into()
13    }
14
15    fn extensions(&self) -> &'static [&'static str] {
16        // .c and .h are parsed with the C++ grammar (a superset of C).
17        // K&R-style definitions and some C99/C11 constructs may not be
18        // captured perfectly, but coverage for modern C is acceptable.
19        &["cpp", "cc", "cxx", "c", "h", "hpp", "hxx"]
20    }
21
22    fn symbols_query(&self) -> &'static str {
23        include_str!("../queries/cpp_symbols.scm")
24    }
25
26    fn calls_query(&self) -> &'static str {
27        include_str!("../queries/cpp_calls.scm")
28    }
29
30    fn imports_query(&self) -> &'static str {
31        include_str!("../queries/cpp_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        // Top-level C++ symbols are effectively public (visible to other
40        // translation units unless explicitly static/anonymous-namespace).
41        // We default everything to Public for simplicity.
42        Visibility::Public
43    }
44
45    fn is_external_import(&self, module_path: &str) -> bool {
46        // System includes (<iostream>) keep angle brackets after the engine's
47        // quote-stripping pass. Local includes ("myheader.h") have quotes
48        // stripped, leaving a bare path. Angle brackets → external.
49        module_path.starts_with('<')
50    }
51}