oak_json/language/
mod.rs

1use oak_core::language::Language;
2
3/// JSON 语言实现
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub struct JsonLanguage {
6    /// 是否允许尾随逗号
7    pub trailing_comma: bool,
8    /// 是否允许裸键(不带引号的键)
9    pub bare_keys: bool,
10    /// 是否允许单引号字符串
11    pub single_quotes: bool,
12    /// 是否允许注释
13    pub comments: bool,
14    /// 是否允许十六进制数字
15    pub hex_numbers: bool,
16    /// 是否允许无穷大和 NaN
17    pub infinity_and_nan: bool,
18}
19
20impl JsonLanguage {
21    /// 创建标准 JSON 语言实例
22    pub fn standard() -> Self {
23        Self::default()
24    }
25
26    /// 创建 JSON5 语言实例
27    pub fn json5() -> Self {
28        Self {
29            trailing_comma: true,
30            bare_keys: true,
31            single_quotes: true,
32            comments: true,
33            hex_numbers: true,
34            infinity_and_nan: true,
35        }
36    }
37
38    /// 创建宽松 JSON 语言实例
39    pub fn relaxed() -> Self {
40        Self {
41            trailing_comma: true,
42            bare_keys: true,
43            single_quotes: true,
44            comments: true,
45            hex_numbers: true,
46            infinity_and_nan: true,
47        }
48    }
49}
50
51impl Default for JsonLanguage {
52    fn default() -> Self {
53        Self {
54            trailing_comma: false,
55            bare_keys: false,
56            single_quotes: false,
57            comments: false,
58            hex_numbers: false,
59            infinity_and_nan: false,
60        }
61    }
62}
63
64impl Language for JsonLanguage {
65    type SyntaxKind = crate::kind::JsonSyntaxKind;
66    type TypedRoot = (); // 暂时使用空类型,后续可以定义具体的AST根节点类型
67}