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    // Applicability decides whether a Python call returns or raises, not which
16    // declaration its callee reference names.
17    fn call_applicability_may_select_callee(&self) -> bool {
18        false
19    }
20
21    // Invocation validity does not choose a declaration's modeled result type.
22    // Native typing.overload selection is not modeled; decorated values retain
23    // their existing unknown-value evidence instead of overload alternatives.
24    fn callable_result_is_applicability_independent(&self) -> bool {
25        true
26    }
27
28    fn keyed_property_reads_container_element(&self) -> bool {
29        true
30    }
31
32    fn language(&self) -> Language {
33        Language::Python
34    }
35
36    fn path_synthetic_module_unit(
37        &self,
38        project: &dyn Project,
39        file: &ProjectFile,
40    ) -> Option<CodeUnit> {
41        use crate::declarations::module_code_unit;
42        module_code_unit(project, file)
43    }
44
45    fn parser_language(&self, _flavor: ParserFlavor) -> tree_sitter::Language {
46        tree_sitter_python::LANGUAGE.into()
47    }
48
49    fn structural_spec(&self) -> &'static dyn StructuralSpec {
50        &crate::structural::PYTHON_STRUCTURAL_SPEC
51    }
52
53    fn highlight_query(&self) -> Option<&'static str> {
54        Some(tree_sitter_python::HIGHLIGHTS_QUERY)
55    }
56}