Skip to content

Commit 08c782d

Browse files
committed
WIP: Add doc for added properties
Sort `firstPotentialTokenKind` in alphabetical order
1 parent 4ef5eef commit 08c782d

File tree

3 files changed

+1017
-1003
lines changed

3 files changed

+1017
-1003
lines changed

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/IncrementalParseUtilsFile.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ let IncrementalParseUtilsFile = SourceFileSyntax(leadingTrivia: copyrightHeader)
2525
) {
2626
try VariableDeclSyntax(
2727
"""
28+
/// This property presents the first potential ``TokenSpec``s of all ``SyntaxKind``s
2829
@_spi(IncrementalParse)
2930
public var firstPotentialTokenKind: [TokenSpec]
3031
"""
@@ -33,7 +34,7 @@ let IncrementalParseUtilsFile = SourceFileSyntax(leadingTrivia: copyrightHeader)
3334

3435
for node in NON_BASE_SYNTAX_NODES {
3536
SwitchCaseSyntax("case .\(node.varOrCaseName):") {
36-
StmtSyntax("return [\(raw: Set(node.firstPotentialToken.map{$0.descriptionAsTokenSpec}).joined(separator: ", "))]")
37+
StmtSyntax("return [\(raw: Set(node.firstPotentialToken.map{$0.descriptionAsTokenSpec}).sorted().joined(separator: ", "))]")
3738
}
3839
}
3940
SwitchCaseSyntax("default:") {
@@ -44,6 +45,8 @@ let IncrementalParseUtilsFile = SourceFileSyntax(leadingTrivia: copyrightHeader)
4445

4546
try VariableDeclSyntax(
4647
"""
48+
/// This property presents children of nodes in the form of ``SyntaxKind``.
49+
/// All potential children kinds are listed in the internal array.
4750
@_spi(RawSyntax)
4851
public var syntaxLayout: [[SyntaxKind]]
4952
"""
@@ -71,6 +74,9 @@ let IncrementalParseUtilsFile = SourceFileSyntax(leadingTrivia: copyrightHeader)
7174
) {
7275
DeclSyntax(
7376
"""
77+
/// This property is used to calculate the next potential token
78+
/// of a ``Syntax``, which is essentially the next expected optional child of a node, and will be located by the last
79+
/// non-nil child of the node.
7480
public var nextPotentialTokenChoices: [TokenSpec] {
7581
if let children = self.layoutView?.children,
7682
let lastNonNilChildIdx = children.lastIndex(where: { $0 != nil }),

Sources/SwiftParser/Parser.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,15 +650,17 @@ extension Parser {
650650
}
651651

652652
func nodeCanBeReused(node: Syntax) -> Bool {
653+
var underlyingRaw = node.raw
654+
653655
var lookahead = self.lookahead()
654656
lookahead.lexemes.advance(by: node.byteSize, currentToken: &lookahead.currentToken)
655657

656658
let currentTokenSpec = PrepareForKeywordMatch(lookahead.currentToken)
657659

658660
if let codeBlockItem = node.as(CodeBlockItemSyntax.self) {
659-
return codeBlockItem.item.raw.nextPotentialTokenChoices.allSatisfy { !($0 ~= currentTokenSpec) }
661+
underlyingRaw = codeBlockItem.item.raw
660662
}
661663

662-
return node.raw.nextPotentialTokenChoices.allSatisfy { !($0 ~= currentTokenSpec) }
664+
return underlyingRaw.nextPotentialTokenChoices.allSatisfy { !($0 ~= currentTokenSpec) }
663665
}
664666
}

0 commit comments

Comments
 (0)