You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my pet project, i am parsing some context using syn-rsx, and trying to recreate part of token stream as input for other library. To recreate tokens i using quote!()\quote_spanned!() macros and found few problems:
Only few elements implement ToTokens, so i need to implement it manually in my wrappers.
Tokens that i hardcode and tokens from NodeElement semantically have different sites (call_site vs def_site vs mixed_site), and source file info, and if i understand correctly cannot be joined.
What do you think about modifying your implementation, so it will save original token stream inside struct
For example, instead of
pubstructNodeElement{/// Name of the element.pubname:NodeName,/// Attributes of the element node.pubattributes:Vec<Node>,/// Children of the element node.pubchildren:Vec<Node>,/// Source span of the element for error reporting.////// Note: This should cover the entire node in nightly, but is a "close/// enough" approximation in stable until [Span::join] is stabilized.pubspan:Span,}
The same approach is used in syn library itself. So the code will look more idiomatically.
It allows you to implement parser fully on type - TypeDD aproach makes contracts more visible.
You can implement syn::Parse just by going and init every field in struct
Allows you to implement ToTokens (Spanned will be derived from this method) without introducing mixed site.
Also, you don't need to implement your own TryFrom<Struct> for String because TokenStream could be converted to text directly. But you still be able to implement fn safe_html_text for important types
Downside:
Its a breaking change.
?Anything else
The text was updated successfully, but these errors were encountered:
Hi! First of all thanks for a great project!.
In my pet project, i am parsing some context using
syn-rsx
, and trying to recreate part of token stream as input for other library. To recreate tokens i usingquote!()\quote_spanned!()
macros and found few problems:ToTokens
, so i need to implement it manually in my wrappers.NodeElement
semantically have different sites (call_site vs def_site vs mixed_site), and source file info, and if i understand correctly cannot be joined.What do you think about modifying your implementation, so it will save original token stream inside struct
For example, instead of
You could have:
Benefits:
syn
library itself. So the code will look more idiomatically.syn::Parse
just by going and init every field in structToTokens
(Spanned will be derived from this method) without introducing mixed site.TryFrom<Struct> for String
becauseTokenStream
could be converted to text directly. But you still be able to implementfn safe_html_text
for important typesDownside:
The text was updated successfully, but these errors were encountered: