Skip to content

Commit 5f45659

Browse files
committed
More clean up
1 parent eb61324 commit 5f45659

15 files changed

Lines changed: 403 additions & 262 deletions

Sources/SyntaxParser/TokenVisitor/NodeFactory.swift

Lines changed: 0 additions & 72 deletions
This file was deleted.

Sources/SyntaxParser/TokenVisitor/SyntaxClassifiable.swift

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -38,60 +38,3 @@ internal protocol SyntaxClassifiable {
3838
/// Returns the semantic classification of this syntax node type.
3939
static var syntaxType: SyntaxType { get }
4040
}
41-
42-
/// Utility for classifying Swift syntax nodes and cleaning type names.
43-
///
44-
/// SyntaxClassifier provides semantic classification of syntax elements and
45-
/// handles the normalization of SwiftSyntax type names for readability.
46-
/// This helps categorize nodes by their role in the language (declarations,
47-
/// expressions, patterns, etc.) rather than their specific SwiftSyntax type.
48-
@available(*, deprecated)
49-
internal enum SyntaxClassifier {
50-
// MARK: - String Constants
51-
52-
/// Suffix used by SwiftSyntax type names (e.g., "VariableDeclSyntax" → "VariableDecl").
53-
private static let syntax = "Syntax"
54-
55-
// MARK: - Classification Methods
56-
57-
/// Classifies a syntax node by its semantic role in the Swift language.
58-
///
59-
/// This method first checks if the node's type conforms to `SyntaxClassifiable`
60-
/// for self-classification. If not, it falls back to examining the SwiftSyntax
61-
/// node type hierarchy to determine the semantic category.
62-
///
63-
/// - Parameter node: The SwiftSyntax node to classify
64-
/// - Returns: The semantic classification of the node
65-
internal static func classifyNode(_ node: Syntax) -> SyntaxType {
66-
// First, check if the node can classify itself
67-
if let classifiable = type(of: node) as? any SyntaxClassifiable.Type {
68-
return classifiable.syntaxType
69-
}
70-
71-
// Fallback to type-based classification
72-
switch node {
73-
case _ where node.is(DeclSyntax.self):
74-
return .decl // Declarations (struct, func, var, etc.)
75-
case _ where node.is(ExprSyntax.self):
76-
return .expr // Expressions (literals, function calls, etc.)
77-
case _ where node.is(PatternSyntax.self):
78-
return .pattern // Patterns (identifier patterns, tuple patterns, etc.)
79-
case _ where node.is(TypeSyntax.self):
80-
return .type // Type annotations and references
81-
default:
82-
return .other // Other syntax elements (punctuation, keywords, etc.)
83-
}
84-
}
85-
86-
/// Cleans up SwiftSyntax type names by removing the "Syntax" suffix.
87-
///
88-
/// SwiftSyntax type names typically end with "Syntax" (e.g., "VariableDeclSyntax").
89-
/// This method removes that suffix to create more readable names for output
90-
/// (e.g., "VariableDecl"), making the tree structure more human-friendly.
91-
///
92-
/// - Parameter node: The SwiftSyntax node whose type name should be cleaned
93-
/// - Returns: Cleaned class name without "Syntax" suffix
94-
internal static func cleanClassName(from node: Syntax) -> String {
95-
node.cleanClassName
96-
}
97-
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// AttributeListSyntax+SyntaxClassifiable.swift
3+
// SyntaxKit
4+
//
5+
// Created by Leo Dion.
6+
// Copyright © 2025 BrightDigit.
7+
//
8+
// Permission is hereby granted, free of charge, to any person
9+
// obtaining a copy of this software and associated documentation
10+
// files (the “Software”), to deal in the Software without
11+
// restriction, including without limitation the rights to use,
12+
// copy, modify, merge, publish, distribute, sublicense, and/or
13+
// sell copies of the Software, and to permit persons to whom the
14+
// Software is furnished to do so, subject to the following
15+
// conditions:
16+
//
17+
// The above copyright notice and this permission notice shall be
18+
// included in all copies or substantial portions of the Software.
19+
//
20+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
21+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27+
// OTHER DEALINGS IN THE SOFTWARE.
28+
//
29+
30+
import Foundation
31+
@_spi(RawSyntax) import SwiftSyntax
32+
33+
/// Extension for AttributeListSyntax to conform to SyntaxClassifiable.
34+
extension AttributeListSyntax: SyntaxClassifiable {
35+
/// Attribute lists are classified as `.collection` type.
36+
internal static var syntaxType: SyntaxType {
37+
.collection
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// CatchClauseListSyntax+SyntaxClassifiable.swift
3+
// SyntaxKit
4+
//
5+
// Created by Leo Dion.
6+
// Copyright © 2025 BrightDigit.
7+
//
8+
// Permission is hereby granted, free of charge, to any person
9+
// obtaining a copy of this software and associated documentation
10+
// files (the “Software”), to deal in the Software without
11+
// restriction, including without limitation the rights to use,
12+
// copy, modify, merge, publish, distribute, sublicense, and/or
13+
// sell copies of the Software, and to permit persons to whom the
14+
// Software is furnished to do so, subject to the following
15+
// conditions:
16+
//
17+
// The above copyright notice and this permission notice shall be
18+
// included in all copies or substantial portions of the Software.
19+
//
20+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
21+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27+
// OTHER DEALINGS IN THE SOFTWARE.
28+
//
29+
30+
import Foundation
31+
@_spi(RawSyntax) import SwiftSyntax
32+
33+
/// Extension for CatchClauseListSyntax to conform to SyntaxClassifiable.
34+
extension CatchClauseListSyntax: SyntaxClassifiable {
35+
/// Catch clause lists are classified as `.collection` type.
36+
internal static var syntaxType: SyntaxType {
37+
.collection
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// CodeBlockItemListSyntax+SyntaxClassifiable.swift
3+
// SyntaxKit
4+
//
5+
// Created by Leo Dion.
6+
// Copyright © 2025 BrightDigit.
7+
//
8+
// Permission is hereby granted, free of charge, to any person
9+
// obtaining a copy of this software and associated documentation
10+
// files (the “Software”), to deal in the Software without
11+
// restriction, including without limitation the rights to use,
12+
// copy, modify, merge, publish, distribute, sublicense, and/or
13+
// sell copies of the Software, and to permit persons to whom the
14+
// Software is furnished to do so, subject to the following
15+
// conditions:
16+
//
17+
// The above copyright notice and this permission notice shall be
18+
// included in all copies or substantial portions of the Software.
19+
//
20+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
21+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27+
// OTHER DEALINGS IN THE SOFTWARE.
28+
//
29+
30+
import Foundation
31+
@_spi(RawSyntax) import SwiftSyntax
32+
33+
/// Extension for CodeBlockItemListSyntax to conform to SyntaxClassifiable.
34+
extension CodeBlockItemListSyntax: SyntaxClassifiable {
35+
/// Code block item lists are classified as `.collection` type.
36+
internal static var syntaxType: SyntaxType {
37+
.collection
38+
}
39+
}

Sources/SyntaxParser/TokenVisitor/SyntaxClassifiable/CollectionSyntax+SyntaxClassifiable.swift

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)