goffrie / plex

a parser and lexer generator as a Rust procedural macro
Apache License 2.0
410 stars 28 forks source link

Hacky unit/tuple variant fix #10

Closed kivikakk closed 7 years ago

kivikakk commented 7 years ago

I don't love this 'solution' at all and feel free to just ditch this, but it's some food for thought, anyway. I couldn't work out a way to include some out-of-band information about the identifier so that we could pick it up in the to_pat stage, because all we have there is the table and no way to get back to the specific rule/action, so I just shoved it into the identifier itself.

I probably missed something obvious. I'm also a total noob to Rust, so my style may be grade A Awful — any critique is appreciated, and I also understand if you don't have the time for this. :)

Refs #9.

goffrie commented 7 years ago

Thanks for looking at this! I went ahead and fixed the issue myself --- see 8632645a9fef06bc75bbf8600c42c22e4560e327. The idea here is that lr1_machine is generic over the type T of terminals, so we can change its type to a struct that records both the identifier and whether it is a unit-like variant.

kivikakk commented 7 years ago

That's way better. I didn't even realise it was generic over the terminal until it came to writing 63dbbb5, but by then I was too far into my solution to see how that might make a much better result.

Thank you for the learning experience! 🙇🏼‍♀️