Could not find easily a json serializer of rust asts. Maybe you know of one?
I am working on a json serializer of the syn parser to not only dump in debug mode but in a parsable json serde. Syn uses proc_macro2 which uses proc_macro which uses compiler internals. I have the feeling that fallback in proc_macro2 might provide the non-native impl but my rust skills are still not up to speed. Can you help me find or implement json serde for the proc_macro internals like TokenStream,Token, and Identifier that use internal structures?
Here is the first version of the json output with the missing identifiers
Here is the change to the syn to dump out the data Feature/json serde by jmikedupont2 · Pull Request #1 · meta-introspector/syn · GitHub
The updated version implements the to_serialize
pub fn serialize_ident<S>(ident: &proc_macro2::Ident, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let str_repr = ident.to_string();
serializer.serialize_str(&str_repr)
}
and used like this
#[serde(serialize_with = "crate::serialize::serialize_ident")]
pub ident: Ident,
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.