lintel_validate/parsers/
json5.rs1use miette::NamedSource;
2use serde_json::Value;
3
4use crate::diagnostics::ParseDiagnostic;
5
6use super::Parser;
7
8pub struct Json5Parser;
9
10impl Parser for Json5Parser {
11 fn parse(&self, content: &str, file_name: &str) -> Result<Value, ParseDiagnostic> {
12 ::json5::from_str(content).map_err(|e| {
13 let offset = e.position().map_or(0, |pos| {
14 super::line_col_to_offset(content, pos.line + 1, pos.column + 1)
15 });
16 ParseDiagnostic {
17 src: NamedSource::new(file_name, content.to_string()),
18 span: offset.into(),
19 message: e.to_string(),
20 }
21 })
22 }
23
24 fn annotate(&self, content: &str, schema_url: &str) -> Option<String> {
25 Some(super::annotate_json_content(content, schema_url))
26 }
27
28 fn strip_annotation(&self, content: &str) -> String {
29 super::strip_json_schema_property(content)
30 }
31}