Skip to content

Improve modeling token nodes #2010

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

Open
Matejkob opened this issue Aug 5, 2023 · 1 comment
Open

Improve modeling token nodes #2010

Matejkob opened this issue Aug 5, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@Matejkob
Copy link
Contributor

Matejkob commented Aug 5, 2023

With @ahoppen we identified potential confusion and overcomplication in code relating to modeling token nodes. Specifically, we're currently trying to collapse multiple token kinds into a single one without indicating this in our variable names.

The only non-trivial place that needs to be updated is Child.type in SyntaxBuildableChild and, IMHO, the confusion stems from the fact that we try to collapse multiple token kinds into a single one without giving any indication of doing so in the variable names.

I think the way to go about fixing this is to change the associated value of SyntaxOrTokenNodeKind.token to [TokenChoice]. Then we won’t need to call Child.tokenKind in Child.type anymore and could shift the computation that’s currently done in this property down to uses where there’s a lot more context. Potentially, the computation might also just become a lot simpler once we see that context.

Originally posted by @ahoppen in #2006 (comment)

In relation to issue #1978, changes were made in PR #2006 to the Child.tokenKind implementation. However, this solution still appears to be incorrect and needs further attention, which this issue aims to address.

@ahoppen
Copy link
Member

ahoppen commented Aug 8, 2023

Tracked in Apple’s issue tracker as rdar://113567645

AppAppWorks added a commit to AppAppWorks/swift-syntax that referenced this issue Sep 6, 2024
… sides

fixed that the type of node choices property was generated as `RawSyntax`
fixed swiftlang#2010
fixed `Trivia.isBlank`

introduced `SyntaxNodeConvertible`, `ParameterConvertible` and `NodeChoiceConvertible`
introduced a raw representation for each of `Node` and `Child`
coupled `baseKind` with `SyntaxNodeKind` rather than `Node`
removed redundant @_spi(RawSyntax)
replaced the overloading of `SyntaxNodeKind?` with a descriptive enum used
added `syntaxTypeNameWithLeadingUnderscoresDropped` to `Node`
added `nameInProperCase` and `deprecatedNameInProperCase` to `Child`
made `ChildNodeChoices.Choice` a facade of `NodeChoiceConvertible`
promoted `isDeprecated` to `TypeConvertible`
replaced `SyntaxNodeKind.XXX` with `Node.XXX` or `Child.XXX` whenever possible
AppAppWorks added a commit to AppAppWorks/swift-syntax that referenced this issue Sep 6, 2024
… sides

fixed that the type of node choices property was generated as `RawSyntax`
fixed swiftlang#2010
fixed `Trivia.isBlank`

introduced `SyntaxNodeConvertible`, `ParameterConvertible` and `NodeChoiceConvertible`
introduced a raw representation for each of `Node` and `Child`
coupled `baseKind` with `SyntaxNodeKind` rather than `Node`
removed redundant @_spi(RawSyntax)
replaced the overloading of `SyntaxNodeKind?` with a descriptive enum used
added `syntaxTypeNameWithLeadingUnderscoresDropped` to `Node`
added `nameInProperCase` and `deprecatedNameInProperCase` to `Child`
made `ChildNodeChoices.Choice` a facade of `NodeChoiceConvertible`
promoted `isDeprecated` to `TypeConvertible`
replaced `SyntaxNodeKind.XXX` with `Node.XXX` or `Child.XXX` whenever possible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants