Skip to content

Rename some SyntaxClassification #1998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions Sources/SwiftIDEUtils/SwiftIDEUtilsCompatibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,34 @@

public extension SyntaxClassification {
/// A `#` keyword like `#warning`.
@available(*, deprecated, renamed: "poundDirective")
static var poundDirectiveKeyword: SyntaxClassification {
return .poundDirective
@available(*, deprecated, renamed: "ifConfigDirective")
static var poundDirective: SyntaxClassification {
return .ifConfigDirective
}

@available(*, deprecated, renamed: "ifConfigDirective")
static var buildConfigId: SyntaxClassification {
return .ifConfigDirective
}

@available(*, deprecated, message: "String interpolation anchors are now classified as .none")
static var stringInterpolationAnchor: SyntaxClassification {
return .none
}

@available(*, deprecated, renamed: "type")
static var typeIdentifier: SyntaxClassification {
return .type
}

@available(*, deprecated, renamed: "operator")
static var operatorIdentifier: SyntaxClassification {
return .operator
}

@available(*, deprecated, renamed: "floatLiteral")
static var floatingLiteral: SyntaxClassification {
return .floatLiteral
}
}

Expand Down
49 changes: 18 additions & 31 deletions Sources/SwiftIDEUtils/SyntaxClassification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public enum SyntaxClassification {
case attribute
/// A block comment starting with `/**` and ending with `*/.
case blockComment
/// A build configuration directive like `#if`, `#elseif`, `#else`.
case buildConfigId
/// A doc block comment starting with `/**` and ending with `*/.
case docBlockComment
/// A doc line comment starting with `///`.
Expand All @@ -31,6 +29,8 @@ public enum SyntaxClassification {
case floatLiteral
/// A generic identifier.
case identifier
/// A directive starting with `#if`, `#elseif`or `#else`.
case ifConfigDirective
/// An integer literal.
case integerLiteral
/// A Swift keyword, including contextual keywords.
Expand All @@ -40,22 +40,13 @@ public enum SyntaxClassification {
/// The token should not receive syntax coloring.
case none
/// An identifier referring to an operator.
case operatorIdentifier
/// A `#` token like `#warning`.
case poundDirective
case `operator`
/// A regex literal, including multiline regex literals.
case regexLiteral
/// The opening and closing parenthesis of string interpolation.
case stringInterpolationAnchor
/// A string literal including multiline string literals.
case stringLiteral
/// An identifier referring to a type.
case typeIdentifier

@available(*, deprecated, renamed: "floatLiteral")
public static var floatingLiteral: Self {
return .floatLiteral
}
case type
}

extension SyntaxClassification {
Expand All @@ -76,26 +67,22 @@ extension SyntaxClassification {
return (.keyword, false)
case \DeclModifierSyntax.name:
return (.attribute, false)
case \ExpressionSegmentSyntax.leftParen:
return (.stringInterpolationAnchor, true)
case \ExpressionSegmentSyntax.rightParen:
return (.stringInterpolationAnchor, true)
case \IfConfigClauseSyntax.poundKeyword:
return (.buildConfigId, false)
return (.ifConfigDirective, false)
case \IfConfigClauseSyntax.condition:
return (.buildConfigId, false)
return (.ifConfigDirective, false)
case \IfConfigDeclSyntax.poundEndif:
return (.buildConfigId, false)
return (.ifConfigDirective, false)
case \MemberTypeIdentifierSyntax.name:
return (.typeIdentifier, false)
return (.type, false)
case \OperatorDeclSyntax.name:
return (.operatorIdentifier, false)
return (.operator, false)
case \PrecedenceGroupAssociativitySyntax.associativityLabel:
return (.keyword, false)
case \PrecedenceGroupRelationSyntax.higherThanOrLowerThanLabel:
return (.keyword, false)
case \SimpleTypeIdentifierSyntax.name:
return (.typeIdentifier, false)
return (.type, false)
default:
return nil
}
Expand All @@ -114,7 +101,7 @@ extension RawTokenKind {
case .backtick:
return .none
case .binaryOperator:
return .operatorIdentifier
return .operator
case .colon:
return .none
case .comma:
Expand Down Expand Up @@ -152,29 +139,29 @@ extension RawTokenKind {
case .period:
return .none
case .postfixOperator:
return .operatorIdentifier
return .operator
case .postfixQuestionMark:
return .none
case .pound:
return .none
case .poundAvailable:
return .none
case .poundElse:
return .poundDirective
return .ifConfigDirective
case .poundElseif:
return .poundDirective
return .ifConfigDirective
case .poundEndif:
return .poundDirective
return .ifConfigDirective
case .poundIf:
return .poundDirective
return .ifConfigDirective
case .poundSourceLocation:
return .poundDirective
return .keyword
case .poundUnavailable:
return .none
case .prefixAmpersand:
return .none
case .prefixOperator:
return .operatorIdentifier
return .operator
case .rawStringPoundDelimiter:
return .none
case .regexLiteralPattern:
Expand Down
8 changes: 3 additions & 5 deletions Sources/lit-test-helper/ClassifiedSyntaxTreePrinter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ extension SyntaxClassification {
case .none: return ""
case .keyword: return "kw"
case .identifier: return "id"
case .typeIdentifier: return "type"
case .type: return "type"
case .dollarIdentifier: return "dollar"
case .operatorIdentifier: return "op"
case .operator: return "op"
case .integerLiteral: return "int"
case .floatLiteral: return "float"
case .stringLiteral: return "str"
case .stringInterpolationAnchor: return "anchor"
case .regexLiteral: return "regex"
case .poundDirective: return "#kw"
case .buildConfigId: return "#id"
case .ifConfigDirective: return "#kw"
case .attribute: return "attr-builtin"
case .editorPlaceholder: return "placeholder"
case .lineComment: return "comment-line"
Expand Down
76 changes: 37 additions & 39 deletions Tests/SwiftIDEUtilsTest/ClassificationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class ClassificationTests: XCTestCase {
expected: [
ClassificationSpec(source: "let", kind: .keyword),
ClassificationSpec(source: "x", kind: .identifier),
ClassificationSpec(source: "Int", kind: .typeIdentifier),
ClassificationSpec(source: "Int", kind: .type),
]
)
}
Expand All @@ -103,11 +103,11 @@ public class ClassificationTests: XCTestCase {
expected: [
ClassificationSpec(source: "let", kind: .keyword),
ClassificationSpec(source: "x", kind: .identifier),
ClassificationSpec(source: "Int", kind: .typeIdentifier),
ClassificationSpec(source: "Int", kind: .type),
ClassificationSpec(source: "4", kind: .integerLiteral),
ClassificationSpec(source: "+", kind: .operatorIdentifier),
ClassificationSpec(source: "+", kind: .operator),
ClassificationSpec(source: "5", kind: .integerLiteral),
ClassificationSpec(source: "/", kind: .operatorIdentifier),
ClassificationSpec(source: "/", kind: .operator),
ClassificationSpec(source: "6", kind: .integerLiteral),
]
)
Expand All @@ -117,7 +117,7 @@ public class ClassificationTests: XCTestCase {
expected: [
ClassificationSpec(source: "infix", kind: .keyword),
ClassificationSpec(source: "operator", kind: .keyword),
ClassificationSpec(source: "*--*", kind: .operatorIdentifier),
ClassificationSpec(source: "*--*", kind: .operator),
]
)
}
Expand All @@ -131,13 +131,13 @@ public class ClassificationTests: XCTestCase {
ClassificationSpec(source: "func", kind: .keyword),
ClassificationSpec(source: "foo", kind: .identifier),
ClassificationSpec(source: "x", kind: .identifier),
ClassificationSpec(source: "Int", kind: .typeIdentifier),
ClassificationSpec(source: "Int", kind: .type),
ClassificationSpec(source: "y", kind: .identifier),
ClassificationSpec(source: "Int", kind: .typeIdentifier),
ClassificationSpec(source: "Int", kind: .typeIdentifier),
ClassificationSpec(source: "Int", kind: .type),
ClassificationSpec(source: "Int", kind: .type),
ClassificationSpec(source: "return", kind: .keyword),
ClassificationSpec(source: "x", kind: .identifier),
ClassificationSpec(source: "+", kind: .operatorIdentifier),
ClassificationSpec(source: "+", kind: .operator),
ClassificationSpec(source: "y", kind: .identifier),
]
)
Expand Down Expand Up @@ -219,18 +219,18 @@ public class ClassificationTests: XCTestCase {
#endif
""",
expected: [
ClassificationSpec(source: "#if", kind: .poundDirective),
ClassificationSpec(source: "os", kind: .buildConfigId),
ClassificationSpec(source: "macOS", kind: .buildConfigId),
ClassificationSpec(source: "#if", kind: .ifConfigDirective),
ClassificationSpec(source: "os", kind: .ifConfigDirective),
ClassificationSpec(source: "macOS", kind: .ifConfigDirective),
ClassificationSpec(source: "var", kind: .keyword),
ClassificationSpec(source: "x", kind: .identifier),
ClassificationSpec(source: "Int", kind: .typeIdentifier),
ClassificationSpec(source: "#elseif", kind: .poundDirective),
ClassificationSpec(source: "Int", kind: .type),
ClassificationSpec(source: "#elseif", kind: .ifConfigDirective),
ClassificationSpec(source: "var", kind: .keyword),
ClassificationSpec(source: "x", kind: .identifier),
ClassificationSpec(source: "Float", kind: .typeIdentifier),
ClassificationSpec(source: "#else", kind: .poundDirective),
ClassificationSpec(source: "#endif", kind: .poundDirective),
ClassificationSpec(source: "Float", kind: .type),
ClassificationSpec(source: "#else", kind: .ifConfigDirective),
ClassificationSpec(source: "#endif", kind: .ifConfigDirective),
]
)
}
Expand All @@ -242,10 +242,10 @@ public class ClassificationTests: XCTestCase {
#else
""",
expected: [
ClassificationSpec(source: "#if", kind: .poundDirective),
ClassificationSpec(source: "!", kind: .operatorIdentifier),
ClassificationSpec(source: "CONF", kind: .buildConfigId),
ClassificationSpec(source: "#else", kind: .poundDirective),
ClassificationSpec(source: "#if", kind: .ifConfigDirective),
ClassificationSpec(source: "!", kind: .operator),
ClassificationSpec(source: "CONF", kind: .ifConfigDirective),
ClassificationSpec(source: "#else", kind: .ifConfigDirective),
]
)
}
Expand All @@ -269,7 +269,7 @@ public class ClassificationTests: XCTestCase {
assertClassification(
#"#sourceLocation(file: "x", line: 1)"#,
expected: [
ClassificationSpec(source: "#sourceLocation", kind: .poundDirective),
ClassificationSpec(source: "#sourceLocation", kind: .keyword),
ClassificationSpec(source: "file", kind: .keyword),
ClassificationSpec(source: #""x""#, kind: .stringLiteral),
ClassificationSpec(source: "line", kind: .keyword),
Expand Down Expand Up @@ -330,7 +330,7 @@ public class ClassificationTests: XCTestCase {
ClassificationSpec(source: "OSX", kind: .keyword),
ClassificationSpec(source: "10", kind: .integerLiteral),
ClassificationSpec(source: "10", kind: .integerLiteral),
ClassificationSpec(source: "*", kind: .operatorIdentifier),
ClassificationSpec(source: "*", kind: .operator),
]
)
}
Expand All @@ -345,7 +345,7 @@ public class ClassificationTests: XCTestCase {
ClassificationSpec(source: "@IBOutlet", kind: .attribute),
ClassificationSpec(source: "var", kind: .keyword),
ClassificationSpec(source: "foo", kind: .identifier),
ClassificationSpec(source: "String", kind: .typeIdentifier),
ClassificationSpec(source: "String", kind: .type),
]
)
}
Expand All @@ -363,8 +363,8 @@ public class ClassificationTests: XCTestCase {
ClassificationSpec(source: "indirect", kind: .keyword),
ClassificationSpec(source: "case", kind: .keyword),
ClassificationSpec(source: "cons", kind: .identifier),
ClassificationSpec(source: "T", kind: .typeIdentifier),
ClassificationSpec(source: "List", kind: .typeIdentifier),
ClassificationSpec(source: "T", kind: .type),
ClassificationSpec(source: "List", kind: .type),
]
)
}
Expand Down Expand Up @@ -410,7 +410,7 @@ public class ClassificationTests: XCTestCase {
expected: [
ClassificationSpec(source: "infix", kind: .keyword),
ClassificationSpec(source: "operator", kind: .keyword),
ClassificationSpec(source: "*-*", kind: .operatorIdentifier),
ClassificationSpec(source: "*-*", kind: .operator),
ClassificationSpec(source: "FunnyPrecedence", kind: .identifier),
]
)
Expand Down Expand Up @@ -441,7 +441,7 @@ public class ClassificationTests: XCTestCase {
expected: [
ClassificationSpec(source: "protocol", kind: .keyword),
ClassificationSpec(source: "Prot2", kind: .identifier),
ClassificationSpec(source: "Prot", kind: .typeIdentifier),
ClassificationSpec(source: "Prot", kind: .type),
]
)
}
Expand All @@ -453,13 +453,13 @@ public class ClassificationTests: XCTestCase {
ClassificationSpec(source: "func", kind: .keyword),
ClassificationSpec(source: "genFn", kind: .identifier),
ClassificationSpec(source: "T", kind: .identifier),
ClassificationSpec(source: "Prot", kind: .typeIdentifier),
ClassificationSpec(source: "T", kind: .typeIdentifier),
ClassificationSpec(source: "Int", kind: .typeIdentifier),
ClassificationSpec(source: "Prot", kind: .type),
ClassificationSpec(source: "T", kind: .type),
ClassificationSpec(source: "Int", kind: .type),
ClassificationSpec(source: "where", kind: .keyword),
ClassificationSpec(source: "T", kind: .typeIdentifier),
ClassificationSpec(source: "Blarg", kind: .typeIdentifier),
ClassificationSpec(source: "Prot2", kind: .typeIdentifier),
ClassificationSpec(source: "T", kind: .type),
ClassificationSpec(source: "Blarg", kind: .type),
ClassificationSpec(source: "Prot2", kind: .type),
]
)
}
Expand All @@ -469,9 +469,7 @@ public class ClassificationTests: XCTestCase {
#""This is string \(1) interpolation""#,
expected: [
ClassificationSpec(source: #""This is string "#, kind: .stringLiteral),
ClassificationSpec(source: "(", kind: .stringInterpolationAnchor),
ClassificationSpec(source: "1", kind: .integerLiteral),
ClassificationSpec(source: ")", kind: .stringInterpolationAnchor),
ClassificationSpec(source: #" interpolation""#, kind: .stringLiteral),
]
)
Expand Down Expand Up @@ -531,12 +529,12 @@ public class ClassificationTests: XCTestCase {
ClassificationSpec(source: "func", kind: .keyword),
ClassificationSpec(source: "keywordInCaseAndLocalArgLabel", kind: .identifier),
ClassificationSpec(source: "for", kind: .identifier),
ClassificationSpec(source: "Int", kind: .typeIdentifier),
ClassificationSpec(source: "Int", kind: .type),
ClassificationSpec(source: "for", kind: .identifier),
ClassificationSpec(source: "in", kind: .identifier),
ClassificationSpec(source: "Int", kind: .typeIdentifier),
ClassificationSpec(source: "Int", kind: .type),
ClassificationSpec(source: "class", kind: .identifier),
ClassificationSpec(source: "Int", kind: .typeIdentifier),
ClassificationSpec(source: "Int", kind: .type),
]
)
}
Expand Down