1use crate::{lexer::TomlLexer, parser::TomlParser};
2use oak_core::{Language, LanguageCategory};
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
7pub enum DateTimeFormat {
8 Rfc3339,
9 }
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
14pub struct TomlLanguage {
15 pub allow_multiline_strings: bool,
16 pub allow_hex_numbers: bool,
17 pub datetime_format: DateTimeFormat,
18}
19
20impl Language for TomlLanguage {
21 const NAME: &'static str = "toml";
22 const CATEGORY: LanguageCategory = LanguageCategory::Config;
23
24 type TokenType = crate::kind::TomlSyntaxKind;
25 type ElementType = crate::kind::TomlSyntaxKind;
26 type TypedRoot = crate::ast::TomlRoot;
27}
28
29impl Default for TomlLanguage {
30 fn default() -> Self {
31 Self::standard()
32 }
33}
34
35impl TomlLanguage {
36 pub fn new() -> Self {
37 Self::standard()
38 }
39
40 pub fn standard() -> Self {
41 Self { allow_multiline_strings: true, allow_hex_numbers: false, datetime_format: DateTimeFormat::Rfc3339 }
42 }
43
44 pub fn lexer(&self) -> TomlLexer<'_> {
45 TomlLexer::new(self)
46 }
47
48 pub fn parser(&self) -> TomlParser<'_> {
49 TomlParser::new(self)
50 }
51}