Skip to content

Conversation

@alexcrichton
Copy link
Collaborator

@alexcrichton alexcrichton commented May 16, 2018

Depends on dtolnay/quote#73
Depends on dtolnay/proc-macro2#90
Depends on a new nightly

@alexcrichton
Copy link
Collaborator Author

This is very much a WIP and not a final state, I'm about to be tied up in meetings for a few hours though and wanted to post progress. If anyone would like to take over and/or pile on, feel free!

@alexcrichton
Copy link
Collaborator Author

Ok the whole crate is now building, tests have yet to be updated

src/synom.rs Outdated

impl Synom for proc_macro2::Ident {
fn parse(input: Cursor) -> PResult<Self> {
input.term().ok_or_else(|| ParseError::new("not an ident"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like this to preserve the behavior of 0.13's impl Synom for Ident. Separately we will need some way to do https://docs.rs/syn/0.13/syn/struct.Ident.html#method.parse_any.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out this was required! Otherwise expressions were parsed very weirdly

src/synom.rs Outdated
}

fn description() -> Option<&'static str> {
Some("arbitrary token stream")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Some("identifier").

@alexcrichton
Copy link
Collaborator Author

Ok that might be everything, let's see what CI says...

@alexcrichton
Copy link
Collaborator Author

Ok it looks like the last failure is 1.15.1 but that's just because it doesn't understand [patch] and should be fixable with a new release of quote

// parse them, so we ignore them here.
for name in IGNORED_MODS {
if item.ident == name {
if item.ident.to_string() == *name {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened dtolnay/proc-macro2#92 to avoid these changes.

src/lifetime.rs Outdated
fn to_tokens(&self, tokens: &mut Tokens) {
self.term.to_tokens(tokens);
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Punct::new('\'', Spacing::Joint));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This token needs to be stored in the Lifetime struct so that we preserve its Span correctly.

/// give_away(ident_string);
///
/// fn give_away(s: String) { /* ... */ }
/// ```
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is valuable explanation and examples being removed here. Compare:

Any thoughts on how to provide Syn-specific Ident documentation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm I wonder if we could just wholesale move the documentation to proc_macro2::Ident?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I moved this to proc-macro2 in dtolnay/proc-macro2@8b71dac.

/// Parses any identifier
///
/// This is useful when parsing a DSL which allows Rust keywords as identifiers.
pub fn parse_any(input: Cursor) -> PResult<Self> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep some way of doing this. This was added recently in #424.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a new macro parser in synom, like any_ident!()?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented this as an extension trait in fe68c90.

# [ cfg ( any ( feature = "full" , feature = "derive" ) ) ]
fn fold_generics(&mut self, i: Generics) -> Generics { fold_generics(self, i) }

fn fold_ident(&mut self, i: Ident) -> Ident { fold_ident(self, i) }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep fold_ident.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops didn't even realize that went away

@dtolnay
Copy link
Owner

dtolnay commented May 18, 2018

I can't comment on it directly but please remove the tests/rust submodule added in this PR. IIRC we used to have it but it slows down Cargo git dependencies on Syn.

@SergioBenitez
Copy link
Contributor

What's holding this back?

@dtolnay
Copy link
Owner

dtolnay commented May 20, 2018

I think we are mostly waiting for @Eijebong to wrap up work on servo/servo#20497 so that the timing can be maximally bad.

After that, docs need updating, we need some design work around how to handle what used to be Ident::parse_any, and I would like to get serde_derive updated before publishing so that we understand practical implications of the changes. If you have bandwidth to help, the best thing would be to make a PR for Serde with some [patch.crates-io] dependencies on this branch.

@dtolnay dtolnay merged commit 857e7e7 into dtolnay:master May 21, 2018
@alexcrichton alexcrichton deleted the next branch May 21, 2018 02:34
@dtolnay
Copy link
Owner

dtolnay commented May 21, 2018

Serde update: serde-rs/serde#1273

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

Successfully merging this pull request may close these issues.

3 participants