fracturedjson/
model.rs

1/// The type of a JSON element.
2///
3/// This enum represents the different types of items that can appear in JSON,
4/// including standard JSON types (null, boolean, string, number, object, array)
5/// and extended types for comment support (blank lines, comments).
6///
7/// This is primarily exposed for advanced use cases where you need to inspect
8/// the parsed structure. Most users won't need to interact with this directly.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum JsonItemType {
11    /// JSON `null` value.
12    Null,
13    /// JSON `false` boolean.
14    False,
15    /// JSON `true` boolean.
16    True,
17    /// A JSON string value.
18    String,
19    /// A JSON number value.
20    Number,
21    /// A JSON object (`{}`).
22    Object,
23    /// A JSON array (`[]`).
24    Array,
25    /// A blank line (when `preserve_blank_lines` is enabled).
26    BlankLine,
27    /// A line comment (`// ...`).
28    LineComment,
29    /// A block comment (`/* ... */`).
30    BlockComment,
31}
32
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
34pub enum TokenType {
35    BeginArray,
36    EndArray,
37    BeginObject,
38    EndObject,
39    String,
40    Number,
41    Null,
42    True,
43    False,
44    BlockComment,
45    LineComment,
46    BlankLine,
47    Comma,
48    Colon,
49}
50
51#[derive(Debug, Clone, Copy, PartialEq, Eq)]
52pub enum BracketPaddingType {
53    Empty = 0,
54    Simple = 1,
55    Complex = 2,
56}
57
58#[derive(Debug, Clone, Copy, PartialEq, Eq)]
59pub enum TableColumnType {
60    Unknown,
61    Simple,
62    Number,
63    Array,
64    Object,
65    Mixed,
66}
67
68/// A position within the JSON input text.
69///
70/// Used to report the location of errors or elements within the source.
71/// All values are zero-indexed.
72///
73/// # Example
74///
75/// ```rust
76/// use fracturedjson::InputPosition;
77///
78/// // Represents position at the start of line 3, column 5
79/// let pos = InputPosition { index: 42, row: 2, column: 4 };
80/// ```
81#[derive(Debug, Clone, Copy, PartialEq, Eq)]
82pub struct InputPosition {
83    /// Byte offset from the start of the input (zero-indexed).
84    pub index: usize,
85    /// Line number (zero-indexed, so first line is 0).
86    pub row: usize,
87    /// Column number within the line (zero-indexed).
88    pub column: usize,
89}
90
91#[derive(Debug, Clone, PartialEq, Eq)]
92pub struct JsonToken {
93    pub token_type: TokenType,
94    pub text: String,
95    pub input_position: InputPosition,
96}
97
98#[derive(Debug, Clone)]
99pub struct JsonItem {
100    pub item_type: JsonItemType,
101    pub input_position: InputPosition,
102    pub complexity: usize,
103    pub name: String,
104    pub value: String,
105    pub prefix_comment: String,
106    pub middle_comment: String,
107    pub middle_comment_has_new_line: bool,
108    pub postfix_comment: String,
109    pub is_post_comment_line_style: bool,
110    pub name_length: usize,
111    pub value_length: usize,
112    pub prefix_comment_length: usize,
113    pub middle_comment_length: usize,
114    pub postfix_comment_length: usize,
115    pub minimum_total_length: usize,
116    pub requires_multiple_lines: bool,
117    pub children: Vec<JsonItem>,
118}
119
120impl Default for JsonItem {
121    fn default() -> Self {
122        Self {
123            item_type: JsonItemType::Null,
124            input_position: InputPosition {
125                index: 0,
126                row: 0,
127                column: 0,
128            },
129            complexity: 0,
130            name: String::new(),
131            value: String::new(),
132            prefix_comment: String::new(),
133            middle_comment: String::new(),
134            middle_comment_has_new_line: false,
135            postfix_comment: String::new(),
136            is_post_comment_line_style: false,
137            name_length: 0,
138            value_length: 0,
139            prefix_comment_length: 0,
140            middle_comment_length: 0,
141            postfix_comment_length: 0,
142            minimum_total_length: 0,
143            requires_multiple_lines: false,
144            children: Vec::new(),
145        }
146    }
147}