Skip to main content

oak_regex/language/
mod.rs

1use crate::ast::RegexRoot;
2use oak_core::{Language, LanguageCategory};
3use serde::{Deserialize, Serialize};
4
5/// Configuration for the regular expression language.
6///
7/// This structure defines the language configuration for the regex parser,
8/// including options such as whether to ignore whitespace characters.
9#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
10pub struct RegexLanguage {
11    /// Whether to ignore whitespace characters
12    pub ignore_whitespace: bool,
13}
14
15impl RegexLanguage {
16    /// Creates a new RegexLanguage instance.
17    pub fn new() -> Self {
18        Self::default()
19    }
20}
21
22/// Default implementation for RegexLanguage.
23///
24/// Creates a RegexLanguage instance with default settings.
25impl Default for RegexLanguage {
26    fn default() -> Self {
27        Self { ignore_whitespace: false }
28    }
29}
30
31/// Implementation of the Language trait for RegexLanguage.
32///
33/// This connects the language configuration to the specific syntax kinds
34/// and AST root type used for regex parsing.
35impl Language for RegexLanguage {
36    const NAME: &'static str = "regex";
37    const CATEGORY: LanguageCategory = LanguageCategory::Dsl;
38
39    type TokenType = crate::kind::RegexSyntaxKind;
40    type ElementType = crate::kind::RegexSyntaxKind;
41    type TypedRoot = RegexRoot;
42}