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