-
Notifications
You must be signed in to change notification settings - Fork 439
Generate grammar doc comments for layout nodes #1771
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 |
Cool stuff, interesting idea! I'm not convinced it's worth having both grammar + children though. In general children seems more useful to me. Do you have any examples where you'd consider the "grammar" as better than children? Right now they're basically duplicates, with children having the advantage of having the name as well. |
### Children | ||
|
||
\(GrammarGenerator.childrenList(for: children)) |
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.
The list of children should already be visible through DocC, under the type/protocol's Instance Properties section. Does it really need to be repeated in the main description 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 it does because these are sorted in source order while the Instance Properties are sorted alphabetically.
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.
OK I think this is a valid reason. Although, maybe in the long term we should have the ability to specify to DocC the ordering of properties.
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, if we could do that, I agree that we might be able to remove the children list.
/// (``AttributeSyntax`` | ``IfConfigDeclSyntax``) `*` | ||
/// ``DeclModifierSyntax``? | ||
/// (`'get'` | `'set'` | `'didSet'` | `'willSet'` | `'unsafeAddress'` | `'addressWithOwner'` | `'addressWithNativeOwner'` | `'unsafeMutableAddress'` | `'mutableAddressWithOwner'` | `'mutableAddressWithNativeOwner'` | `'_read'` | `'_modify'` | `'init'`) | ||
/// ``AccessorParameterSyntax``? | ||
/// ``AccessorEffectSpecifiersSyntax``? | ||
/// ``AccessorInitEffectsSyntax``? | ||
/// ``CodeBlockSyntax``? |
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.
Is there a way to generate the translation between the type/protocol names and the actual grammar terms/components that they represent? I think having such a translation table can help a lot to contributors.
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.
What do you mean by “actual grammar terms/components that they represent”?
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 might be misunderstanding it. What I mean is: it seems to me that not all syntax nodes in the parser correlate one-to-one with the syntax nodes as documented in TSPL.
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.
No, there isn’t always a 1:1 correlation between the SwiftSyntax nodes and the grammar rules in TSPL.
private func grammar(for tokenChoice: TokenChoice) -> String { | ||
switch tokenChoice { | ||
case .keyword(text: let text): | ||
return "`'\(text)'`" |
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 feel having quotation marks within the code voice makes it a bit ambiguous what the token actually is.
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.
My idea here was to optimize this for rendering in docc and I found that rendering the token name in code voice reads a little nicer in docc. Would you prefer to just use
return "'\(text)'"
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, I think I would prefer just return "'\(text)'"
or return "`\(text)`"
. And if the latter is used, syntactic categories can be italicized like in TSPL, to differentiate from token texts.
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.
The thing is that we use docc links for links to other syntactic categories, which are always monospaced.
The documentation for StructDeclSyntax shows all kinds of references. Which fonts would you use here?
.joined(separator: "\n") | ||
} | ||
|
||
/// Generates a |
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.
Incomplete doc comment. Should be "/// Generates a list of child nodes"?
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.
Good catch. Thank you
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.
Thanks for this. I think this is a good approach in general. I have just some nitpicky-ish comments.
1e8152f
to
dc058cd
Compare
My idea was that in particular for simple nodes, the grammar shows the structure of the node in a very nice and concise form. But looking at other nodes as well, I agree that it very much breaks down for more complex nodes. @WowbaggersLiquidLunch Do you have opinions on just showing the ![]() |
dc058cd
to
1669a5f
Compare
OK, I removed the Grammar section and we’re just left with Children now. That seems to be cleaner. |
@swift-ci Please test |
@swift-ci Please test Windows |
1669a5f
to
d868b0d
Compare
@swift-ci Please test |
.joined(separator: "\n") | ||
} | ||
|
||
/// Generates a |
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.
Got half way through :)?
Generate a `Grammar` and a `Children` section as doc-comments for layout nodes. The `Grammar` section is particularly useful for fairly simple syntax nodes to convey their structure. The `Children` section allows you to see the children of the syntax node at a glance in the source order.
d868b0d
to
9b128ec
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
Sorry for the late response. I still think it's better to have the Grammar section. It's probably a bit more clutter, but from my experience, having the grammar documented really helps new contributors find the relevant things to modify. Although, instead of "'await' Additionally something I just noticed: Currently the grammars are documented on the |
Which information do you think would be valuable in the Grammar section that’s not present in the Children section?
To be clear: There is a difference between SwiftSyntax and TSPL, just by the way the trees are structured. For example, if we wanted to model the following production rules in SwiftSyntax,
So, there is not equivalent of the
production rule or await-operator in SwiftSyntax, so I don’t think there’s a natural way to place it.
Since the grammar rules on the |
Generate a
Grammar
and aChildren
section as doc-comments for layout nodes.The
Grammar
section is particularly useful for fairly simple syntax nodes to convey their structure. TheChildren
section allows you to see the children of the syntax node at a glance in the source order.