-
Notifications
You must be signed in to change notification settings - Fork 440
Improve modeling of Child
in CodeGeneration
#1289
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
Improve modeling of Child
in CodeGeneration
#1289
Conversation
@swift-ci Please test |
case .token(choices: let choices): | ||
if choices.count == 1 { | ||
switch choices.first! { | ||
case .keyword(text: _): return "KeywordToken" |
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.
Could text also be replaced with _
6208ab4
to
2467d12
Compare
@swift-ci Please test |
@@ -81,14 +66,11 @@ public let AVAILABILITY_NODES: [Node] = [ | |||
kind: "Syntax", | |||
children: [ | |||
Child(name: "Platform", | |||
kind: "IdentifierToken", | |||
kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), | |||
description: "The name of the OS on which the availability should berestricted or 'swift' if the availability should berestricted based on a Swift version.", |
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'm not actually sure what these are used for. But it appears we're not adding a space when we drop the newlines and indentation (separate to this PR, just noticed 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.
What exactly do you mean?
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 name of the OS on which the availability should berestricted or 'swift' if the availability should berestricted based on a Swift version."
Note the two "berestricted". This is coming from the python where it's defined as a multiline string. But the lines are being joined as is (well, with indentation removed), without a space separator.
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.
Oh, I see, this wasn’t related to the line I changed.
Interesting that I haven’t noticed this before. I fixed it now.
# This will force validation logic to check the text passed into the | ||
# token against the choices. | ||
self.text_choices = text_choices or [] | ||
self.token_choices.append((token, choice_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.
Is there a case where token != KeywordToken
and kind != KeywordToken
? Can't we just check/use kind
instead?
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 exactly are you suggesting? Also, this is going to be removed in a month or so anyway when all gyb files are migrated to CodeGeneration so maybe it doesn’t matter too much anyway.
2467d12
to
8984572
Compare
…Generation # Conflicts: # CodeGeneration/Sources/SyntaxSupport/gyb_generated/AttributeNodes.swift # CodeGeneration/Sources/SyntaxSupport/gyb_generated/AvailabilityNodes.swift # CodeGeneration/Sources/SyntaxSupport/gyb_generated/DeclNodes.swift
@swift-ci Please test |
@swift-ci please test macOS |
@swift-ci Please test macOS |
Instead of having
tokenChoices
,textChoices
,nodeChoices
andcollectionElementName
inChild
, which are all pretty much mutually exclusive with each other, model the kind of a child as an enum that be either ofThe syntax in the Python definition files is a little awkward with this because you specify keywords e.g. as
Keyword|async
but since I anticipate that they will soon be gone anyway once we've moved all code generation to use SwiftSyntaxBuilder, I don't think we need to put too much effort into making the Python files look nice.This is a prerequisite for #1180, which will assert that tokens in a syntax tree match the specified token kind and text choices.