1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::{json, jsx, shared::sp};
use nom::{
branch::alt,
combinator::{map, opt},
error::ParseError,
sequence::delimited,
IResult,
};
use serde::{Serialize, Serializer};
#[derive(Debug, PartialEq, Clone)]
pub enum JsxnValue {
JsxValue(jsx::JsxValue),
JsonValue(json::JsonValue),
}
impl Serialize for JsxnValue {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
JsxnValue::JsxValue(json_value) => json_value.serialize(serializer),
JsxnValue::JsonValue(jsx_value) => jsx_value.serialize(serializer),
}
}
}
pub fn root<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, JsxnValue, E> {
delimited(
sp,
alt((
map(json::root, JsxnValue::JsonValue),
map(jsx::root, JsxnValue::JsxValue),
)),
opt(sp),
)(i)
}