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.
Description
POC for preserving comments in Cadence AST. When complete, this should enable us to make a fully working a pretty printer for Cadence.
This is a follow-up to my discussion in Discord some time ago: https://discord.com/channels/613813861610684416/1108479699732152503/1240749220357607475
Closes onflow#308
Design
I decided to start tracking trivia tokens in the form of leading/trailing trivia structs attached to Token's as discussed in onflow#308 (comment).
I believe this could simplify some parsing logic, as the lexer already computes which tokens are associated with which comments + it removes the need to skip comments when parsing.
At the AST level, I added leading/trailing comments fields to some AST nodes. The other trivia types such as spaces or newlines are just discarded for now, as I don't think we'd need them. Maybe that also means we don't even need to track them at the lexer level, but I still think that is a good think for checking correctness in unit testing if nothing else.
Note that I've currently implemented this only for FunctionDeclaration and Block AST nodes, but I'll keep expanding that to other AST nodes.
Notes
TODO(preserve-comments)
in codeDefinition of Done
Description
master
branchFiles changed
in the Github PR explorer