Refactor lrlex codegen using quote #503
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here is my first attempt to do a more holistic refactoring of the code gen of lrlex using the Quote library.
When using the string formatting, we generate the code from top-down.
When using quote it takes a more inside-out approach generating the module contents, or a functions block, then plugging that in place.
In particular I tried to organize it such that we reduce the number of variables in scope.
So the
lexerdeffunction impl block is generated over few blocks of code with only those variables in scope when they are needed. We could reduce that down to e.g. generating the function impl over a single block, but it increases the number of variables in scope and there is quite a few because of thelex_flags.I don't really have a preference both choices seemed like a trade-off to me.