Skip to main content

brokk_bifrost_python/
knowledge.rs

1//! Analyzer-independent language rules.
2
3use brokk_bifrost_core::analyzer::CodeUnit;
4use brokk_bifrost_core::analyzer::Language;
5use brokk_bifrost_core::analyzer::ProjectFile;
6use brokk_bifrost_core::analyzer::language_knowledge::LanguageKnowledge;
7use brokk_bifrost_core::analyzer::language_knowledge::ParserFlavor;
8use brokk_bifrost_core::analyzer::project::Project;
9use brokk_bifrost_core::analyzer::structural::spec::StructuralSpec;
10
11/// Python syntax and static language rules.
12pub struct PythonKnowledge;
13
14impl LanguageKnowledge for PythonKnowledge {
15    fn keyed_property_reads_container_element(&self) -> bool {
16        true
17    }
18
19    fn language(&self) -> Language {
20        Language::Python
21    }
22
23    fn path_synthetic_module_unit(
24        &self,
25        project: &dyn Project,
26        file: &ProjectFile,
27    ) -> Option<CodeUnit> {
28        use crate::declarations::module_code_unit;
29        module_code_unit(project, file)
30    }
31
32    fn parser_language(&self, _flavor: ParserFlavor) -> tree_sitter::Language {
33        tree_sitter_python::LANGUAGE.into()
34    }
35
36    fn structural_spec(&self) -> &'static dyn StructuralSpec {
37        &crate::structural::PYTHON_STRUCTURAL_SPEC
38    }
39
40    fn highlight_query(&self) -> Option<&'static str> {
41        Some(tree_sitter_python::HIGHLIGHTS_QUERY)
42    }
43}