diff --git a/pmd-swift/src/main/antlr4/net/sourceforge/pmd/lang/swift/antlr4/Swift.g4 b/pmd-swift/src/main/antlr4/net/sourceforge/pmd/lang/swift/antlr4/Swift.g4 index d6277137dc..0eb9f7517e 100644 --- a/pmd-swift/src/main/antlr4/net/sourceforge/pmd/lang/swift/antlr4/Swift.g4 +++ b/pmd-swift/src/main/antlr4/net/sourceforge/pmd/lang/swift/antlr4/Swift.g4 @@ -894,11 +894,14 @@ platformCondition : 'os' '(' operatingSystem ')' | 'arch' '(' architecture ')' | 'swift' '(' '>=' swiftVersion ')' + | 'canImport' '(' moduleName ')' + | 'targetEnvironment' '(' 'simulator' ')' ; operatingSystem: 'OSX' | 'iOS' | 'watchOS' | 'tvOS' ; architecture: 'i386' | 'x86_64' | 'arm' | 'arm64' ; swiftVersion: FloatingPointLiteral ; +moduleName: IdentifierCharacters ; lineControlStatement: '#sourceLocation' '(' 'file' ':' fileName ',' 'line' ':' lineNumber ')' | '#sourceLocation' '(' ')' ; diff --git a/pmd-swift/src/test/java/net/sourceforge/pmd/cpd/SwiftTokenizerTest.java b/pmd-swift/src/test/java/net/sourceforge/pmd/cpd/SwiftTokenizerTest.java index f09619dd01..5c6870686d 100644 --- a/pmd-swift/src/test/java/net/sourceforge/pmd/cpd/SwiftTokenizerTest.java +++ b/pmd-swift/src/test/java/net/sourceforge/pmd/cpd/SwiftTokenizerTest.java @@ -30,7 +30,7 @@ public class SwiftTokenizerTest extends AbstractTokenizerTest { @Test public void tokenizeTest() throws IOException { - this.expectedTokenCount = 4217; + this.expectedTokenCount = 4239; super.tokenizeTest(); } } diff --git a/pmd-swift/src/test/resources/net/sourceforge/pmd/cpd/BTree.swift b/pmd-swift/src/test/resources/net/sourceforge/pmd/cpd/BTree.swift index 33a60c91d8..9b283a3ec8 100644 --- a/pmd-swift/src/test/resources/net/sourceforge/pmd/cpd/BTree.swift +++ b/pmd-swift/src/test/resources/net/sourceforge/pmd/cpd/BTree.swift @@ -1003,3 +1003,13 @@ class MyClass { let myClass = MyClass() //myClass.delegate = View() // error: cannot assign value of type 'View' to type '(View & MyProtocol)?' myClass.delegate = ViewSubclass() + +// 4.1 conditional + +#if canImport(SomeModule) +let someModuleImportedVersion = SomeModule.version +#endif + +#if targetEnvironment(simulator) +print("code only compiled for simulator") +#endif