1#![doc = include_str!("readme.md")]
2use oak_core::language::{Language, LanguageCategory};
3#[cfg(feature = "serde")]
4pub mod serde_impl;
10#[cfg(feature = "serde")]
11pub use serde_impl::{from_value, to_value};
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16pub struct JsonLanguage {
17 pub trailing_comma: bool,
19 pub bare_keys: bool,
21 pub single_quotes: bool,
23 pub comments: bool,
25 pub hex_numbers: bool,
27 pub infinity_and_nan: bool,
29}
30
31impl JsonLanguage {
32 pub fn new() -> Self {
34 Self::default()
35 }
36
37 pub fn standard() -> Self {
39 Self::default()
40 }
41
42 pub fn json5() -> Self {
44 Self { trailing_comma: true, bare_keys: true, single_quotes: true, comments: true, hex_numbers: true, infinity_and_nan: true }
45 }
46
47 pub fn relaxed() -> Self {
49 Self { trailing_comma: true, bare_keys: true, single_quotes: true, comments: true, hex_numbers: true, infinity_and_nan: true }
50 }
51}
52
53impl Default for JsonLanguage {
54 fn default() -> Self {
55 Self { trailing_comma: false, bare_keys: false, single_quotes: false, comments: false, hex_numbers: false, infinity_and_nan: false }
56 }
57}
58
59impl Language for JsonLanguage {
60 const NAME: &'static str = "json";
61 const CATEGORY: LanguageCategory = LanguageCategory::Config;
62
63 type TokenType = crate::lexer::token_type::JsonTokenType;
64 type ElementType = crate::parser::element_type::JsonElementType;
65 type TypedRoot = crate::ast::JsonRoot;
66}