1#![doc = include_str!("readme.md")]
2use oak_core::language::{Language, LanguageCategory};
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9pub struct JsonLanguage {
10 pub trailing_comma: bool,
12 pub bare_keys: bool,
14 pub single_quotes: bool,
16 pub comments: bool,
18 pub hex_numbers: bool,
20 pub infinity_and_nan: bool,
22}
23
24impl JsonLanguage {
25 pub fn new() -> Self {
27 Self::default()
28 }
29
30 pub fn standard() -> Self {
32 Self::default()
33 }
34
35 pub fn json5() -> Self {
37 Self { trailing_comma: true, bare_keys: true, single_quotes: true, comments: true, hex_numbers: true, infinity_and_nan: true }
38 }
39
40 pub fn relaxed() -> Self {
42 Self { trailing_comma: true, bare_keys: true, single_quotes: true, comments: true, hex_numbers: true, infinity_and_nan: true }
43 }
44}
45
46impl Default for JsonLanguage {
47 fn default() -> Self {
48 Self { trailing_comma: false, bare_keys: false, single_quotes: false, comments: false, hex_numbers: false, infinity_and_nan: false }
49 }
50}
51
52impl Language for JsonLanguage {
53 const NAME: &'static str = "json";
54 const CATEGORY: LanguageCategory = LanguageCategory::Config;
55
56 type TokenType = crate::lexer::token_type::JsonTokenType;
57 type ElementType = crate::parser::element_type::JsonElementType;
58 type TypedRoot = crate::ast::JsonRoot;
59}