jasn/
lib.rs

1//! A Rust library for parsing and formatting JASN (Just Another Serialization Notation).
2//!
3//! JASN is a human-readable data serialization format similar to JSON but with explicit integer and binary types.
4//!
5//! # Features
6//! 1. **Explicit Integer Types**: Distinguish between integers and floats (2 vs 2.0).
7//! 2. **Binary Data**: Support for base64 and hex-encoded binary data
8//! 3. **Timestamps**: ISO8601/RFC3339 timestamps with `ts"..."` syntax
9//! 4. Permissive syntax, similar to JSON5
10//!
11//! # JASN Syntax
12//!
13//! A comprehensive example showing all supported value types:
14//!
15//! ```jasn
16//! {
17//!   /* Comments are supported */
18//!   null_value: null,
19//!   
20//!   /* Booleans */
21//!   bool_true: true,
22//!   bool_false: false,
23//!   
24//!   /* Integers (explicit type, no decimal point) */
25//!   integer: 42,
26//!   negative: -123,
27//!   hex: 0xFF,
28//!   binary: 0b1010,
29//!   octal: 0o755,
30//!   with_underscores: 1_000_000,
31//!   
32//!   /* Floats (always have decimal point or exponent) */
33//!   float: 3.14,
34//!   scientific: 1.5e10,
35//!   special_inf: inf,
36//!   special_neg_inf: -inf,
37//!   special_nan: nan,
38//!   
39//!   /* Strings (double or single quotes) */
40//!   string_double: "Hello, World!",
41//!   string_single: 'Hello, World!',
42//!   string_unicode: "Hello \u4E16\u754C",  /* Unicode escapes */
43//!   
44//!   /* Binary data */
45//!   binary_hex: hex"48656c6c6f",           /* Hex encoding */
46//!   binary_base64: b64"SGVsbG8gV29ybGQ=", /* Base64 encoding */
47//!   
48//!   /* Timestamps (RFC3339/ISO8601) */
49//!   timestamp: ts"2024-01-15T12:30:45Z",
50//!   timestamp_offset: ts"2024-01-15T12:30:45-05:00",
51//!   
52//!   /* Lists */
53//!   list: [1, 2, 3, "mixed", true, null],
54//!   nested_list: [[1, 2], [3, 4]],
55//!   
56//!   /* Maps (objects) */
57//!   map: {
58//!     unquoted_key: "value",
59//!     "quoted key": "also works",
60//!     nested: { a: 1, b: 2 },
61//!   },
62//!   
63//!   /* Trailing commas allowed */
64//!   trailing: [1, 2, 3,],
65//! }
66//! ```
67//!
68//! # Usage
69//!
70//! ## AST Manipulation (no serde required)
71//!
72//! ```
73//! use jasn::{parse, format_pretty};
74//!
75//! let jasn_text = r#"{ name: "Alice", age: 30 }"#;
76//! let value = parse(jasn_text).unwrap();
77//! println!("{}", format_pretty(&value));
78//!
79//! // For custom formatting:
80//! let opts = jasn::formatter::Options::pretty()
81//!     .with_indent("\t");
82//! println!("{}", jasn::formatter::format_with_opts(&value, &opts));
83//! ```
84//!
85//! ## Serde Integration (default feature)
86//!
87//! ```
88//! use serde::{Deserialize, Serialize};
89//!
90//! #[derive(Serialize, Deserialize)]
91//! struct Person {
92//!     name: String,
93//!     age: u32,
94//! }
95//!
96//! let person = Person { name: "Alice".into(), age: 30 };
97//! let jasn_text = jasn::to_string_pretty(&person).unwrap();
98//! let parsed: Person = jasn::from_str(&jasn_text).unwrap();
99//! ```
100//!
101//! # Features
102//!
103//! - `serde` (default): Enable serde serialization/deserialization support
104//!
105//! # Grammar
106//!
107//! For the complete grammar specification, see the [`grammar`] module.
108//!
109//! > **Note:** The specification is still under active development and may be subject to change.
110
111#![warn(missing_docs)]
112
113// Re-export core types
114pub use jasn_core::{Binary, Timestamp, Value};
115
116pub mod parser;
117pub use parser::parse;
118
119pub mod formatter;
120pub use formatter::{format, format_pretty};
121
122#[cfg(feature = "serde")]
123pub mod de;
124#[cfg(feature = "serde")]
125pub mod ser;
126
127#[cfg(feature = "serde")]
128pub use de::{from_str, from_value};
129#[cfg(feature = "serde")]
130pub use ser::{to_string, to_string_pretty, to_value};
131
132/// Complete grammar specification for JASN.
133///
134#[doc = include_str!("../GRAMMAR.md")]
135pub mod grammar {}