-
Notifications
You must be signed in to change notification settings - Fork 440
Add ability to attach leading trivia directly to buildable nodes #475
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
Conversation
@swift-ci please test |
I like the API. Clean and easy to understand 👏 Was wondering if it would make sense to add a single test that tests if we combine the leading VariableDecl(
leadingTrivia: .newlines(1) + .docLineComment("/// The `open` contextual token") + .newlines(1),
modifiers: [TokenSyntax.static.withLeadingTrivia(.newlines(1) )],
letOrVarKeyword: .var
) |
@swift-ci please test |
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.
Yes, this really improves readability of TokensFile.swift 👍
${',\n '.join(delegated_init_args)} | ||
) | ||
} | ||
% end | ||
|
||
func build${type.base_name()}(format: Format, leadingTrivia: Trivia? = nil) -> ${type.syntax()} { | ||
func build${type.base_name()}(format: Format, leadingTrivia additionalLeadingTrivia: Trivia? = nil) -> ${type.syntax()} { |
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.
Since we are defaulting to ?? []
should we not add it 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.
Yeah, I think that's a good idea. I kept it optional to be consistent with the other build-methods, should those be refactored too?
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 the SyntaxBuildable
protocol (and its related subprotocols) currently require this to be optional, so we'd have to refactor that (which might be a larger change).
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 would suggest that we keep it as-is for now and could consider refactoring it to be non-optional in a follow-up PR.
- Simplify leading trivia attachment in syntax-building method - Add some doc comments regarding leading trivia on buildable nodes - Add test case for leading trivia to verify that it is combined correctly
a2e5bc9
to
70f46d2
Compare
@swift-ci please test |
Based on #474.
This branch adds the ability to attach leading trivia directly to
BuildableNodes
as a parameter/attribute (currently this can only be done by passing it as a parameter directly to the build syntax method), thereby addressing the points outlined here. This is particularly convenient inTokensFile
, where we can now attach doc comments directly to the nodes:rather than having to modify the first token (as done currently):
thereby making the DSL more readable and more aligned with the actual generated code.
cc @ahoppen @kimdv