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