Skip to main content

aft_parse/grammar/
disabled.rs

1use std::sync::{Arc, LazyLock};
2
3use super::{manifests, GrammarManifest, GrammarState, GrammarUnavailable};
4
5pub struct GrammarRegistry(&'static GrammarManifest);
6
7static REGISTRIES: LazyLock<super::RegistryMap<GrammarRegistry>> =
8    LazyLock::new(|| super::registry_map(manifests(), |entry| Arc::new(GrammarRegistry(entry))));
9
10pub fn registry(language: &str) -> Option<&'static Arc<GrammarRegistry>> {
11    REGISTRIES.get(language)
12}
13
14/// A disabled build must not resolve, create or inspect grammar storage.
15pub fn configure(_config: &crate::config::Config) {}
16
17test_support_visibility! {
18fn unavailable(language: &str) -> GrammarUnavailable {
19    GrammarUnavailable::new(language, GrammarState::SupportDisabled)
20}
21}
22
23impl GrammarRegistry {
24    pub fn stored(&self) -> Result<tree_sitter::Language, GrammarUnavailable> {
25        Err(unavailable(&self.0.language))
26    }
27
28    pub fn request(self: &Arc<Self>) -> Result<tree_sitter::Language, GrammarUnavailable> {
29        Err(unavailable(&self.0.language))
30    }
31
32    pub fn identity(&self) -> &str {
33        &self.0.sha256
34    }
35
36    pub fn compile_ms(&self) -> f64 {
37        0.0
38    }
39
40    pub fn subscribe(&self) -> std::sync::mpsc::Receiver<String> {
41        let (_, receiver) = std::sync::mpsc::channel();
42        receiver
43    }
44}
45
46pub fn prepare_parser(_parser: &mut tree_sitter::Parser, language: &str) -> Result<(), GrammarUnavailable> {
47    Err(unavailable(language))
48}
49
50pub fn engine_target(language: &str) -> Result<&'static str, GrammarUnavailable> {
51    Err(unavailable(language))
52}