Skip to main content

oak_von/language/
mod.rs

1#![doc = include_str!("readme.md")]
2use alloc::{
3    string::{String, ToString},
4    vec,
5    vec::Vec,
6};
7use oak_core::{Language, LanguageCategory};
8
9/// Configuration for comments in VON.
10#[derive(Debug, Clone, PartialEq, Eq)]
11#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12pub struct CommentConfig {
13    /// The character sequence that starts a line comment.
14    pub line_comment: Option<String>,
15    /// The character sequences that start and end a block comment.
16    pub block_comment: Option<(String, String)>,
17}
18
19/// Configuration for strings in VON.
20#[derive(Debug, Clone, PartialEq, Eq)]
21#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
22pub struct StringConfig {
23    /// The characters that can be used as string quotes.
24    pub quotes: Vec<char>,
25    /// The character used for escaping characters within strings.
26    pub escape_char: Option<char>,
27}
28
29/// Configuration for whitespace in VON.
30#[derive(Debug, Clone, PartialEq, Eq)]
31#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
32pub struct WhitespaceConfig {
33    /// The characters treated as non-newline whitespace.
34    pub characters: Vec<char>,
35    /// The characters treated as newlines.
36    pub new_line_characters: Vec<char>,
37}
38
39/// Implementation of the VON language.
40#[derive(Debug, Clone, PartialEq, Eq)]
41#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
42pub struct VonLanguage {
43    /// Comment configuration.
44    pub commentconfig: CommentConfig,
45    /// String configuration.
46    pub stringconfig: StringConfig,
47    /// Whitespace configuration.
48    pub whitespaceconfig: WhitespaceConfig,
49}
50
51impl VonLanguage {
52    /// Creates a new `VonLanguage` instance with default settings.
53    pub fn new() -> Self {
54        Self::default()
55    }
56}
57
58impl Default for VonLanguage {
59    fn default() -> Self {
60        Self {
61            commentconfig: CommentConfig { line_comment: Some("#".to_string()), block_comment: None },
62            stringconfig: StringConfig { quotes: vec!['"', '\''], escape_char: Some('\\') },
63            whitespaceconfig: WhitespaceConfig { characters: vec![' ', '\t'], new_line_characters: vec!['\n', '\r'] },
64        }
65    }
66}
67
68impl Language for VonLanguage {
69    const NAME: &'static str = "von";
70    const CATEGORY: LanguageCategory = LanguageCategory::Programming;
71
72    type TokenType = crate::lexer::token_type::VonTokenType;
73    type ElementType = crate::parser::element_type::VonElementType;
74    type TypedRoot = crate::ast::VonRoot;
75}