From 019f8c20ff07406b468dff83fd53320c01ff6496 Mon Sep 17 00:00:00 2001 From: Fabio Rodella Date: Tue, 12 May 2015 11:25:12 -0300 Subject: [PATCH 1/2] Support access modifiers in Swift regexes --- StencilPlugin/Model/TemplateConfig.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/StencilPlugin/Model/TemplateConfig.m b/StencilPlugin/Model/TemplateConfig.m index 9efd525..f44524c 100644 --- a/StencilPlugin/Model/TemplateConfig.m +++ b/StencilPlugin/Model/TemplateConfig.m @@ -63,10 +63,10 @@ + (NSOrderedSet *)objcMapsFromFileAtPath:(NSString *)filePath + (NSOrderedSet *)swiftMapsFromFileAtPath:(NSString *)filePath { NSMutableOrderedSet *maps = [NSMutableOrderedSet new]; - [self processFileAtPath:filePath matching:@"^\\s*extension\\s+(\\w+).*" thingType:STCThingTypeSwiftClass maps:maps]; - [self processFileAtPath:filePath matching:@"^\\s*class\\s+(\\w+).*" thingType:STCThingTypeSwiftClass maps:maps]; - [self processFileAtPath:filePath matching:@"^\\s*class\\s+(\\w+)\\s*:\\s*(\\w+).*" thingType:STCThingTypeSwiftClass maps:maps]; - [self processFileAtPath:filePath matching:@"^\\s*protocol\\s+(\\w+)\\s*:\\s*(\\w+).*" thingType:STCThingTypeSwiftProtocol maps:maps]; + [self processFileAtPath:filePath matching:@"^[@objc|public|private|internal]*\\s*extension\\s+(\\w+).*" thingType:STCThingTypeSwiftClass maps:maps]; + [self processFileAtPath:filePath matching:@"^[@objc|public|private|internal]*\\s*class\\s+(\\w+).*" thingType:STCThingTypeSwiftClass maps:maps]; + [self processFileAtPath:filePath matching:@"^[@objc|public|private|internal]*\\s*class\\s+(\\w+)\\s*:\\s*(\\w+).*" thingType:STCThingTypeSwiftClass maps:maps]; + [self processFileAtPath:filePath matching:@"^[@objc|public|private|internal]*\\s*protocol\\s+(\\w+)\\s*:\\s*(\\w+).*" thingType:STCThingTypeSwiftProtocol maps:maps]; return maps.copy; } From 5d69211f209cbc63966b88f2c728f580c32a1a7d Mon Sep 17 00:00:00 2001 From: Fabio Rodella Date: Wed, 13 May 2015 08:48:58 -0300 Subject: [PATCH 2/2] Correctly handle the @objc directive, with or without an exposed name --- StencilPlugin/Model/TemplateConfig.m | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/StencilPlugin/Model/TemplateConfig.m b/StencilPlugin/Model/TemplateConfig.m index f44524c..c81a1c6 100644 --- a/StencilPlugin/Model/TemplateConfig.m +++ b/StencilPlugin/Model/TemplateConfig.m @@ -62,11 +62,14 @@ + (NSOrderedSet *)objcMapsFromFileAtPath:(NSString *)filePath + (NSOrderedSet *)swiftMapsFromFileAtPath:(NSString *)filePath { + NSString *objcPrefix = @"(?:@objc(?:\\s*\\(\\s*\\w+\\s*\\))?)?"; + NSString *accessPrefix = @"(?:public|private|internal)?"; + NSMutableOrderedSet *maps = [NSMutableOrderedSet new]; - [self processFileAtPath:filePath matching:@"^[@objc|public|private|internal]*\\s*extension\\s+(\\w+).*" thingType:STCThingTypeSwiftClass maps:maps]; - [self processFileAtPath:filePath matching:@"^[@objc|public|private|internal]*\\s*class\\s+(\\w+).*" thingType:STCThingTypeSwiftClass maps:maps]; - [self processFileAtPath:filePath matching:@"^[@objc|public|private|internal]*\\s*class\\s+(\\w+)\\s*:\\s*(\\w+).*" thingType:STCThingTypeSwiftClass maps:maps]; - [self processFileAtPath:filePath matching:@"^[@objc|public|private|internal]*\\s*protocol\\s+(\\w+)\\s*:\\s*(\\w+).*" thingType:STCThingTypeSwiftProtocol maps:maps]; + [self processFileAtPath:filePath matching:[NSString stringWithFormat:@"^\\s*%@\\s*%@\\s*extension\\s+(\\w+).*", objcPrefix, accessPrefix] thingType:STCThingTypeSwiftClass maps:maps]; + [self processFileAtPath:filePath matching:[NSString stringWithFormat:@"^\\s*%@\\s*%@\\s*class\\s+(\\w+).*", objcPrefix, accessPrefix] thingType:STCThingTypeSwiftClass maps:maps]; + [self processFileAtPath:filePath matching:[NSString stringWithFormat:@"^\\s*%@\\s*%@\\s*class\\s+(\\w+)\\s*:\\s*(\\w+).*", objcPrefix, accessPrefix] thingType:STCThingTypeSwiftClass maps:maps]; + [self processFileAtPath:filePath matching:[NSString stringWithFormat:@"^\\s*%@\\s*%@\\s*protocol\\s+(\\w+)\\s*:\\s*(\\w+).*", objcPrefix, accessPrefix] thingType:STCThingTypeSwiftProtocol maps:maps]; return maps.copy; }