Skip to main content

oak_d/language/
mod.rs

1use crate::ast::DRoot;
2use oak_core::{Language, LanguageCategory};
3use serde::{Deserialize, Serialize};
4
5/// Language definition for D programming language
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
7pub struct DLanguage {
8    /// Whether to enable D2 features
9    pub d2_features: bool,
10    /// Whether to allow inline assembly
11    pub inline_asm: bool,
12    /// Whether to enable contract programming
13    pub contracts: bool,
14}
15
16impl DLanguage {
17    /// Create a new D language instance
18    pub fn new() -> Self {
19        Self::default()
20    }
21
22    /// Create a standard D language instance
23    pub fn standard() -> Self {
24        Self { d2_features: true, inline_asm: true, contracts: true }
25    }
26
27    /// Create a minimal D language instance
28    pub fn minimal() -> Self {
29        Self { d2_features: false, inline_asm: false, contracts: false }
30    }
31}
32
33impl Default for DLanguage {
34    fn default() -> Self {
35        Self { d2_features: true, inline_asm: false, contracts: true }
36    }
37}
38
39impl Language for DLanguage {
40    const NAME: &'static str = "d";
41    const CATEGORY: LanguageCategory = LanguageCategory::Programming;
42
43    type TokenType = crate::kind::DSyntaxKind;
44    type ElementType = crate::kind::DSyntaxKind;
45    type TypedRoot = DRoot;
46}