aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-seld-json-lint/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe-seld-json-lint/src')
-rw-r--r--crates/shirabe-seld-json-lint/src/lib.rs15
-rw-r--r--crates/shirabe-seld-json-lint/src/parsing_exception.rs45
2 files changed, 60 insertions, 0 deletions
diff --git a/crates/shirabe-seld-json-lint/src/lib.rs b/crates/shirabe-seld-json-lint/src/lib.rs
new file mode 100644
index 00000000..2165c8f2
--- /dev/null
+++ b/crates/shirabe-seld-json-lint/src/lib.rs
@@ -0,0 +1,15 @@
+//! Partial port of seld/jsonlint.
+//!
+//! The parser, lexer, and duplicate-key exception (`JsonParser`, `Lexer`,
+//! `DuplicateKeyException`) are intentionally not ported: JSON syntax validation now relies on
+//! serde_json, and duplicate-key detection is done with a hand-written serde visitor, so
+//! jsonlint's own parsing machinery is no longer needed.
+//!
+//! `ParsingException` is kept because it is the exception type thrown for invalid JSON and is
+//! matched (via downcast) across the codebase as an error-kind signal; it also carries detail
+//! such as the error line. Porting it keeps both the thrown exception class and the information
+//! it carries unchanged.
+
+pub mod parsing_exception;
+
+pub use parsing_exception::*;
diff --git a/crates/shirabe-seld-json-lint/src/parsing_exception.rs b/crates/shirabe-seld-json-lint/src/parsing_exception.rs
new file mode 100644
index 00000000..9d3eaa57
--- /dev/null
+++ b/crates/shirabe-seld-json-lint/src/parsing_exception.rs
@@ -0,0 +1,45 @@
+//! ref: composer/vendor/seld/jsonlint/src/Seld/JsonLint/ParsingException.php
+
+#[derive(Debug, Clone, Default)]
+pub struct ParsingExceptionLoc {
+ pub first_line: i64,
+ pub first_column: i64,
+ pub last_line: i64,
+ pub last_column: i64,
+}
+
+#[derive(Debug, Clone)]
+pub enum ParsingExceptionToken {
+ Name(String),
+ Symbol(i64),
+}
+
+#[derive(Debug, Clone, Default)]
+pub struct ParsingExceptionDetails {
+ pub text: Option<String>,
+ pub token: Option<ParsingExceptionToken>,
+ pub line: Option<i64>,
+ pub loc: Option<ParsingExceptionLoc>,
+ pub expected: Option<Vec<String>>,
+}
+
+#[derive(Debug)]
+pub struct ParsingException {
+ inner: shirabe_php_shim::Exception,
+ pub(crate) details: Box<ParsingExceptionDetails>,
+}
+
+impl ParsingException {
+ pub fn new(message: String, details: ParsingExceptionDetails) -> Self {
+ Self {
+ inner: shirabe_php_shim::Exception::new(message),
+ details: Box::new(details),
+ }
+ }
+
+ pub fn get_details(&self) -> &ParsingExceptionDetails {
+ &self.details
+ }
+}
+
+shirabe_php_shim::impl_php_exception!(ParsingException, inner, r"Seld\JsonLint\ParsingException");