lukaslueg / macro_railroad

A library to generate syntax diagrams for Rust macros.
MIT License
529 stars 11 forks source link

rewrite parser to use syn 0.15 #18

Closed jmhain closed 5 years ago

jmhain commented 5 years ago

Saw the call for participation on TWIR for issue #17, so decided to give it a shot. Passes tests, but seems to be slower than the current syn 0.14-based parser.

lukaslueg commented 5 years ago

Thanks for the PR!

The following macro should produce two literals ' and a, yet the new parser seems to skip the ' and only produces one literal a. Could you look into this?

macro_rules! a { ('a) => { ... }; }
jmhain commented 5 years ago

The following macro should produce two literals ' and a, yet the new parser seems to skip the ' and only produces one literal a. Could you look into this?

Yeah, it looks like syn stopped parsing ' as a Punct, and instead only as part of a lifetime. Added a commit with a workaround.

Edit Actually I just realized the fix isn't technically what you asked for since it now produces one literal 'a (instead of dropping the '), rather than two separate literals. Not sure if this matters...

lukaslueg commented 5 years ago

@jmhain thanks for the changes; @dtolnay your input is appreciated.

lukaslueg commented 5 years ago

'a should be parsed at one Literal as whitespace in between is not allowed. E.g. <'a> in the macro_rules!() can be matched by < 'a >, <'a >, < 'a> but not <' a>.

lukaslueg commented 5 years ago

I've reviewed this and I'd like to go with @dtolnay 's PR, which seems more close to how syn was designed for. @jmhain thanks very much for this PR, I know it's frustrating if a PR does not get pulled. I'd highly appreciate if you could tackle the remaining problems with the Parser, the multi-character Punct being the most pressing.