Draft
Conversation
This was referenced Aug 4, 2024
turbolent
reviewed
Nov 21, 2025
Member
turbolent
left a comment
There was a problem hiding this comment.
Great work! Had another pass through the code with some suggestions. Will review the tests next
| }, | ||
| }, | ||
| Source: "*/", | ||
| Source: "\000", |
Member
There was a problem hiding this comment.
How come the source is the null character here?
Author
There was a problem hiding this comment.
I think this is expected, since the error occurs at EOF (which doesn't have a position within the source code) - added a clarifying comment now.
The EOF token has the same source, but its just not checked, in unit tests: https://github.com/bartolomej/cadence/blob/43b4adf252468a0580c0adc635c7715d956777e2/parser/lexer/lexer_test.go#L74-L81
Do you think null source for error tokens could cause any unexpected issues downstream?
…ence into preserve-comments
Co-authored-by: Bastian Müller <bastian@turbolent.com>
Co-authored-by: Bastian Müller <bastian@turbolent.com>
turbolent
reviewed
Nov 24, 2025
turbolent
reviewed
Nov 24, 2025
…ence into preserve-comments
# Conflicts: # ast/parameterlist.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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. This should enable us to make a fully working, 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 #308
Design
I decided to start tracking comments in the form of leading/trailing comment structs attached to lexer tokens and AST nodes as discussed in #308 (comment).
I believe this approach (instead of the old one where comments were tracked as AST nodes) could simplify comment parsing logic, as the lexer already computes which tokens are associated with which comments + it removes the need to skip comments when parsing.
Notes
TODO(preserve-comments)in codeDefinition of Done
TODOs
Description
masterbranchFiles changedin the Github PR explorer