Skip to content
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

Rewrite to operate on tokens #142

Closed
dtolnay opened this issue May 22, 2017 · 3 comments
Closed

Rewrite to operate on tokens #142

dtolnay opened this issue May 22, 2017 · 3 comments

Comments

@dtolnay
Copy link
Owner

dtolnay commented May 22, 2017

Using rust-lang/rust#40939 and proc-macro2. @​alexcrichton is working on this.

@mystor
Copy link
Collaborator

mystor commented May 26, 2017

I'm helping @alexcrichton with modifying the parser to run on TokenStream objects. My current unrebased branch is https://github.com/mystor/syn/tree/proc-macro2.

@dtolnay
Copy link
Owner Author

dtolnay commented May 26, 2017

I love both of you.

@mystor question about flatten_stream - it looks like this would be lossy right? If you have a TokenStream containing $a * 3 where the value of $a is 1 + 2, this would turn it into something that is indistinguishable from 1 + 2 * 3. (Not that we handle operator precedence anyway currently, but we will want to.) Any sense of how much harder it would be to support that correctly?

@mystor
Copy link
Collaborator

mystor commented May 26, 2017

@dtolnay Yes, flatten_stream is currently lossy, which is quite unfortunate. I don't know off of the top of my head what the best way to handle the None delimiter sequences.

As you can probably tell from my current WIP branch, I was trying to do the minimal number of changes to the rest of syn to get the parser to work built on top of proc-macro2. I imagine that any attempt to get None-delimited sequences working with precedence will require a reworking of that entire part of the parser, as well as a change to the synom input format, which I figured we would probably have to do separately (although potentially before 0.12 is released, depending on how long it takes to get the real proc-macro into nightly).

alexcrichton added a commit to alexcrichton/syn that referenced this issue May 26, 2017
This ended up being a bit larger of a commit than I intended! I imagine that
this'll be one of the larger of the commits working towards dtolnay#142. The purpose of
this commit is to use an updated version of the `quote` crate which doesn't work
with strings but rather works with tokens form the `proc-macro2` crate. The
`proc-macro2` crate itself is based on the proposed API for `proc_macro` itself,
and will continue to mirror it. The hope is that we'll flip an easy switch
eventually to use compiler tokens, whereas for now we'll stick to string parsing
at the lowest layer.

The largest change here is the addition of span information to the AST. Building
on the previous PRs to refactor the AST this makes it relatively easy from a
user perspective to digest and use the AST still, it's just a few extra fields
on the side. The fallout from this was then quite large throughout the
`printing` feature of the crate. The `parsing`, `fold`, and `visit` features
then followed suit to get updated as well.

This commit also changes the the semantics of the AST somewhat as well.
Previously it was inferred what tokens should be printed, for example if you
have a closure argument `syn` would automatically not print the colon in `a: b`
if the type listed was "infer this type". Now the colon is a separate field and
must be in sync with the type listed as the colon/type will be printed
unconditionally (emitting no output if both are `None`).
alexcrichton added a commit to alexcrichton/syn that referenced this issue May 26, 2017
This ended up being a bit larger of a commit than I intended! I imagine that
this'll be one of the larger of the commits working towards dtolnay#142. The purpose of
this commit is to use an updated version of the `quote` crate which doesn't work
with strings but rather works with tokens form the `proc-macro2` crate. The
`proc-macro2` crate itself is based on the proposed API for `proc_macro` itself,
and will continue to mirror it. The hope is that we'll flip an easy switch
eventually to use compiler tokens, whereas for now we'll stick to string parsing
at the lowest layer.

The largest change here is the addition of span information to the AST. Building
on the previous PRs to refactor the AST this makes it relatively easy from a
user perspective to digest and use the AST still, it's just a few extra fields
on the side. The fallout from this was then quite large throughout the
`printing` feature of the crate. The `parsing`, `fold`, and `visit` features
then followed suit to get updated as well.

This commit also changes the the semantics of the AST somewhat as well.
Previously it was inferred what tokens should be printed, for example if you
have a closure argument `syn` would automatically not print the colon in `a: b`
if the type listed was "infer this type". Now the colon is a separate field and
must be in sync with the type listed as the colon/type will be printed
unconditionally (emitting no output if both are `None`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants