-
Notifications
You must be signed in to change notification settings - Fork 145
[WIP] Retain comments in AST #3509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
turbolent
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Had another pass through the code with some suggestions. Will review the tests next
| }, | ||
| }, | ||
| Source: "*/", | ||
| Source: "\000", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come the source is the null character here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
Co-authored-by: Bastian Müller <[email protected]>
…ence into preserve-comments
# Conflicts: # ast/parameterlist.go
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