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