swiftlang / swiftlang/swift-syntax

Improve modeling token nodes

Open
#2,010 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Swift
Stars
3.7k
Forks
553
Avg merge
5d 13h
Merged PRs (30d)
16

Description

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 https://github.com/apple/swift-syntax/pull/2006#discussion_r1285082312_

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.