Skip to content

Commit a7e74ca

Browse files
committed
Move types that are not syntax node related to separate file Misc.swift.gyb
1 parent bffcd8c commit a7e74ca

File tree

6 files changed

+1410
-1370
lines changed

6 files changed

+1410
-1370
lines changed

Sources/SwiftSyntax/Misc.swift.gyb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
%{
2+
# -*- mode: Swift -*-
3+
from gyb_syntax_support import *
4+
from gyb_syntax_support.Traits import TRAITS
5+
NODE_MAP = create_node_map()
6+
# Ignore the following admonition it applies to the resulting .swift file only
7+
}%
8+
//// Automatically Generated From SyntaxNodes.swift.gyb.
9+
//// Do Not Edit Directly!
10+
//===------------ SyntaxNodes.swift - Syntax Node definitions -------------===//
11+
//
12+
// This source file is part of the Swift.org open source project
13+
//
14+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
15+
// Licensed under Apache License v2.0 with Runtime Library Exception
16+
//
17+
// See https://swift.org/LICENSE.txt for license information
18+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
19+
//
20+
//===----------------------------------------------------------------------===//
21+
22+
import _InternalSwiftSyntaxParser
23+
24+
extension SyntaxNode {
25+
public var isUnknown: Bool { return raw.kind.isUnknown }
26+
public var asUnknown: UnknownSyntax? {
27+
guard isUnknown else { return nil }
28+
return UnknownSyntax(asSyntaxData)
29+
}
30+
% for node in SYNTAX_NODES:
31+
% if not node.is_base():
32+
33+
public var is${node.syntax_kind}: Bool { return raw.kind == .${node.swift_syntax_kind} }
34+
public var as${node.syntax_kind}: ${node.name}? {
35+
guard is${node.syntax_kind} else { return nil }
36+
return ${node.name}(asSyntaxData)
37+
}
38+
% end
39+
% end
40+
}
41+
42+
extension SyntaxParser {
43+
static func verifyNodeDeclarationHash() -> Bool {
44+
return String(cString: swiftparse_syntax_structure_versioning_identifier()!) ==
45+
"${calculate_node_hash()}"
46+
}
47+
}

Sources/SwiftSyntax/SyntaxNodes.swift.gyb

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
//
2020
//===----------------------------------------------------------------------===//
2121

22-
import _InternalSwiftSyntaxParser
23-
2422
%{
2523
"""
2624
Each Syntax node implements the protocol of a more generic node. For example,
@@ -44,6 +42,7 @@ Each node will have:
4442
% # Handled in SyntaxNodesBase.swift.gyb
4543
% pass
4644
% elif node.collection_element:
45+
% # Handled in SyntaxCollections.swift.gyb
4746
% pass
4847
% else:
4948

@@ -212,28 +211,3 @@ extension ${node.name}: CustomReflectable {
212211
}
213212
% end
214213
% end
215-
216-
extension SyntaxNode {
217-
public var isUnknown: Bool { return raw.kind.isUnknown }
218-
public var asUnknown: UnknownSyntax? {
219-
guard isUnknown else { return nil }
220-
return UnknownSyntax(asSyntaxData)
221-
}
222-
% for node in SYNTAX_NODES:
223-
% if not node.is_base():
224-
225-
public var is${node.syntax_kind}: Bool { return raw.kind == .${node.swift_syntax_kind} }
226-
public var as${node.syntax_kind}: ${node.name}? {
227-
guard is${node.syntax_kind} else { return nil }
228-
return ${node.name}(asSyntaxData)
229-
}
230-
% end
231-
% end
232-
}
233-
234-
extension SyntaxParser {
235-
static func verifyNodeDeclarationHash() -> Bool {
236-
return String(cString: swiftparse_syntax_structure_versioning_identifier()!) ==
237-
"${calculate_node_hash()}"
238-
}
239-
}

0 commit comments

Comments
 (0)