Skip to content

Commit 8a30b2d

Browse files
committed
Moved NodeInitRule into a separate file
1 parent 17fbad3 commit 8a30b2d

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

CodeGeneration/Sources/SyntaxSupport/Node.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public class Node {
6363
return kind.varOrCaseName
6464
}
6565

66-
/// List of convenience initializer rules for this node.
66+
/// List of convenience initializer rules for this node. CodeGeneration will
67+
/// generate a convenience initializer for each rule.
6768
public let rules: [NodeInitRule]
6869

6970
/// If this is a layout node, return a view of the node that provides access
@@ -127,10 +128,6 @@ public class Node {
127128
self.nameForDiagnostics = nameForDiagnostics
128129
self.documentation = docCommentTrivia(from: documentation)
129130
self.parserFunction = parserFunction
130-
131-
132-
// FIXME: We should validate rules and check that all referenced children
133-
// elements in fact exist on that node.
134131
self.rules = rules
135132

136133
let childrenWithUnexpected: [Child]
@@ -391,8 +388,3 @@ fileprivate extension Child {
391388
fileprivate extension Node {
392389

393390
}
394-
395-
public struct NodeInitRule {
396-
public let nonOptionalChildName: String
397-
public let childDefaultValues: [String: Token]
398-
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import Foundation
14+
import SwiftSyntax
15+
16+
/// A rule that describes convenienve initialization rules for a ``Node``.
17+
///
18+
/// When generating syntax nodes, SwiftSyntax will make additional
19+
/// convenience initializer for each rule that a Node has.
20+
///
21+
/// The convenience initializer will take a non-optional parameter
22+
/// `nonOptionalChildName`, and when a non-optional value is passed, it'll call
23+
/// the full memberwise initializer with the provided `childDefaultValues`.
24+
///
25+
/// For example, when initializing an `EnumCaseParameterSyntax`, the convenience
26+
/// initializer will take a non-optional `firstName` parameter, and when it's
27+
/// passed, it'll call the full memberwise initializer with
28+
/// `colon = .colonToken()`.
29+
public struct NodeInitRule {
30+
/// The name of the parameter that is required to be present for
31+
/// this conveniece initializer rule to apply.
32+
public let nonOptionalChildName: String
33+
34+
/// A dicrionary of parameter names to their respective default values
35+
/// to apply when the `nonOptionalChildName` is passed as concrete value.
36+
public let childDefaultValues: [String: Token]
37+
}

0 commit comments

Comments
 (0)