From 74d156937a317d51e2c64bdc461a297775a1e72a Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Mon, 16 Aug 2021 18:02:33 -0600 Subject: [PATCH] Removed the swift modulemap parser. (#37) --- build/swift/BUILD.bazel | 1 - build/swift/swift_test.bzl | 40 ---- spm/repositories.bzl | 8 - swift/Sources/ModuleMap/BUILD.bazel | 11 - .../ModuleMap/Character+Extensions.swift | 10 - .../ModuleMap/CharacterSet+Extensions.swift | 41 ---- .../ModuleMap/ExportAsDeclaration.swift | 6 - .../Sources/ModuleMap/ExportDeclaration.swift | 9 - .../ModuleMap/ExternModuleDeclaration.swift | 10 - .../Sources/ModuleMap/HeaderDeclaration.swift | 26 --- swift/Sources/ModuleMap/LinkDeclaration.swift | 7 - .../Sources/ModuleMap/ModuleDeclaration.swift | 19 -- .../ModuleMap/ModuleDeclarationProtocol.swift | 3 - swift/Sources/ModuleMap/ModuleMember.swift | 1 - swift/Sources/ModuleMap/Operator.swift | 3 - .../Parser+ExportAsDeclarationExts.swift | 8 - .../Parser+ExportDeclarationExts.swift | 29 --- .../ModuleMap/Parser+ExternModuleExts.swift | 36 ---- .../Parser+HeaderDeclarationExts.swift | 125 ------------ .../Parser+LinkDeclarationExts.swift | 31 --- .../Sources/ModuleMap/Parser+ModuleExts.swift | 167 --------------- .../Parser+RequiresDeclarationExts.swift | 62 ------ .../ModuleMap/Parser+TokenHelpersExts.swift | 45 ----- ...ser+UmbrellaDirectoryDeclarationExts.swift | 14 -- .../ModuleMap/Parser+UseDeclarationExts.swift | 9 - swift/Sources/ModuleMap/Parser.swift | 66 ------ swift/Sources/ModuleMap/ParserError.swift | 13 -- .../ModuleMap/RequiresDeclaration.swift | 25 --- swift/Sources/ModuleMap/ReservedWord.swift | 18 -- swift/Sources/ModuleMap/StringNavigator.swift | 60 ------ swift/Sources/ModuleMap/Token.swift | 17 -- swift/Sources/ModuleMap/Tokenizer.swift | 173 ---------------- .../UmbrellaDirectoryDeclaration.swift | 7 - swift/Sources/ModuleMap/UseDeclaration.swift | 6 - swift/Tests/ModuleMapTests/BUILD.bazel | 9 - .../Character+ExtensionsTests.swift | 21 -- .../Parser+ExportAsDeclarationExtsTests.swift | 20 -- .../Parser+ExportDeclarationExtsTests.swift | 51 ----- .../Parser+ExternModuleExtsTests.swift | 80 -------- .../Parser+HeaderDeclarationExtsTests.swift | 103 ---------- .../Parser+LinkDeclarationExtsTests.swift | 36 ---- .../Parser+ModuleExtsTests.swift | 190 ------------------ .../Parser+RequiresDeclarationExtsTests.swift | 52 ----- ...mbrellaDirectoryDeclarationExtsTests.swift | 57 ------ .../Parser+UseDeclarationExtsTests.swift | 20 -- swift/Tests/ModuleMapTests/ParserTests.swift | 36 ---- .../ModuleMapTests/StringNavigatorTests.swift | 100 --------- .../Tests/ModuleMapTests/TokenizerTests.swift | 110 ---------- .../XCTestCase+Extensions.swift | 30 --- swiftformat | 11 - swiftlint | 14 -- 51 files changed, 2046 deletions(-) delete mode 100644 build/swift/BUILD.bazel delete mode 100644 build/swift/swift_test.bzl delete mode 100644 swift/Sources/ModuleMap/BUILD.bazel delete mode 100644 swift/Sources/ModuleMap/Character+Extensions.swift delete mode 100644 swift/Sources/ModuleMap/CharacterSet+Extensions.swift delete mode 100644 swift/Sources/ModuleMap/ExportAsDeclaration.swift delete mode 100644 swift/Sources/ModuleMap/ExportDeclaration.swift delete mode 100644 swift/Sources/ModuleMap/ExternModuleDeclaration.swift delete mode 100644 swift/Sources/ModuleMap/HeaderDeclaration.swift delete mode 100644 swift/Sources/ModuleMap/LinkDeclaration.swift delete mode 100644 swift/Sources/ModuleMap/ModuleDeclaration.swift delete mode 100644 swift/Sources/ModuleMap/ModuleDeclarationProtocol.swift delete mode 100644 swift/Sources/ModuleMap/ModuleMember.swift delete mode 100644 swift/Sources/ModuleMap/Operator.swift delete mode 100644 swift/Sources/ModuleMap/Parser+ExportAsDeclarationExts.swift delete mode 100644 swift/Sources/ModuleMap/Parser+ExportDeclarationExts.swift delete mode 100644 swift/Sources/ModuleMap/Parser+ExternModuleExts.swift delete mode 100644 swift/Sources/ModuleMap/Parser+HeaderDeclarationExts.swift delete mode 100644 swift/Sources/ModuleMap/Parser+LinkDeclarationExts.swift delete mode 100644 swift/Sources/ModuleMap/Parser+ModuleExts.swift delete mode 100644 swift/Sources/ModuleMap/Parser+RequiresDeclarationExts.swift delete mode 100644 swift/Sources/ModuleMap/Parser+TokenHelpersExts.swift delete mode 100644 swift/Sources/ModuleMap/Parser+UmbrellaDirectoryDeclarationExts.swift delete mode 100644 swift/Sources/ModuleMap/Parser+UseDeclarationExts.swift delete mode 100644 swift/Sources/ModuleMap/Parser.swift delete mode 100644 swift/Sources/ModuleMap/ParserError.swift delete mode 100644 swift/Sources/ModuleMap/RequiresDeclaration.swift delete mode 100644 swift/Sources/ModuleMap/ReservedWord.swift delete mode 100644 swift/Sources/ModuleMap/StringNavigator.swift delete mode 100644 swift/Sources/ModuleMap/Token.swift delete mode 100644 swift/Sources/ModuleMap/Tokenizer.swift delete mode 100644 swift/Sources/ModuleMap/UmbrellaDirectoryDeclaration.swift delete mode 100644 swift/Sources/ModuleMap/UseDeclaration.swift delete mode 100644 swift/Tests/ModuleMapTests/BUILD.bazel delete mode 100644 swift/Tests/ModuleMapTests/Character+ExtensionsTests.swift delete mode 100644 swift/Tests/ModuleMapTests/Parser+ExportAsDeclarationExtsTests.swift delete mode 100644 swift/Tests/ModuleMapTests/Parser+ExportDeclarationExtsTests.swift delete mode 100644 swift/Tests/ModuleMapTests/Parser+ExternModuleExtsTests.swift delete mode 100644 swift/Tests/ModuleMapTests/Parser+HeaderDeclarationExtsTests.swift delete mode 100644 swift/Tests/ModuleMapTests/Parser+LinkDeclarationExtsTests.swift delete mode 100644 swift/Tests/ModuleMapTests/Parser+ModuleExtsTests.swift delete mode 100644 swift/Tests/ModuleMapTests/Parser+RequiresDeclarationExtsTests.swift delete mode 100644 swift/Tests/ModuleMapTests/Parser+UmbrellaDirectoryDeclarationExtsTests.swift delete mode 100644 swift/Tests/ModuleMapTests/Parser+UseDeclarationExtsTests.swift delete mode 100644 swift/Tests/ModuleMapTests/ParserTests.swift delete mode 100644 swift/Tests/ModuleMapTests/StringNavigatorTests.swift delete mode 100644 swift/Tests/ModuleMapTests/TokenizerTests.swift delete mode 100644 swift/Tests/ModuleMapTests/XCTestCase+Extensions.swift delete mode 100755 swiftformat delete mode 100755 swiftlint diff --git a/build/swift/BUILD.bazel b/build/swift/BUILD.bazel deleted file mode 100644 index ccd9dcef..00000000 --- a/build/swift/BUILD.bazel +++ /dev/null @@ -1 +0,0 @@ -# Intentionally blank diff --git a/build/swift/swift_test.bzl b/build/swift/swift_test.bzl deleted file mode 100644 index b70edf4f..00000000 --- a/build/swift/swift_test.bzl +++ /dev/null @@ -1,40 +0,0 @@ -# load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test") -# load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") - -# def swift_test(name, srcs = None, size = "small", timeout = None, flaky = False, deps = [], data = [], env = {}, test_tags = []): -# test_lib_name = "%sLib" % (name) - -# if srcs == None: -# srcs = native.glob(["**/*.swift"]) - -# swift_library( -# name = test_lib_name, -# testonly = 1, -# srcs = srcs, -# deps = deps, -# visibility = ["//visibility:private"], -# ) - -# ios_unit_test( -# name = name, -# minimum_os_version = "14.0", -# flaky = flaky, -# env = env, -# size = size, -# timeout = timeout, -# deps = [":%s" % (test_lib_name)], -# resources = data, -# tags = test_tags, -# visibility = ["//visibility:private"], -# ) - -load("@build_bazel_rules_swift//swift:swift.bzl", real_swift_test = "swift_test") - -def swift_test(name, size = "small", deps = [], data = []): - real_swift_test( - name = name, - size = size, - srcs = native.glob(["**/*.swift"]), - deps = deps, - data = data, - ) diff --git a/spm/repositories.bzl b/spm/repositories.bzl index 48123232..7c709b96 100644 --- a/spm/repositories.bzl +++ b/spm/repositories.bzl @@ -18,11 +18,3 @@ def rules_spm_dependencies(): sha256 = "f872c0388808c3f8de67e0c6d39b0beac4a65d7e07eff3ced123d0b102046fb6", url = "https://github.com/bazelbuild/rules_swift/releases/download/0.23.0/rules_swift.0.23.0.tar.gz", ) - - maybe( - http_archive, - name = "cgrindel_swift_toolbox", - sha256 = "3b1022dcb99f45753f94d9e6c2623bf4973c887bae52df8bb1b25ee46878bdff", - strip_prefix = "swift_toolbox-0.2.0", - url = "https://github.com/cgrindel/swift_toolbox/archive/v0.2.0.tar.gz", - ) diff --git a/swift/Sources/ModuleMap/BUILD.bazel b/swift/Sources/ModuleMap/BUILD.bazel deleted file mode 100644 index c0da6392..00000000 --- a/swift/Sources/ModuleMap/BUILD.bazel +++ /dev/null @@ -1,11 +0,0 @@ -load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") - -swift_library( - name = "ModuleMap", - srcs = glob(["*.swift"]), - module_name = "ModuleMap", - visibility = ["//swift:__subpackages__"], - deps = [ - "@cgrindel_swift_toolbox//Sources/StructUtils", - ], -) diff --git a/swift/Sources/ModuleMap/Character+Extensions.swift b/swift/Sources/ModuleMap/Character+Extensions.swift deleted file mode 100644 index c458843b..00000000 --- a/swift/Sources/ModuleMap/Character+Extensions.swift +++ /dev/null @@ -1,10 +0,0 @@ -import Foundation - -public extension Character { - /// Returns true if all of the Unicode scalars in this Character (grapheme cluster) are in the - /// specified set. Otherwise false. - func isIn(_ characterSet: CharacterSet) -> Bool { - let subset = CharacterSet(unicodeScalars) - return subset.isSubset(of: characterSet) - } -} diff --git a/swift/Sources/ModuleMap/CharacterSet+Extensions.swift b/swift/Sources/ModuleMap/CharacterSet+Extensions.swift deleted file mode 100644 index e1bdace2..00000000 --- a/swift/Sources/ModuleMap/CharacterSet+Extensions.swift +++ /dev/null @@ -1,41 +0,0 @@ -import Foundation - -public extension CharacterSet { - /// Valid characters to start an identifier. - /// Spec: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf - /// Section: 6.4.2.1 - static let c99IdentifierBeginningCharacters: CharacterSet = { - var charSet = CharacterSet.letters - charSet.insert(charactersIn: "_") - return charSet - }() - - static let c99IdenfitiferCharacters: CharacterSet = { - var charSet = CharacterSet.c99IdentifierBeginningCharacters - charSet.formUnion(.decimalDigits) - return charSet - }() - - static let c99Operators: CharacterSet = { - CharacterSet(charactersIn: "*") - }() - - static let c99NumberBeginningCharacters: CharacterSet = { - .decimalDigits - }() - - static let c99OctalDigits: CharacterSet = { - .init(charactersIn: "01234567") - }() - - static let c99HexadecimalDigits: CharacterSet = { - .init(charactersIn: "0123456789abcdefABCDEF") - }() - - static let c99NumberCharacters: CharacterSet = { - var charSet = CharacterSet.decimalDigits - charSet.formUnion(.c99HexadecimalDigits) - charSet.insert(charactersIn: ".,") - return charSet - }() -} diff --git a/swift/Sources/ModuleMap/ExportAsDeclaration.swift b/swift/Sources/ModuleMap/ExportAsDeclaration.swift deleted file mode 100644 index 191d611a..00000000 --- a/swift/Sources/ModuleMap/ExportAsDeclaration.swift +++ /dev/null @@ -1,6 +0,0 @@ -import StructUtils - -/// Spec: https://clang.llvm.org/docs/Modules.html#re-export-declaration -struct ExportAsDeclaration: Withable, Equatable, ModuleMember { - var identifier = "" -} diff --git a/swift/Sources/ModuleMap/ExportDeclaration.swift b/swift/Sources/ModuleMap/ExportDeclaration.swift deleted file mode 100644 index 556a95da..00000000 --- a/swift/Sources/ModuleMap/ExportDeclaration.swift +++ /dev/null @@ -1,9 +0,0 @@ -import StructUtils - -/// Spec: https://clang.llvm.org/docs/Modules.html#export-declaration -struct ExportDeclaration: Withable, Equatable, ModuleMember { - /// Can have zero or more identifiers (e.g. first.second => ["first", "second"]) - var identifiers = [String]() - // If the end of the asterisk was specified, then this is a wildcard export. - var wildcard = false -} diff --git a/swift/Sources/ModuleMap/ExternModuleDeclaration.swift b/swift/Sources/ModuleMap/ExternModuleDeclaration.swift deleted file mode 100644 index 795ab385..00000000 --- a/swift/Sources/ModuleMap/ExternModuleDeclaration.swift +++ /dev/null @@ -1,10 +0,0 @@ -import StructUtils - -public struct ExternModuleDeclaration: Withable { - public var moduleID = "" - public var definitionPath = "" - - public init() {} -} - -extension ExternModuleDeclaration: ModuleDeclarationProtocol, ModuleMember {} diff --git a/swift/Sources/ModuleMap/HeaderDeclaration.swift b/swift/Sources/ModuleMap/HeaderDeclaration.swift deleted file mode 100644 index 7b18f8e5..00000000 --- a/swift/Sources/ModuleMap/HeaderDeclaration.swift +++ /dev/null @@ -1,26 +0,0 @@ -import StructUtils - -/// Spec: https://clang.llvm.org/docs/Modules.html#header-declaration -struct HeaderDeclaration: Withable, Equatable, ModuleMember { - /// Attributes that are specific to a single header file declaration. - struct SingleQualifiers: Withable, Equatable { - var privateHeader = false - var textual = false - } - - /// Specifies how the header declaration should be interpretted. - enum DeclarationType: Equatable { - case single(SingleQualifiers) - case umbrella - case exclude - } - - /// Type of declaration - var type: DeclarationType = .single(.init()) - /// Path to the header file. - var path = "" - - // Attributes - var size: Int? - var mtime: Int? -} diff --git a/swift/Sources/ModuleMap/LinkDeclaration.swift b/swift/Sources/ModuleMap/LinkDeclaration.swift deleted file mode 100644 index 8aded66d..00000000 --- a/swift/Sources/ModuleMap/LinkDeclaration.swift +++ /dev/null @@ -1,7 +0,0 @@ -import StructUtils - -/// Spec: https://clang.llvm.org/docs/Modules.html#link-declaration -struct LinkDeclaration: Withable, Equatable, ModuleMember { - var name = "" - var framework = false -} diff --git a/swift/Sources/ModuleMap/ModuleDeclaration.swift b/swift/Sources/ModuleMap/ModuleDeclaration.swift deleted file mode 100644 index 034aea7e..00000000 --- a/swift/Sources/ModuleMap/ModuleDeclaration.swift +++ /dev/null @@ -1,19 +0,0 @@ -import StructUtils - -public struct ModuleDeclaration: Withable { - public var moduleID = "" - - // Qualifiers - public var explicit = false - public var framework = false - - // Attributes - public var attributes = [String]() - - // Module members - public var members = [ModuleMember]() - - public init() {} -} - -extension ModuleDeclaration: ModuleDeclarationProtocol, ModuleMember {} diff --git a/swift/Sources/ModuleMap/ModuleDeclarationProtocol.swift b/swift/Sources/ModuleMap/ModuleDeclarationProtocol.swift deleted file mode 100644 index 121d2efc..00000000 --- a/swift/Sources/ModuleMap/ModuleDeclarationProtocol.swift +++ /dev/null @@ -1,3 +0,0 @@ -public protocol ModuleDeclarationProtocol { - var moduleID: String { get } -} diff --git a/swift/Sources/ModuleMap/ModuleMember.swift b/swift/Sources/ModuleMap/ModuleMember.swift deleted file mode 100644 index f2316ba7..00000000 --- a/swift/Sources/ModuleMap/ModuleMember.swift +++ /dev/null @@ -1 +0,0 @@ -public protocol ModuleMember {} diff --git a/swift/Sources/ModuleMap/Operator.swift b/swift/Sources/ModuleMap/Operator.swift deleted file mode 100644 index cadfe0b1..00000000 --- a/swift/Sources/ModuleMap/Operator.swift +++ /dev/null @@ -1,3 +0,0 @@ -public enum Operator: Equatable { - case asterisk -} diff --git a/swift/Sources/ModuleMap/Parser+ExportAsDeclarationExts.swift b/swift/Sources/ModuleMap/Parser+ExportAsDeclarationExts.swift deleted file mode 100644 index 236d13c0..00000000 --- a/swift/Sources/ModuleMap/Parser+ExportAsDeclarationExts.swift +++ /dev/null @@ -1,8 +0,0 @@ -extension Parser { - mutating func parseExportAsDeclaration(moduleID: String) throws -> ExportAsDeclaration { - return try .with { - $0.identifier = - try nextIdentifier("Collecting identifier for export_as in \(moduleID) module.") - } - } -} diff --git a/swift/Sources/ModuleMap/Parser+ExportDeclarationExts.swift b/swift/Sources/ModuleMap/Parser+ExportDeclarationExts.swift deleted file mode 100644 index 5912f353..00000000 --- a/swift/Sources/ModuleMap/Parser+ExportDeclarationExts.swift +++ /dev/null @@ -1,29 +0,0 @@ -extension Parser { - mutating func parseExportDeclaration(moduleID: String) throws -> ExportDeclaration { - // The export token has been consumed - var decl = ExportDeclaration() - - var continueProcessing = true - while continueProcessing { - let token = try nextToken("Collecting module ids for export in \(moduleID) module.") - switch token { - case .operator(.asterisk): - decl.wildcard = true - continueProcessing = false - case let .identifier(idValue): - decl.identifiers.append(idValue) - case .period: - break - case .newLine: - continueProcessing = false - default: - throw ParserError.unexpectedToken( - token, - "Collecting module ids for export in \(moduleID) module." - ) - } - } - - return decl - } -} diff --git a/swift/Sources/ModuleMap/Parser+ExternModuleExts.swift b/swift/Sources/ModuleMap/Parser+ExternModuleExts.swift deleted file mode 100644 index 25aba54e..00000000 --- a/swift/Sources/ModuleMap/Parser+ExternModuleExts.swift +++ /dev/null @@ -1,36 +0,0 @@ -extension Parser { - /// Syntax - /// - /// extern module module-id string-literal - /// - mutating func parseExternModuleDeclaration() throws -> ExternModuleDeclaration { - // Already found the extern token - let moduleToken = try nextToken("Looking for the module token while parsing an extern module.") - guard moduleToken == .reserved(.module) else { - throw ParserError.unexpectedToken( - moduleToken, - "Expected the module token while parsing an extern module." - ) - } - let idToken = try nextToken("Looking for the module id token while parsing an extern module.") - guard case let .identifier(moduleID) = idToken else { - throw ParserError.unexpectedToken( - idToken, - "Expected the module id token while parsing an extern module." - ) - } - let pathToken = - try nextToken("Looking for the module definition path token while parsing an extern module.") - guard case let .stringLiteral(definitionPath) = pathToken else { - throw ParserError.unexpectedToken( - pathToken, - "Expected a string literal token for the path while parsing an extern module." - ) - } - - return .with { - $0.moduleID = moduleID - $0.definitionPath = definitionPath - } - } -} diff --git a/swift/Sources/ModuleMap/Parser+HeaderDeclarationExts.swift b/swift/Sources/ModuleMap/Parser+HeaderDeclarationExts.swift deleted file mode 100644 index 18b70960..00000000 --- a/swift/Sources/ModuleMap/Parser+HeaderDeclarationExts.swift +++ /dev/null @@ -1,125 +0,0 @@ -// MARK: - Header Declaration Parsing - -extension Parser { - /// Syntax - /// - /// header-declaration: - /// privateopt textualopt header string-literal header-attrsopt - /// umbrella header string-literal header-attrsopt - /// exclude header string-literal header-attrsopt - /// - /// header-attrs: - /// '{' header-attr* '}' - /// - /// header-attr: - /// size integer-literal - /// mtime integer-literal - /// - /// Spec: https://clang.llvm.org/docs/Modules.html#header-declaration - mutating func parseHeaderDeclaration( - moduleID: String, - prefixTokens: [Token] - ) throws -> HeaderDeclaration { - // The tokens up through the header token have been consumed. - var decl = HeaderDeclaration() - - // Parse the prefix tokens to determine the type of declaration - if let prefixToken = prefixTokens.first { - switch prefixToken { - case .reserved(.umbrella): - decl.type = .umbrella - case .reserved(.exclude): - decl.type = .exclude - default: - decl.type = .single(try .from(moduleID: moduleID, tokens: prefixTokens)) - } - } - - let path = - try nextStringLiteral("Collecting the path for header declaration in \(moduleID) module.") - decl.path = path - - var continueProcessing = true - var expectCurlyBracketClose = false - while continueProcessing { - let token = - try nextToken("Collecting end of header declaration for \(path) in \(moduleID) module.") - switch token { - case .newLine: - continueProcessing = false - case .curlyBracketOpen: - expectCurlyBracketClose = true - try parseHeaderDeclarationAttribute(moduleID: moduleID, path: path, decl: &decl) - case .curlyBracketClose: - guard expectCurlyBracketClose else { - throw ParserError.unexpectedToken( - token, - "Collecting header attributes for \(path) in \(moduleID) module." - ) - } - continueProcessing = false - default: - throw ParserError.unexpectedToken( - token, - "Collecting end of header declaration for \(path) in \(moduleID) module." - ) - } - } - - return decl - } - - mutating func parseHeaderDeclarationAttribute( - moduleID: String, - path: String, - decl: inout HeaderDeclaration - ) throws { - var continueProcessing = true - while continueProcessing { - let token = try nextToken( - "Collecting attributes for header declaration for \(path) in \(moduleID) module." - ) - switch token { - case .identifier("size"): - decl.size = try nextIntLiteral( - "Collecting the size attribute value for \(path) in \(moduleID) module." - ) - case .identifier("mtime"): - decl.mtime = try nextIntLiteral( - "Collecting the mtime attribute value for \(path) in \(moduleID) module." - ) - case .newLine: - break - case .curlyBracketClose: - continueProcessing = false - default: - throw ParserError.unexpectedToken( - token, - "Collecting header declaration attributes for \(moduleID) module." - ) - } - } - } -} - -// MARK: - Single Header Qualifiers Parsing - -extension HeaderDeclaration.SingleQualifiers { - static func from(moduleID: String, tokens: [Token]) throws -> Self { - var qualifiers = Self() - for token in tokens { - switch token { - case .reserved(.private): - qualifiers.privateHeader = true - case .reserved(.textual): - qualifiers.textual = true - default: - throw ParserError.unexpectedToken( - token, - "Collecting qualifiers for single header declaration in \(moduleID) module." - ) - } - } - return qualifiers - } -} diff --git a/swift/Sources/ModuleMap/Parser+LinkDeclarationExts.swift b/swift/Sources/ModuleMap/Parser+LinkDeclarationExts.swift deleted file mode 100644 index 9169a93e..00000000 --- a/swift/Sources/ModuleMap/Parser+LinkDeclarationExts.swift +++ /dev/null @@ -1,31 +0,0 @@ -extension Parser { - /// Syntax - /// - /// link-declaration: - /// link frameworkopt string-literal - /// - /// Spec: https://clang.llvm.org/docs/Modules.html#link-declaration - mutating func parseLinkDeclaration(moduleID: String) throws -> LinkDeclaration { - // We have consumed the link word. - var decl = LinkDeclaration() - - var continueProcessing = true - while continueProcessing { - let token = try nextToken("Collecting a link declaration in \(moduleID) module.") - switch token { - case .reserved(.framework): - decl.framework = true - case let .stringLiteral(name): - decl.name = name - continueProcessing = false - default: - throw ParserError.unexpectedToken( - token, - "Collecting a link declaration in \(moduleID) module." - ) - } - } - - return decl - } -} diff --git a/swift/Sources/ModuleMap/Parser+ModuleExts.swift b/swift/Sources/ModuleMap/Parser+ModuleExts.swift deleted file mode 100644 index 25c240ae..00000000 --- a/swift/Sources/ModuleMap/Parser+ModuleExts.swift +++ /dev/null @@ -1,167 +0,0 @@ -extension Parser { - /// Syntax - /// - /// explicitopt frameworkopt module module-id attributesopt '{' module-member* '}' - /// - /// attributes: - /// attribute attributesopt - /// - /// attribute: - /// '[' identifier ']' - /// - /// Spec: https://clang.llvm.org/docs/Modules.html#module-declaration - mutating func parseModuleDeclaration( - isSubmodule: Bool, - prefixTokens: [Token] - ) throws -> ModuleDeclaration { - // We have collected the module word. - var module = ModuleDeclaration() - var continueProcessing = true - - // Collect the qualififers and the module token - for token in prefixTokens { - switch token { - case .reserved(.explicit): - guard isSubmodule else { - throw ParserError.unexpectedToken( - token, - "The explicit qualifier can only exist on submodules." - ) - } - module.explicit = true - case .reserved(.framework): - module.framework = true - default: - throw ParserError.unexpectedToken(token, "Collecting qualifiers for module declaration.") - } - } - - module.moduleID = try nextIdentifier("Looking for the module id token while parsing a module.") - - // Collect any attributes until the beginning of the module members section - continueProcessing = true - while continueProcessing { - let token = try nextToken("Collecting attributes for \(module.moduleID) module.") - switch token { - case .curlyBracketOpen: - continueProcessing = false - case .squareBracketOpen: - let attribute = try parseModuleAttribute(moduleID: module.moduleID) - module.attributes.append(attribute) - default: - throw ParserError.unexpectedToken( - token, - "Collecting attributes for \(module.moduleID) module." - ) - } - } - - // Collect the module members - while true { - guard let member = try nextModuleMember(moduleID: module.moduleID) else { - break - } - module.members.append(member) - } - - return module - } - - mutating func parseModuleAttribute(moduleID: String) throws -> String { - // Already collected the square bracket open. - let attribValue = try nextIdentifier("Collecting attribute for \(moduleID) module.") - try assertNextToken( - .squareBracketClose, - "Collecting closing square bracket (]) for \(moduleID) module." - ) - return attribValue - } - - /// Syntax - /// - /// module-member: - /// requires-declaration - /// header-declaration - /// umbrella-dir-declaration - /// submodule-declaration - /// export-declaration - /// export-as-declaration - /// use-declaration - /// link-declaration - /// config-macros-declaration - /// conflict-declaration - /// - mutating func nextModuleMember(moduleID: String) throws -> ModuleMember? { - var prefixTokens = [Token]() - while true { - guard let token = tokenIterator.next() else { - return nil - } - - switch token { - case .newLine: - guard prefixTokens.isEmpty else { - throw ParserError.unexpectedTokens( - prefixTokens, - "Prefix tokens found before end of line in \(moduleID) module." - ) - } - continue - case .curlyBracketClose: - guard prefixTokens.isEmpty else { - throw ParserError.unexpectedTokens( - prefixTokens, - "Prefix tokens found at end of module member block in \(moduleID) module." - ) - } - // Found the end of the members section - return nil - case .reserved(.requires): - guard prefixTokens.isEmpty else { - throw ParserError.unexpectedTokens( - prefixTokens, - "Prefix tokens found for requires declaration in \(moduleID) module." - ) - } - return try parseRequiresDeclaration(moduleID: moduleID) - case .reserved(.umbrella): - // The umbrella word can appear for umbrella headers or umbrella directories. - // If the next token is header, then it is an umbrella header. Otherwise, it is an umbrella - // directory. - let nextToken = try nextToken("Checking if umbrella header or directory.") - if nextToken == .reserved(.header) { - prefixTokens.append(.reserved(.umbrella)) - return try parseHeaderDeclaration(moduleID: moduleID, prefixTokens: prefixTokens) - } - guard prefixTokens.isEmpty else { - throw ParserError.unexpectedTokens( - prefixTokens, - "Prefix tokens found for umbrella directory declaration in \(moduleID) module." - ) - } - return try parseUmbrellaDirectoryDeclaration(moduleID: moduleID, pathToken: nextToken) - case .reserved(.header): - return try parseHeaderDeclaration(moduleID: moduleID, prefixTokens: prefixTokens) - case .reserved(.export): - return try parseExportDeclaration(moduleID: moduleID) - case .reserved(.exportAs): - return try parseExportAsDeclaration(moduleID: moduleID) - case .reserved(.extern): - guard prefixTokens.isEmpty else { - throw ParserError.unexpectedTokens(prefixTokens, "Collecting module declarations.") - } - return try parseExternModuleDeclaration() - case .reserved(.module): - return try parseModuleDeclaration(isSubmodule: true, prefixTokens: prefixTokens) - case .reserved(.use): - return try parseUseDeclaration(moduleID: moduleID) - case .reserved(.link): - return try parseLinkDeclaration(moduleID: moduleID) - case .reserved(.configMacros), .reserved(.conflict): - throw ParserError.unsupported(token, "This module member is currently not supported.") - default: - prefixTokens.append(token) - } - } - } -} diff --git a/swift/Sources/ModuleMap/Parser+RequiresDeclarationExts.swift b/swift/Sources/ModuleMap/Parser+RequiresDeclarationExts.swift deleted file mode 100644 index 9970d9e9..00000000 --- a/swift/Sources/ModuleMap/Parser+RequiresDeclarationExts.swift +++ /dev/null @@ -1,62 +0,0 @@ -extension Parser { - /// Syntax - /// - /// requires-declaration: - /// requires feature-list - /// - /// feature-list: - /// feature (',' feature)* - /// - /// feature: - /// !opt identifier - /// - mutating func parseRequiresDeclaration(moduleID: String) throws -> RequiresDeclaration { - // Already read the requires reserved word - var decl = RequiresDeclaration() - var currentFeature = RequiresDeclaration.Feature() - - var continueProcessing = true - while continueProcessing { - var token = - try nextToken("Collecting features for requires declaration in \(moduleID) module.") - switch token { - case .exclamationPoint: - currentFeature.compatible = false - case let .identifier(featureName): - // Add the feature to the list - currentFeature.name = featureName - decl.features.append(currentFeature) - - // Need to check for comma or newLine next - token = try nextToken( - "Looking for the end of the features for requires declaration in \(moduleID) module." - ) - switch token { - case .comma: - currentFeature = RequiresDeclaration.Feature() - case .newLine: - continueProcessing = false - default: - throw ParserError.unexpectedToken( - token, - "Collecting features for requires declaration in \(moduleID) module." - ) - } - case .newLine: - continueProcessing = false - default: - throw ParserError.unexpectedToken( - token, - "Collecting features for requires declaration in \(moduleID) module." - ) - } - } - - guard decl.features.count > 0 else { - throw ParserError.invalidRequiresDeclaration( - "No features were found for requires declaration in \(moduleID) module." - ) - } - return decl - } -} diff --git a/swift/Sources/ModuleMap/Parser+TokenHelpersExts.swift b/swift/Sources/ModuleMap/Parser+TokenHelpersExts.swift deleted file mode 100644 index 64306f09..00000000 --- a/swift/Sources/ModuleMap/Parser+TokenHelpersExts.swift +++ /dev/null @@ -1,45 +0,0 @@ -// MARK: Token Helpers - -extension Parser { - /// Returns the next token. If there is no token, throw an error with the specified message. - mutating func nextToken(_ errorMsgExp: @autoclosure () -> String) throws -> Token { - guard let token = tokenIterator.next() else { - throw ParserError.endOfTokens(errorMsgExp()) - } - return token - } - - mutating func nextIdentifier(_ errorMsgExp: @autoclosure () -> String) throws -> String { - let token = try nextToken(errorMsgExp()) - guard case let .identifier(idValue) = token else { - throw ParserError.unexpectedToken(token, errorMsgExp()) - } - return idValue - } - - mutating func nextStringLiteral(_ errorMsgExp: @autoclosure () -> String) throws -> String { - let token = try nextToken(errorMsgExp()) - guard case let .stringLiteral(value) = token else { - throw ParserError.unexpectedToken(token, errorMsgExp()) - } - return value - } - - mutating func nextIntLiteral(_ errorMsgExp: @autoclosure () -> String) throws -> Int { - let token = try nextToken(errorMsgExp()) - guard case let .integerLiteral(intValue) = token else { - throw ParserError.unexpectedToken(token, errorMsgExp()) - } - return intValue - } - - mutating func assertNextToken( - _ expected: Token, - _ errorMsgExp: @autoclosure () -> String - ) throws { - let token = try nextToken(errorMsgExp()) - guard token == expected else { - throw ParserError.unexpectedToken(token, errorMsgExp()) - } - } -} diff --git a/swift/Sources/ModuleMap/Parser+UmbrellaDirectoryDeclarationExts.swift b/swift/Sources/ModuleMap/Parser+UmbrellaDirectoryDeclarationExts.swift deleted file mode 100644 index c0beb67e..00000000 --- a/swift/Sources/ModuleMap/Parser+UmbrellaDirectoryDeclarationExts.swift +++ /dev/null @@ -1,14 +0,0 @@ -extension Parser { - mutating func parseUmbrellaDirectoryDeclaration( - moduleID: String, - pathToken: Token - ) throws -> UmbrellaDirectoryDeclaration { - guard case let .stringLiteral(path) = pathToken else { - throw ParserError.unexpectedToken( - pathToken, - "Collecting the directory path for the umbrella directory declaration for \(moduleID) module." - ) - } - return .with { $0.path = path } - } -} diff --git a/swift/Sources/ModuleMap/Parser+UseDeclarationExts.swift b/swift/Sources/ModuleMap/Parser+UseDeclarationExts.swift deleted file mode 100644 index a72c4453..00000000 --- a/swift/Sources/ModuleMap/Parser+UseDeclarationExts.swift +++ /dev/null @@ -1,9 +0,0 @@ -extension Parser { - mutating func parseUseDeclaration(moduleID: String) throws -> UseDeclaration { - return try .with { - $0.moduleID = try nextIdentifier( - "Collecting the module id for the use declaration in \(moduleID) module." - ) - } - } -} diff --git a/swift/Sources/ModuleMap/Parser.swift b/swift/Sources/ModuleMap/Parser.swift deleted file mode 100644 index 124550b0..00000000 --- a/swift/Sources/ModuleMap/Parser.swift +++ /dev/null @@ -1,66 +0,0 @@ -/// Spec: https://clang.llvm.org/docs/Modules.html#module-map-language -public struct Parser { - var tokenIterator: AnyIterator - - public init(_ tokenIterator: AnyIterator) { - self.tokenIterator = tokenIterator - } - - // MARK: Parse Functions - - public mutating func parse() throws -> [ModuleDeclarationProtocol] { - var result = [ModuleDeclarationProtocol]() - while true { - guard let module = try nextModule() else { - break - } - result.append(module) - } - return result - } - - mutating func nextModule() throws -> ModuleDeclarationProtocol? { - var prefixTokens = [Token]() - while true { - guard let token = tokenIterator.next() else { - return nil - } - - switch token { - case .newLine: - break - case .reserved(.extern): - guard prefixTokens.isEmpty else { - throw ParserError.unexpectedTokens(prefixTokens, "Collecting module declarations.") - } - return try parseExternModuleDeclaration() - case .reserved(.module): - return try parseModuleDeclaration(isSubmodule: false, prefixTokens: prefixTokens) - default: - prefixTokens.append(token) - } - } - } -} - -// MARK: - Initializers - -public extension Parser { - init(iterator: I) where I: IteratorProtocol, I.Element == Token { - self.init(AnyIterator(iterator)) - } - - init(text: String) { - self.init(iterator: Tokenizer(text: text)) - } -} - -// MARK: - Parse Helper Function - -public extension Parser { - /// Parse the provided string and return the module declarations. - static func parse(_ text: String) throws -> [ModuleDeclarationProtocol] { - var parser = Parser(text: text) - return try parser.parse() - } -} diff --git a/swift/Sources/ModuleMap/ParserError.swift b/swift/Sources/ModuleMap/ParserError.swift deleted file mode 100644 index 2b9b2598..00000000 --- a/swift/Sources/ModuleMap/ParserError.swift +++ /dev/null @@ -1,13 +0,0 @@ -enum ParserError: Error, Equatable { - case endOfTokens(String) - // The first arg is the actual token. The second arg is a message. - case unexpectedToken(Token, String) - // The first arg are the actual tokens. The second arg is a message. - case unexpectedTokens([Token], String) - // The first arg is a message. - case invalidRequiresDeclaration(String) - // The first arg is the string value that could not be converted. The second arg is a message. - case invalidInt(String, String) - // The first arg is the token that triggered the error. The second arg is a message. - case unsupported(Token, String) -} diff --git a/swift/Sources/ModuleMap/RequiresDeclaration.swift b/swift/Sources/ModuleMap/RequiresDeclaration.swift deleted file mode 100644 index 11e31a6f..00000000 --- a/swift/Sources/ModuleMap/RequiresDeclaration.swift +++ /dev/null @@ -1,25 +0,0 @@ -import StructUtils - -/// Spec: https://clang.llvm.org/docs/Modules.html#requires-declaration -struct RequiresDeclaration: Withable, Equatable { - struct Feature: Withable, Equatable { - var name = "" - var compatible = true - - public init() {} - - public init( - name: String, - compatible: Bool = true - ) { - self.name = name - self.compatible = compatible - } - } - - var features = [Feature]() - - public init() {} -} - -extension RequiresDeclaration: ModuleMember {} diff --git a/swift/Sources/ModuleMap/ReservedWord.swift b/swift/Sources/ModuleMap/ReservedWord.swift deleted file mode 100644 index a1a8d52c..00000000 --- a/swift/Sources/ModuleMap/ReservedWord.swift +++ /dev/null @@ -1,18 +0,0 @@ -public enum ReservedWord: String, Equatable { - case configMacros = "config_macros" - case conflict - case exclude - case explicit - case extern - case export - case exportAs = "export_as" - case framework - case header - case link - case module - case `private` - case requires - case textual - case umbrella - case use -} diff --git a/swift/Sources/ModuleMap/StringNavigator.swift b/swift/Sources/ModuleMap/StringNavigator.swift deleted file mode 100644 index 9d5732cb..00000000 --- a/swift/Sources/ModuleMap/StringNavigator.swift +++ /dev/null @@ -1,60 +0,0 @@ -import Foundation - -struct StringNavigator { - let input: String - var currentIndex: String.Index - var markIndex: String.Index - - init(_ input: String) { - self.input = input - currentIndex = input.startIndex - markIndex = currentIndex - } - - mutating func reset() { - currentIndex = input.startIndex - markIndex = input.startIndex - } - - mutating func mark() { - markIndex = currentIndex - } - - mutating func previous() { - guard currentIndex != input.startIndex else { - return - } - currentIndex = input.index(before: currentIndex) - } - - mutating func next() { - guard currentIndex != input.endIndex else { - return - } - currentIndex = input.index(after: currentIndex) - } - - var current: Character? { - guard currentIndex != input.endIndex else { - return nil - } - return input[currentIndex] - } - - var markToCurrent: Substring { - return input[markIndex ..< currentIndex] - } -} - -// MARK: Navigate With CharacterSet - -extension StringNavigator { - mutating func next(whileIn charSet: CharacterSet) { - while true { - guard let char = current, char.isIn(charSet) else { - break - } - next() - } - } -} diff --git a/swift/Sources/ModuleMap/Token.swift b/swift/Sources/ModuleMap/Token.swift deleted file mode 100644 index efe36c80..00000000 --- a/swift/Sources/ModuleMap/Token.swift +++ /dev/null @@ -1,17 +0,0 @@ -public enum Token: Equatable { - case reserved(ReservedWord) - case identifier(String) - case stringLiteral(String) - case integerLiteral(Int) - case floatLiteral(Float) - case comment(String) - case curlyBracketOpen - case curlyBracketClose - case `operator`(Operator) - case newLine - case squareBracketOpen - case squareBracketClose - case exclamationPoint - case comma - case period -} diff --git a/swift/Sources/ModuleMap/Tokenizer.swift b/swift/Sources/ModuleMap/Tokenizer.swift deleted file mode 100644 index 38a39782..00000000 --- a/swift/Sources/ModuleMap/Tokenizer.swift +++ /dev/null @@ -1,173 +0,0 @@ -import Foundation - -/// Specification: https://clang.llvm.org/docs/Modules.html#module-map-language -public struct Tokenizer: Sequence, IteratorProtocol { - enum TokenizerError: Error { - case unrecognizedCharacter(Character) - } - - var inputNavigator: StringNavigator - var errors: [Error] = [] - - public init(text input: String) { - inputNavigator = StringNavigator(input) - } - - public mutating func next() -> Token? { - while true { - guard let char = inputNavigator.current else { - return nil - } - - if char.isIn(.whitespaces) { - // Ignore the character - inputNavigator.next() - } else if char == "{" { - inputNavigator.next() - return .curlyBracketOpen - } else if char == "}" { - inputNavigator.next() - return .curlyBracketClose - } else if char == "[" { - inputNavigator.next() - return .squareBracketOpen - } else if char == "]" { - inputNavigator.next() - return .squareBracketClose - } else if char == "!" { - inputNavigator.next() - return .exclamationPoint - } else if char == "," { - inputNavigator.next() - return .comma - } else if char == "." { - inputNavigator.next() - return .period - } else if char == "\"" { - return collectStringLiteral() - } else if char.isIn(.newlines) { - return collectNewline() - } else if char.isIn(.c99Operators) { - return collectOperator() - } else if char.isIn(.c99NumberBeginningCharacters) { - return collectNumberConstant() - } else if char.isIn(.c99IdentifierBeginningCharacters) { - return collectIdentifier() - } - // We did not recognize the character. Note it and keep trucking. - else { - errors.append(TokenizerError.unrecognizedCharacter(char)) - // Ignore the character - inputNavigator.next() - } - } - } - - mutating func collectIdentifier() -> Token { - inputNavigator.mark() - inputNavigator.next() - while true { - guard - let char = inputNavigator.current, - char.isIn(.c99IdenfitiferCharacters) - else { - break - } - inputNavigator.next() - } - let idStr = String(inputNavigator.markToCurrent) - if let reservedWord = ReservedWord(rawValue: idStr) { - return .reserved(reservedWord) - } - return .identifier(idStr) - } - - mutating func collectNewline() -> Token { - // inputNavigator.mark() - // inputNavigator.next() - // while true { - // guard - // let char = inputNavigator.current, - // char.isIn(.newlines) - // else { - // break - // } - // inputNavigator.next() - // } - inputNavigator.next(whileIn: .newlines) - return .newLine - } - - mutating func collectStringLiteral() -> Token { - // Currently on a string literal delimiter; move forward and mark the start of the string value. - inputNavigator.next() - inputNavigator.mark() - // NOTE: Collecting parts in the event that we implement escape sequence processing. - var parts = [String]() - while true { - guard let char = inputNavigator.current else { - break - } - if char == "\"" { - // Found the end of the string; capture the string value and move past the EOS delimiter - parts.append(String(inputNavigator.markToCurrent)) - inputNavigator.next() - break - } - inputNavigator.next() - } - return .stringLiteral(parts.joined(separator: "")) - } - - mutating func collectOperator() -> Token? { - inputNavigator.next() - // We only support one operator - return .operator(.asterisk) - } - - mutating func collectNumberConstant() -> Token? { - // Currently on the first character of the number constant. - guard let firstChar = inputNavigator.current else { - return nil - } - - // Check for octal or hex value - if firstChar == "0" { - inputNavigator.next() - if let secondChar = inputNavigator.current { - // Hex value - if secondChar.isIn(["x", "X"]) { - inputNavigator.next() - inputNavigator.mark() - inputNavigator.next(whileIn: .c99HexadecimalDigits) - guard let hexValue = Int(String(inputNavigator.markToCurrent), radix: 16) else { - return nil - } - return .integerLiteral(hexValue) - } - // Octal value - inputNavigator.mark() - inputNavigator.next(whileIn: .c99OctalDigits) - guard let octalValue = Int(String(inputNavigator.markToCurrent), radix: 8) else { - return nil - } - return .integerLiteral(octalValue) - } - // No more characters. So, the value is 0 - return .integerLiteral(0) - } - - // Collect the rest of the number digits and see if Swift can parse it. - // This is some weak sauce, but is good enough for the current modulemap parsing. - inputNavigator.mark() - inputNavigator.next(whileIn: .c99NumberCharacters) - let numStr = inputNavigator.markToCurrent - if let int = Int(numStr) { - return .integerLiteral(int) - } - if let float = Float(numStr) { - return .floatLiteral(float) - } - return nil - } -} diff --git a/swift/Sources/ModuleMap/UmbrellaDirectoryDeclaration.swift b/swift/Sources/ModuleMap/UmbrellaDirectoryDeclaration.swift deleted file mode 100644 index 87f9872d..00000000 --- a/swift/Sources/ModuleMap/UmbrellaDirectoryDeclaration.swift +++ /dev/null @@ -1,7 +0,0 @@ -import StructUtils - -/// Spec: https://clang.llvm.org/docs/Modules.html#umbrella-directory-declaration -struct UmbrellaDirectoryDeclaration: Withable, Equatable, ModuleMember { - /// Path to the directory with the headers to be included. - var path = "" -} diff --git a/swift/Sources/ModuleMap/UseDeclaration.swift b/swift/Sources/ModuleMap/UseDeclaration.swift deleted file mode 100644 index a2193ba5..00000000 --- a/swift/Sources/ModuleMap/UseDeclaration.swift +++ /dev/null @@ -1,6 +0,0 @@ -import StructUtils - -/// Spec: https://clang.llvm.org/docs/Modules.html#use-declaration -struct UseDeclaration: Withable, Equatable, ModuleMember { - var moduleID = "" -} diff --git a/swift/Tests/ModuleMapTests/BUILD.bazel b/swift/Tests/ModuleMapTests/BUILD.bazel deleted file mode 100644 index dc8d7b70..00000000 --- a/swift/Tests/ModuleMapTests/BUILD.bazel +++ /dev/null @@ -1,9 +0,0 @@ -load("//build/swift:swift_test.bzl", "swift_test") - -swift_test( - name = "ModuleMapTests", - deps = [ - "//swift/Sources/ModuleMap", - "@cgrindel_swift_toolbox//Sources/Truth", - ], -) diff --git a/swift/Tests/ModuleMapTests/Character+ExtensionsTests.swift b/swift/Tests/ModuleMapTests/Character+ExtensionsTests.swift deleted file mode 100644 index c82bb107..00000000 --- a/swift/Tests/ModuleMapTests/Character+ExtensionsTests.swift +++ /dev/null @@ -1,21 +0,0 @@ -@testable import ModuleMap -import Truth -import XCTest - -class CharacterExtensionsTests: XCTestCase { - func test_isIn() throws { - do_isIn_test(char: "1", charSet: .decimalDigits, expected: true) - do_isIn_test(char: "a", charSet: .decimalDigits, expected: false) - do_isIn_test(char: "😉", charSet: .decimalDigits, expected: false) - } - - func do_isIn_test( - char: Character, - charSet: CharacterSet, - expected: Bool, - file: StaticString = #file, - line: UInt = #line - ) { - assertThat(char.isIn(charSet)).isEqualTo(expected, file: file, line: line) - } -} diff --git a/swift/Tests/ModuleMapTests/Parser+ExportAsDeclarationExtsTests.swift b/swift/Tests/ModuleMapTests/Parser+ExportAsDeclarationExtsTests.swift deleted file mode 100644 index fb9c74dd..00000000 --- a/swift/Tests/ModuleMapTests/Parser+ExportAsDeclarationExtsTests.swift +++ /dev/null @@ -1,20 +0,0 @@ -@testable import ModuleMap -import Truth -import XCTest - -class ParserExportAsDeclarationExtsTests: XCTestCase { - func test_parse_ForModule_WithExportAs() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: ExportAsDeclaration.self, - text: """ - module MyModule { - export_as Foo - } - """ - ) { - $0.isEqualTo(.with { - $0.identifier = "Foo" - }) - } - } -} diff --git a/swift/Tests/ModuleMapTests/Parser+ExportDeclarationExtsTests.swift b/swift/Tests/ModuleMapTests/Parser+ExportDeclarationExtsTests.swift deleted file mode 100644 index 1d9f3658..00000000 --- a/swift/Tests/ModuleMapTests/Parser+ExportDeclarationExtsTests.swift +++ /dev/null @@ -1,51 +0,0 @@ -@testable import ModuleMap -import Truth -import XCTest - -class ParserExportDeclarationExtsTests: XCTestCase { - func test_parse_ForModule_WithExportDeclWildcard_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: ExportDeclaration.self, - text: """ - module MyModule { - export * - } - """ - ) { - $0.isEqualTo(.with { - $0.wildcard = true - }) - } - } - - func test_parse_ForModule_WithExportDeclIdentifiers_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: ExportDeclaration.self, - text: """ - module MyModule { - export foo.bar - } - """ - ) { - $0.isEqualTo(.with { - $0.identifiers = ["foo", "bar"] - }) - } - } - - func test_parse_ForModule_WithExportDeclIdentifiersAndWildcard_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: ExportDeclaration.self, - text: """ - module MyModule { - export foo.bar.* - } - """ - ) { - $0.isEqualTo(.with { - $0.identifiers = ["foo", "bar"] - $0.wildcard = true - }) - } - } -} diff --git a/swift/Tests/ModuleMapTests/Parser+ExternModuleExtsTests.swift b/swift/Tests/ModuleMapTests/Parser+ExternModuleExtsTests.swift deleted file mode 100644 index 56165b22..00000000 --- a/swift/Tests/ModuleMapTests/Parser+ExternModuleExtsTests.swift +++ /dev/null @@ -1,80 +0,0 @@ -@testable import ModuleMap -import Truth -import XCTest - -class ParserExternModuleExtsTests: XCTestCase { - func test_parse_ForExternModule_Success() throws { - let text = """ - extern module MyModule "path/to/def/module.modulemap" - """ - let result = try Parser.parse(text) - assertThat(result) - .hasCount(1) - .firstItem { - $0.isA(ExternModuleDeclaration.self) { - $0.key(\.moduleID) { $0.isEqualTo("MyModule") } - .key(\.definitionPath) { $0.isEqualTo("path/to/def/module.modulemap") } - } - } - } - - func test_parse_ForExternModule_MissingModuleToken_Failure() throws { - let text = """ - extern MyModule "path/to/def/module.modulemap" - """ - assertThat { try Parser.parse(text) }.doesThrow( - ParserError.unexpectedToken( - .identifier("MyModule"), - "Expected the module token while parsing an extern module." - ) - ) - } - - func test_parse_ForExternModule_MissingModuleIDToken_Failure() throws { - let text = """ - extern module "path/to/def/module.modulemap" - """ - assertThat { try Parser.parse(text) }.doesThrow( - ParserError.unexpectedToken( - .stringLiteral("path/to/def/module.modulemap"), - "Expected the module id token while parsing an extern module." - ) - ) - } - - func test_parse_ForExternModule_MissingPathToken_Failure() throws { - let text = """ - extern module MyModule foo - """ - assertThat { try Parser.parse(text) }.doesThrow( - ParserError.unexpectedToken( - .identifier("foo"), - "Expected a string literal token for the path while parsing an extern module." - ) - ) - } - - func test_parse_ForExternModule_PrematureEOT() throws { - var text = """ - extern - """ - assertThat { try Parser.parse(text) }.doesThrow( - ParserError.endOfTokens("Looking for the module token while parsing an extern module.") - ) - - text = """ - extern module - """ - assertThat { try Parser.parse(text) }.doesThrow( - ParserError.endOfTokens("Looking for the module id token while parsing an extern module.") - ) - - text = """ - extern module MyModule - """ - assertThat { try Parser.parse(text) }.doesThrow( - ParserError - .endOfTokens("Looking for the module definition path token while parsing an extern module.") - ) - } -} diff --git a/swift/Tests/ModuleMapTests/Parser+HeaderDeclarationExtsTests.swift b/swift/Tests/ModuleMapTests/Parser+HeaderDeclarationExtsTests.swift deleted file mode 100644 index 5ec66143..00000000 --- a/swift/Tests/ModuleMapTests/Parser+HeaderDeclarationExtsTests.swift +++ /dev/null @@ -1,103 +0,0 @@ -@testable import ModuleMap -import Truth -import XCTest - -class ParserHeaderDeclarationExtsTests: XCTestCase { - func test_parse_ForModule_WithSingleHeaderDeclNoQualifiers_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: HeaderDeclaration.self, - text: """ - module MyModule { - header "path/to/header.h" - } - """ - ) { - $0.isEqualTo(.with { - $0.type = .single(.init()) - $0.path = "path/to/header.h" - }) - } - } - - func test_parse_ForModule_WithSingleHeaderDeclNoQualifiersWithAttribs_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: HeaderDeclaration.self, - text: """ - module MyModule { - header "path/to/header.h" { size 1234 mtime 5678 } - } - """ - ) { - $0.isEqualTo(.with { - $0.type = .single(.init()) - $0.path = "path/to/header.h" - $0.size = 1234 - $0.mtime = 5678 - }) - } - } - - func test_parse_ForModule_WithSingleHeaderDeclAsPrivate_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: HeaderDeclaration.self, - text: """ - module MyModule { - private header "path/to/header.h" - } - """ - ) { - $0.isEqualTo(.with { - $0.type = .single(.with { $0.privateHeader = true }) - $0.path = "path/to/header.h" - }) - } - } - - func test_parse_ForModule_WithSingleHeaderDeclAsTextual_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: HeaderDeclaration.self, - text: """ - module MyModule { - textual header "path/to/header.h" - } - """ - ) { - $0.isEqualTo(.with { - $0.type = .single(.with { $0.textual = true }) - $0.path = "path/to/header.h" - }) - } - } - - func test_parse_ForModule_WithUmbrellaHeader_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: HeaderDeclaration.self, - text: """ - module MyModule { - umbrella header "path/to/header.h" - } - """ - ) { - $0.isEqualTo(.with { - $0.type = .umbrella - $0.path = "path/to/header.h" - }) - } - } - - func test_parse_ForModule_WithExcludeHeader_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: HeaderDeclaration.self, - text: """ - module MyModule { - exclude header "path/to/header.h" - } - """ - ) { - $0.isEqualTo(.with { - $0.type = .exclude - $0.path = "path/to/header.h" - }) - } - } -} diff --git a/swift/Tests/ModuleMapTests/Parser+LinkDeclarationExtsTests.swift b/swift/Tests/ModuleMapTests/Parser+LinkDeclarationExtsTests.swift deleted file mode 100644 index c856d7b5..00000000 --- a/swift/Tests/ModuleMapTests/Parser+LinkDeclarationExtsTests.swift +++ /dev/null @@ -1,36 +0,0 @@ -@testable import ModuleMap -import Truth -import XCTest - -class ParserLinkDeclarationExtsTests: XCTestCase { - func test_parse_ForModule_WithLinkDeclNoFramework_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: LinkDeclaration.self, - text: """ - module MyModule { - link "LibName" - } - """ - ) { - $0.isEqualTo(.with { - $0.name = "LibName" - }) - } - } - - func test_parse_ForModule_WithLinkDeclAsFramework_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: LinkDeclaration.self, - text: """ - module MyModule { - link framework "LibName" - } - """ - ) { - $0.isEqualTo(.with { - $0.name = "LibName" - $0.framework = true - }) - } - } -} diff --git a/swift/Tests/ModuleMapTests/Parser+ModuleExtsTests.swift b/swift/Tests/ModuleMapTests/Parser+ModuleExtsTests.swift deleted file mode 100644 index e46ac7d1..00000000 --- a/swift/Tests/ModuleMapTests/Parser+ModuleExtsTests.swift +++ /dev/null @@ -1,190 +0,0 @@ -@testable import ModuleMap -import Truth -import XCTest - -class ParserModuleExtsTests: XCTestCase { - // MARK: Top-Level Module Parsing - - func test_parse_ForModule_WithoutQualifiersAttributesAndMembers_Success() throws { - let text = """ - module MyModule {} - """ - let result = try Parser.parse(text) - assertThat(result) - .hasCount(1) - .firstItem { - $0.isA(ModuleDeclaration.self) { - $0.key(\.moduleID) { $0.isEqualTo("MyModule") } - .key(\.framework) { $0.isFalse() } - .key(\.explicit) { $0.isFalse() } - .key(\.attributes) { $0.isEmpty() } - .key(\.members) { $0.isEmpty() } - } - } - } - - func test_parse_ForModule_WithQualifiers_Success() throws { - let text = """ - framework module MyModule {} - """ - let result = try Parser.parse(text) - assertThat(result) - .hasCount(1) - .firstItem { - $0.isA(ModuleDeclaration.self) { - $0.key(\.moduleID) { $0.isEqualTo("MyModule") } - .key(\.framework) { $0.isTrue() } - .key(\.explicit) { $0.isFalse() } - .key(\.attributes) { $0.isEmpty() } - .key(\.members) { $0.isEmpty() } - } - } - } - - func test_parse_ForModule_WithAttributes_Success() throws { - let text = """ - module MyModule [system] [extern_c] {} - """ - let result = try Parser.parse(text) - assertThat(result) - .hasCount(1) - .firstItem { - $0.isA(ModuleDeclaration.self) { - $0.key(\.moduleID) { $0.isEqualTo("MyModule") } - .key(\.framework) { $0.isFalse() } - .key(\.explicit) { $0.isFalse() } - .key(\.attributes) { $0.isEqualTo(["system", "extern_c"]) } - .key(\.members) { $0.isEmpty() } - } - } - } - - func test_parse_ForModule_WithUnexpectedQualifier_Failure() throws { - let text = """ - unexpected module MyModule {} - """ - assertThat { try Parser.parse(text) }.doesThrow( - ParserError.unexpectedToken( - .identifier("unexpected"), - "Collecting qualifiers for module declaration." - ) - ) - } - - func test_parse_ForModule_WithMissingModuleID_Failure() throws { - let text = """ - module {} - """ - assertThat { try Parser.parse(text) }.doesThrow( - ParserError.unexpectedToken( - .curlyBracketOpen, - "Looking for the module id token while parsing a module." - ) - ) - } - - func test_parse_ForModule_WithMalformedAttribute_Failure() throws { - let text = """ - module MyModule [system {} - """ - assertThat { try Parser.parse(text) }.doesThrow( - ParserError.unexpectedToken( - .curlyBracketOpen, - "Collecting closing square bracket (]) for MyModule module." - ) - ) - } - - // MARK: Submodules - - func test_parse_ForModule_WithSubmodule_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: ModuleDeclaration.self, - text: """ - module MyModule { - module SubModule { - header "SubModule.h" - export * - } - } - """ - ) { - $0.key(\.moduleID) { $0.isEqualTo("SubModule") } - .key(\.members) { - $0.hasCount(2) - .firstItem { - $0.isA(HeaderDeclaration.self) { $0.isEqualTo(.with { $0.path = "SubModule.h" }) } - } - .lastItem { - $0.isA(ExportDeclaration.self) { $0.isEqualTo(.with { $0.wildcard = true }) } - } - } - } - } - - func test_parse_ForModule_WithExplicitSubmodule_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: ModuleDeclaration.self, - text: """ - module MyModule { - explicit module SubModule { - header "SubModule.h" - export * - } - } - """ - ) { - $0.key(\.moduleID) { $0.isEqualTo("SubModule") } - .key(\.explicit) { $0.isTrue() } - .key(\.members) { - $0.hasCount(2) - .firstItem { - $0.isA(HeaderDeclaration.self) { $0.isEqualTo(.with { $0.path = "SubModule.h" }) } - } - .lastItem { - $0.isA(ExportDeclaration.self) { $0.isEqualTo(.with { $0.wildcard = true }) } - } - } - } - } - - func test_parse_ForModule_WithExplicitOnTopLevelModule_Fail() throws { - let text = """ - explicit module MyModule {} - """ - assertThat { try Parser.parse(text) }.doesThrow( - ParserError.unexpectedToken( - .reserved(.explicit), - "The explicit qualifier can only exist on submodules." - ) - ) - } - - func test_parse_ForModule_WithConfigMacros_Fail() throws { - let text = """ - module MyModule { - config_macros macroA - } - """ - assertThat { try Parser.parse(text) }.doesThrow( - ParserError.unsupported( - .reserved(.configMacros), - "This module member is currently not supported." - ) - ) - } - - func test_parse_ForModule_WithConflict_Fail() throws { - let text = """ - module MyModule { - conflict AnotherModule, "Message why incompatible." - } - """ - assertThat { try Parser.parse(text) }.doesThrow( - ParserError.unsupported( - .reserved(.conflict), - "This module member is currently not supported." - ) - ) - } -} diff --git a/swift/Tests/ModuleMapTests/Parser+RequiresDeclarationExtsTests.swift b/swift/Tests/ModuleMapTests/Parser+RequiresDeclarationExtsTests.swift deleted file mode 100644 index 098a7278..00000000 --- a/swift/Tests/ModuleMapTests/Parser+RequiresDeclarationExtsTests.swift +++ /dev/null @@ -1,52 +0,0 @@ -@testable import ModuleMap -import Truth -import XCTest - -class ParserRequiresDeclarationExtsTests: XCTestCase { - func test_parse_ForModule_WithRequiresDeclOneFeature_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: RequiresDeclaration.self, - text: """ - module MyModule { - requires c99 - } - """ - ) { - $0.isEqualTo(.with { - $0.features = [.with { $0.name = "c99" }] - }) - } - } - - func test_parse_ForModule_WithRequiresDeclMultiFeature_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: RequiresDeclaration.self, - text: """ - module MyModule { - requires c99, !win32, tls - } - """ - ) { - $0.isEqualTo(.with { - $0.features = [ - .init(name: "c99"), - .init(name: "win32", compatible: false), - .init(name: "tls"), - ] - }) - } - } - - func test_parse_ForModule_WithRequiresDeclNoFeatures_Failure() throws { - let text = """ - module MyModule { - requires - } - """ - assertThat { try Parser.parse(text) }.doesThrow( - ParserError.invalidRequiresDeclaration( - "No features were found for requires declaration in MyModule module." - ) - ) - } -} diff --git a/swift/Tests/ModuleMapTests/Parser+UmbrellaDirectoryDeclarationExtsTests.swift b/swift/Tests/ModuleMapTests/Parser+UmbrellaDirectoryDeclarationExtsTests.swift deleted file mode 100644 index b3d86b31..00000000 --- a/swift/Tests/ModuleMapTests/Parser+UmbrellaDirectoryDeclarationExtsTests.swift +++ /dev/null @@ -1,57 +0,0 @@ -@testable import ModuleMap -import Truth -import XCTest - -class ParserUmbrellaDirectoryDeclarationExtsTests: XCTestCase { - func do_parse_ForModule_UmbrellaDirectory_test( - _ text: String, - file: StaticString = #file, line: UInt = #line, - subjectConsumer: (Subject) -> Void - ) throws { - let result = try Parser.parse(text) - assertThat(result) - .hasCount(1) - .firstItem { - $0.isA(ModuleDeclaration.self, file: file, line: line) { - $0.key(file: file, line: line, \.moduleID) { - $0.isEqualTo("MyModule", file: file, line: line) - } - .key(file: file, line: line, \.members) { - $0.hasCount(1, file: file, line: line) - .firstItem { - $0.isA(UmbrellaDirectoryDeclaration.self, file: file, line: line, subjectConsumer) - } - } - } - } - } - - func test_parse_ForModule_WithUmbrellaDirDecl_Success() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: UmbrellaDirectoryDeclaration.self, - text: """ - module MyModule { - umbrella "path/to/header/files" - } - """ - ) { - $0.isEqualTo(.with { - $0.path = "path/to/header/files" - }) - } - } - - func test_parse_ForModule_WithUmbrellaDirDeclMissingPath_Fail() throws { - let text = """ - module MyModule { - umbrella - } - """ - assertThat { try Parser.parse(text) }.doesThrow( - ParserError.unexpectedToken( - .newLine, - "Collecting the directory path for the umbrella directory declaration for MyModule module." - ) - ) - } -} diff --git a/swift/Tests/ModuleMapTests/Parser+UseDeclarationExtsTests.swift b/swift/Tests/ModuleMapTests/Parser+UseDeclarationExtsTests.swift deleted file mode 100644 index c8036105..00000000 --- a/swift/Tests/ModuleMapTests/Parser+UseDeclarationExtsTests.swift +++ /dev/null @@ -1,20 +0,0 @@ -@testable import ModuleMap -import Truth -import XCTest - -class ParserUseDeclarationExtsTests: XCTestCase { - func test_parse_ForModule_WithUseDecl_Expectation() throws { - try do_parse_ForModule_ModuleMember_test( - expectedType: UseDeclaration.self, - text: """ - module MyModule { - use AnotherModule - } - """ - ) { - $0.isEqualTo(.with { - $0.moduleID = "AnotherModule" - }) - } - } -} diff --git a/swift/Tests/ModuleMapTests/ParserTests.swift b/swift/Tests/ModuleMapTests/ParserTests.swift deleted file mode 100644 index df79c5c4..00000000 --- a/swift/Tests/ModuleMapTests/ParserTests.swift +++ /dev/null @@ -1,36 +0,0 @@ -@testable import ModuleMap -import Truth -import XCTest - -class ParserTests: XCTestCase { - // MARK: Empty String - - func test_parse_EmptyString_Success() throws { - let result = try Parser.parse("") - assertThat(result).isEmpty() - } - - // MARK: Multiple Modules - - func test_parse_MultipleTopLevelModules_Success() throws { - let text = """ - extern module MyModule "path/to/def/module.modulemap" - extern module AnotherModule "another/path/to/def/module.modulemap" - """ - let result = try Parser.parse(text) - assertThat(result) - .hasCount(2) - .firstItem { - $0.isA(ExternModuleDeclaration.self) { - $0.key(\.moduleID) { $0.isEqualTo("MyModule") } - .key(\.definitionPath) { $0.isEqualTo("path/to/def/module.modulemap") } - } - } - .lastItem { - $0.isA(ExternModuleDeclaration.self) { - $0.key(\.moduleID) { $0.isEqualTo("AnotherModule") } - .key(\.definitionPath) { $0.isEqualTo("another/path/to/def/module.modulemap") } - } - } - } -} diff --git a/swift/Tests/ModuleMapTests/StringNavigatorTests.swift b/swift/Tests/ModuleMapTests/StringNavigatorTests.swift deleted file mode 100644 index 5ab8cc34..00000000 --- a/swift/Tests/ModuleMapTests/StringNavigatorTests.swift +++ /dev/null @@ -1,100 +0,0 @@ -@testable import ModuleMap -import Truth -import XCTest - -class StringNavigatorTests: XCTestCase { - let input = "Hello, Chicken!" - lazy var navigator = { StringNavigator(input) }() - - // swiftlint:disable function_body_length - func test_navigation_WithNonEmptyString() throws { - assertThat(navigator) - .key(\.input) { $0.isEqualTo(input) } - .key(\.currentIndex) { $0.isEqualTo(input.startIndex) } - .key(\.markIndex) { $0.isEqualTo(input.startIndex) } - .key(\.markToCurrent) { $0.isEqualTo("") } - .key(\.current) { $0.isNotNil { $0.isEqualTo("H") } } - - navigator.next() - assertThat(navigator) - .key(\.currentIndex) { $0.isEqualTo(input.index(after: input.startIndex)) } - .key(\.markIndex) { $0.isEqualTo(input.startIndex) } - .key(\.markToCurrent) { $0.isEqualTo("H") } - .key(\.current) { $0.isNotNil { $0.isEqualTo("e") } } - - navigator.previous() - assertThat(navigator) - .key(\.currentIndex) { $0.isEqualTo(input.startIndex) } - .key(\.markIndex) { $0.isEqualTo(input.startIndex) } - .key(\.markToCurrent) { $0.isEqualTo("") } - .key(\.current) { $0.isNotNil { $0.isEqualTo("H") } } - - // Try to navigate before the start of the input - navigator.previous() - assertThat(navigator) - .key(\.currentIndex) { $0.isEqualTo(input.startIndex) } - .key(\.markIndex) { $0.isEqualTo(input.startIndex) } - .key(\.markToCurrent) { $0.isEqualTo("") } - .key(\.current) { $0.isNotNil { $0.isEqualTo("H") } } - - // Navigate to the end of the input - for _ in 0 ..< input.count { - navigator.next() - } - assertThat(navigator) - .key(\.currentIndex) { $0.isEqualTo(input.endIndex) } - .key(\.markIndex) { $0.isEqualTo(input.startIndex) } - .key(\.markToCurrent) { $0.isEqualTo("Hello, Chicken!") } - .key(\.current) { $0.isNil() } - - // Try to navigate past the end of the input - navigator.next() - assertThat(navigator) - .key(\.currentIndex) { $0.isEqualTo(input.endIndex) } - .key(\.markIndex) { $0.isEqualTo(input.startIndex) } - .key(\.current) { $0.isNil() } - - // Reset to the beginning - navigator.reset() - assertThat(navigator) - .key(\.input) { $0.isEqualTo(input) } - .key(\.currentIndex) { $0.isEqualTo(input.startIndex) } - .key(\.markIndex) { $0.isEqualTo(input.startIndex) } - .key(\.markToCurrent) { $0.isEqualTo("") } - .key(\.current) { $0.isNotNil { $0.isEqualTo("H") } } - - // Mark a substring - navigator.next() - navigator.mark() - for _ in 0 ..< 4 { - navigator.next() - } - assertThat(navigator) - .key(\.markToCurrent) { $0.isEqualTo("ello") } - .key(\.current) { $0.isNotNil { $0.isEqualTo(",") } } - } - - // swiftlint:enable function_body_length - - func test_WithEmptyString() throws { - var navigator = StringNavigator("") - assertThat(navigator) - .key(\.input) { $0.isEqualTo("") } - .key(\.currentIndex) { $0.isEqualTo(input.startIndex) } - .key(\.markIndex) { $0.isEqualTo(input.startIndex) } - .key(\.markToCurrent) { $0.isEqualTo("") } - .key(\.current) { $0.isNil() } - - // Making sure that nothing causes a fatal error - navigator.next() - navigator.previous() - navigator.mark() - } - - func test_nextWhileIn() throws { - var navigator = StringNavigator("1234 5678") - navigator.mark() - navigator.next(whileIn: .decimalDigits) - assertThat(navigator.markToCurrent).isEqualTo("1234") - } -} diff --git a/swift/Tests/ModuleMapTests/TokenizerTests.swift b/swift/Tests/ModuleMapTests/TokenizerTests.swift deleted file mode 100644 index 6d140521..00000000 --- a/swift/Tests/ModuleMapTests/TokenizerTests.swift +++ /dev/null @@ -1,110 +0,0 @@ -@testable import ModuleMap -import Truth -import XCTest - -class TokenizerTests: XCTestCase { - static let umbrellaHdrStr = """ - module CNIOAtomics [system] { - umbrella header "CNIOAtomics.h" - export * - } - """ - - func test_umbrellaHeaderExample() throws { - let tokenizer = Tokenizer(text: Self.umbrellaHdrStr) - let tokens = Array(tokenizer) - let expected: [Token] = [ - .reserved(.module), - .identifier("CNIOAtomics"), - .squareBracketOpen, - .identifier("system"), - .squareBracketClose, - .curlyBracketOpen, - .newLine, - .reserved(.umbrella), - .reserved(.header), - .stringLiteral("CNIOAtomics.h"), - .newLine, - .reserved(.export), - .operator(.asterisk), - .newLine, - .curlyBracketClose, - ] - assertThat(tokens).isEqualTo(expected) - } - - func test_base10Int() throws { - let tokens = Array(Tokenizer(text: "1234 5678")) - let expected: [Token] = [.integerLiteral(1234), .integerLiteral(5678)] - assertThat(tokens).isEqualTo(expected) - } - - func test_base16Int() throws { - let tokens = Array(Tokenizer(text: "0xa2B4 0XAF")) - let expected: [Token] = [ - .integerLiteral(Int("a2B4", radix: 16)!), - .integerLiteral(Int("AF", radix: 16)!), - ] - assertThat(tokens).isEqualTo(expected) - } - - func test_base8Int() throws { - let tokens = Array(Tokenizer(text: "0123 0456")) - let expected: [Token] = [ - .integerLiteral(Int("123", radix: 8)!), - .integerLiteral(Int("456", radix: 8)!), - ] - assertThat(tokens).isEqualTo(expected) - } - - func test_float() throws { - let tokens = Array(Tokenizer(text: "12.34 56.78")) - let expected: [Token] = [.floatLiteral(12.34), .floatLiteral(56.78)] - assertThat(tokens).isEqualTo(expected) - } - - func test_period() throws { - let tokens = Array(Tokenizer(text: ". foo.bar 12.34")) - let expected: [Token] = [ - .period, - .identifier("foo"), - .period, - .identifier("bar"), - .floatLiteral(12.34), - ] - assertThat(tokens).isEqualTo(expected) - } - - // static let submoduleStr = """ - // module std [system] [extern_c] { - // module assert { - // textual header "assert.h" - // header "bits/assert-decls.h" - // export * - // } - - // module complex { - // header "complex.h" - // export * - // } - - // module ctype { - // header "ctype.h" - // export * - // } - - // module errno { - // header "errno.h" - // header "sys/errno.h" - // export * - // } - - // module fenv { - // header "fenv.h" - // export * - // } - - // // ...more headers follow... - // } - // """ -} diff --git a/swift/Tests/ModuleMapTests/XCTestCase+Extensions.swift b/swift/Tests/ModuleMapTests/XCTestCase+Extensions.swift deleted file mode 100644 index 2c2ddc1e..00000000 --- a/swift/Tests/ModuleMapTests/XCTestCase+Extensions.swift +++ /dev/null @@ -1,30 +0,0 @@ -import ModuleMap -import Truth -import XCTest - -public extension XCTestCase { - func do_parse_ForModule_ModuleMember_test( - expectedType _: MM.Type, - file: StaticString = #file, - line: UInt = #line, - text: String, - subjectConsumer: (Subject) -> Void - ) throws { - let result = try Parser.parse(text) - assertThat(result) - .hasCount(1) - .firstItem { - $0.isA(ModuleDeclaration.self, file: file, line: line) { - $0.key(file: file, line: line, \.moduleID) { - $0.isEqualTo("MyModule", file: file, line: line) - } - .key(file: file, line: line, \.members) { - $0.hasCount(1, file: file, line: line) - .firstItem { - $0.isA(MM.self, file: file, line: line, subjectConsumer) - } - } - } - } - } -} diff --git a/swiftformat b/swiftformat deleted file mode 100755 index b6488b4f..00000000 --- a/swiftformat +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env zsh - -# This file exists to support formatting in vim using vim-ale. -# This script ensures that the config file is used when formatting. - -set -euo pipefail - -script_dir="${0:A:h}" -config_file="${script_dir}/.swiftformat" - -swiftformat --config "${config_file}" "${@}" diff --git a/swiftlint b/swiftlint deleted file mode 100755 index c1a7b07b..00000000 --- a/swiftlint +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env zsh - -# This file exists to support linting in vim using vim-ale. -# This script ensures that the config file is used when linting. - -set -euo pipefail - -script_dir="${0:A:h}" -config_file="${script_dir}/.swiftlint.yml" - -swiftlint --config "${config_file}" "${@}" - - -