Skip to main content

brokk_bifrost_cpp/
knowledge.rs

1//! Analyzer-independent language rules.
2
3use brokk_bifrost_core::analyzer::Language;
4use brokk_bifrost_core::analyzer::language_knowledge::LanguageKnowledge;
5use brokk_bifrost_core::analyzer::language_knowledge::ParserFlavor;
6use brokk_bifrost_core::analyzer::structural::spec::StructuralSpec;
7
8/// Cpp syntax and static language rules.
9pub struct CppKnowledge;
10
11impl LanguageKnowledge for CppKnowledge {
12    fn language(&self) -> Language {
13        Language::Cpp
14    }
15
16    fn skips_local_declaration(&self, node: tree_sitter::Node<'_>, source: &str) -> bool {
17        match node.kind() {
18            "declaration" => {
19                crate::declarations::is_direct_recovered_exported_class_field_declaration(
20                    node, source,
21                )
22            }
23            "init_declarator" => node.parent().is_some_and(|declaration| {
24                crate::declarations::is_direct_recovered_exported_class_field_declaration(
25                    declaration,
26                    source,
27                )
28            }),
29            _ => false,
30        }
31    }
32
33    fn package_separator(&self) -> &'static str {
34        "::"
35    }
36
37    fn qualified_call_separator(&self) -> &'static str {
38        "::"
39    }
40
41    fn parser_language(&self, _flavor: ParserFlavor) -> tree_sitter::Language {
42        tree_sitter_cpp::LANGUAGE.into()
43    }
44
45    fn structural_spec(&self) -> &'static dyn StructuralSpec {
46        &crate::structural::CPP_STRUCTURAL_SPEC
47    }
48
49    fn highlight_query(&self) -> Option<&'static str> {
50        Some(tree_sitter_cpp::HIGHLIGHT_QUERY)
51    }
52}