-
-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add From<Span> for all tokens #279
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
As a general rule in the standard library we have tried to always associate conversions with the most specific type involved -- whichever one provides some additional invariant or interpretation that is not present in the other type. For example str is more specific then &[u8] since it is a UTF-8 encoded sequence of bytes. Thus str provides both the as_bytes
method and the from_utf8
constructor for converting to and from &[u8] values.
In syn we have token which is more specific than Span, and Ident which is more specific than Span, so I would prefer to associate constructing tokens and idents with those types rather than associating it with Span.
The keyword tokens are already easy to create from a Span: for example Else(span)
. For the punctuation tokens which hold an array of spans I added a new
constructor: for example AddEq::new(span)
. And for Ident there is Ident::new("value", span)
. Could you take another look and let me know whether anything still needs to be improved?
I'm happy with Ident::new(), but I'm not sure if Else(span) is better. For example, rustc fails to resolve module if span from function body is used in |
@mystor could you take a look and recommend a path forward? Thanks! |
IMHO, it's similar to While creating pr, I completely forgot why I chose |
I would be on board with providing |
I'll do it soon. |
I did it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I published this in syn 0.12.5. |
Fixes #278.