1#![doc = include_str!("readme.md")]
2#[cfg(feature = "serde")]
3use ::serde::{Deserialize, Serialize};
4use oak_core::language::{Language, LanguageCategory};
5#[cfg(feature = "serde")]
6pub mod serde_impl;
7#[cfg(feature = "serde")]
8pub use serde_impl::{from_value, to_value};
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12#[cfg_attr(feature = "serde", derive(Serialize, 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 JsonLanguage {
29 pub fn new() -> Self {
31 Self::default()
32 }
33
34 pub fn standard() -> Self {
36 Self::default()
37 }
38
39 pub fn json5() -> Self {
41 Self { trailing_comma: true, bare_keys: true, single_quotes: true, comments: true, hex_numbers: true, infinity_and_nan: true }
42 }
43
44 pub fn relaxed() -> Self {
46 Self { trailing_comma: true, bare_keys: true, single_quotes: true, comments: true, hex_numbers: true, infinity_and_nan: true }
47 }
48}
49
50impl Default for JsonLanguage {
51 fn default() -> Self {
52 Self { trailing_comma: false, bare_keys: false, single_quotes: false, comments: false, hex_numbers: false, infinity_and_nan: false }
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}