Refactor to fully tokenize before formatting #530
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.
We've been dealing with limitations from incomplete parsing (#200) for ages.
Instead attempting full parsing, this change only tokenizes fully before starting formatting. This should open the door to simplifying parsing and formatting rules.
For example, to find an object literal currently, we have to check repeatedly later on for a matching pattern. With this change we could determine as a block is opened whether to treat it as on object-literal or not (for features like #114, #315, #370).
Next steps could also include cleaning up the factoring for the recognizers for each token, adding a parse-ish pass, and refactoring the beautification rules to make use of the information now available to them.
@evocateur, @einars - please take a look when you have a chance. Any feedback welcome.