Skip to main content

jsonette/parser/
mod.rs

1/*
2 * Copyright (c) 2026 DevEtte.
3 *
4 * This project is dual-licensed under both the MIT License and the
5 * Apache License, Version 2.0 (the "License"). You may not use this
6 * file except in compliance with one of these licenses.
7 *
8 * You may obtain a copy of the Licenses at:
9 * - MIT: https://opensource.org
10 * - Apache 2.0: http://apache.org
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19//! The parsing module contains the strict and tolerant JSON parsers,
20//! as well as fast diagnostics syntax checking and parsing helper utilities.
21
22pub mod strict;
23pub mod utils;
24
25pub use strict::parse;
26
27use crate::json_node::JsonNode;
28use crate::types::Diagnostic;
29
30/// Tolerant parsing: Attempts to build a partial AST even if errors are present.
31/// Useful for live IDE feedback while typing, preserving as much of the tree as possible.
32///
33/// # Arguments
34///
35/// * `input` - The raw JSON string slice to parse (potentially incomplete or invalid).
36///
37/// # Returns
38///
39/// A tuple containing:
40/// * `Option<JsonNode>` - The partial AST tree if any structure could be recovered.
41/// * `Vec<Diagnostic>` - A list of errors encountered during parsing.
42pub fn tolerant_parse(input: &str) -> (Option<JsonNode>, Vec<Diagnostic>) {
43    todo!("Tolerant JSON parsing logic will be implemented in subsequent issues")
44}
45
46/// Fast validation path: parses and returns only syntax or structural errors
47/// without fully allocating the resulting AST tree.
48///
49/// # Arguments
50///
51/// * `input` - The raw JSON string slice to validate.
52///
53/// # Returns
54///
55/// A list of `Diagnostic` errors found in the input. If the input is valid JSON, this is empty.
56pub fn diagnostics(input: &str) -> Vec<Diagnostic> {
57    todo!("Fast diagnostics check will be implemented in subsequent issues")
58}
59
60#[cfg(test)]
61mod stub_tests {
62    use super::*;
63
64    #[test]
65    #[should_panic(expected = "not yet implemented")]
66    fn test_tolerant_parse_is_stub() {
67        tolerant_parse("{}");
68    }
69
70    #[test]
71    #[should_panic(expected = "not yet implemented")]
72    fn test_diagnostics_is_stub() {
73        diagnostics("{}");
74    }
75}