Skip to main content

oak_d/language/
mod.rs

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