Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

Commit

Permalink
Merge pull request #37 from onevcat/fix/brace-in-args
Browse files Browse the repository at this point in the history
Fix/brace in args
  • Loading branch information
onevcat committed Feb 3, 2014
2 parents 4c8e29d + 2ab2d6c commit c676f13
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 31 deletions.
3 changes: 2 additions & 1 deletion VVDocumenter-Xcode/Commenter/VVArgument.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ -(void)setType:(NSString *)type
-(void)setName:(NSString *)name
{
if (name != _name) {
_name = [[[[[[name vv_stringByReplacingRegexPattern:@"^&" withString:@""]
_name = [[[[[[[name vv_stringByReplacingRegexPattern:@"\\(|\\)" withString:@""]
vv_stringByReplacingRegexPattern:@"^&" withString:@""]
vv_stringByReplacingRegexPattern:@"^\\*+" withString:@""]
vv_stringByReplacingRegexPattern:@"\\[.*$" withString:@""]
vv_stringByReplacingRegexPattern:@",$" withString:@""]
Expand Down
3 changes: 2 additions & 1 deletion VVDocumenter-Xcode/Commenter/VVBaseCommenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

-(id) initWithIndentString:(NSString *)indent codeString:(NSString *)code;
-(NSString *) document;
-(void) parseArguments;

-(void) parseArgumentsInputArgs:(NSString *)rawArgsCode;

// Comment methods
-(NSString *) startComment;
Expand Down
48 changes: 24 additions & 24 deletions VVDocumenter-Xcode/Commenter/VVBaseCommenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,34 +118,34 @@ -(NSString *) prefixString
}
}

-(void) parseArguments
-(void) parseArgumentsInputArgs:(NSString *)rawArgsCode
{
[self.arguments removeAllObjects];
NSArray * braceGroups = [self.code vv_stringsByExtractingGroupsUsingRegexPattern:@"\\(([^\\^][^\\(\\)]*)\\)"];
if (braceGroups.count > 0) {
NSString *argumentGroupString = braceGroups[0];
NSArray *argumentStrings = [argumentGroupString componentsSeparatedByString:@","];
for (__strong NSString *argumentString in argumentStrings) {
VVArgument *arg = [[VVArgument alloc] init];
argumentString = [argumentString vv_stringByReplacingRegexPattern:@"=\\s*\\w*" withString:@""];
argumentString = [argumentString vv_stringByReplacingRegexPattern:@"\\s+$" withString:@""];
argumentString = [argumentString vv_stringByReplacingRegexPattern:@"\\s+" withString:@" "];
NSMutableArray *tempArgs = [[argumentString componentsSeparatedByString:@" "] mutableCopy];
while ([[tempArgs lastObject] isEqualToString:@" "]) {
[tempArgs removeLastObject];
}

arg.name = [tempArgs lastObject];

if (rawArgsCode.length == 0) {
return;
}

NSArray *argumentStrings = [rawArgsCode componentsSeparatedByString:@","];
for (__strong NSString *argumentString in argumentStrings) {
VVArgument *arg = [[VVArgument alloc] init];
argumentString = [argumentString vv_stringByReplacingRegexPattern:@"=\\s*\\w*" withString:@""];
argumentString = [argumentString vv_stringByReplacingRegexPattern:@"\\s+$" withString:@""];
argumentString = [argumentString vv_stringByReplacingRegexPattern:@"\\s+" withString:@" "];
NSMutableArray *tempArgs = [[argumentString componentsSeparatedByString:@" "] mutableCopy];
while ([[tempArgs lastObject] isEqualToString:@" "]) {
[tempArgs removeLastObject];
arg.type = [tempArgs componentsJoinedByString:@" "];

VVLog(@"arg type: %@", arg.type);
VVLog(@"arg name: %@", arg.name);

[self.arguments addObject:arg];
}

arg.name = [tempArgs lastObject];

[tempArgs removeLastObject];
arg.type = [tempArgs componentsJoinedByString:@" "];

VVLog(@"arg type: %@", arg.type);
VVLog(@"arg name: %@", arg.name);

[self.arguments addObject:arg];
}

}

@end
5 changes: 4 additions & 1 deletion VVDocumenter-Xcode/Commenter/VVFunctionCommenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ -(void) captureReturnType

-(void) captureParameters
{
[self parseArguments];
NSArray * braceGroups = [self.code vv_stringsByExtractingGroupsUsingRegexPattern:@"\\(([^\\^].*)\\)"];
if (braceGroups.count > 0) {
[self parseArgumentsInputArgs:braceGroups[0]];
}

//Remove void arg in block
NSArray *tempArray = [NSArray arrayWithArray:self.arguments];
Expand Down
5 changes: 3 additions & 2 deletions VVDocumenter-Xcode/Commenter/VVMacroCommenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ -(void) captureReturnType

-(void) captureParameters
{
if ([self.code vv_matchesPatternRegexPattern:@"\\("]) {
[self parseArguments];
NSArray * braceGroups = [self.code vv_stringsByExtractingGroupsUsingRegexPattern:@"\\(([^\\^][^\\(\\)]*)\\)"];
if (braceGroups.count > 0) {
[self parseArgumentsInputArgs:braceGroups[0]];
}
}

Expand Down
11 changes: 9 additions & 2 deletions VVDocumenterTests/CommenterTests/CommenterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ -(void) testParseArguments
arg1.type = @"int";
arg1.name = @"y";

[baseCommenter parseArguments];
NSArray * braceGroups = [baseCommenter.code vv_stringsByExtractingGroupsUsingRegexPattern:@"\\(([^\\^][^\\(\\)]*)\\)"];
if (braceGroups.count > 0) {
[baseCommenter parseArgumentsInputArgs:braceGroups[0]];
}

NSUInteger count = baseCommenter.arguments.count;
STAssertEquals(count, (NSUInteger)2, @"There should be 2 args, %@",baseCommenter.arguments);
STAssertEqualObjects(arg0.type, [(VVArgument *)baseCommenter.arguments[0] type], @"%@ should be type %@", [(VVArgument *)baseCommenter.arguments[0] type], arg0.type);
Expand All @@ -84,7 +88,10 @@ -(void) testParseArguments
arg1.type = @"char";
arg1.name = @"argv";

[baseCommenter parseArguments];
braceGroups = [baseCommenter.code vv_stringsByExtractingGroupsUsingRegexPattern:@"\\(([^\\^][^\\(\\)]*)\\)"];
if (braceGroups.count > 0) {
[baseCommenter parseArgumentsInputArgs:braceGroups[0]];
}
count = baseCommenter.arguments.count;
STAssertEquals(count, (NSUInteger)2, @"There should be 2 args, %@",baseCommenter.arguments);
STAssertEqualObjects(arg0.type, [(VVArgument *)baseCommenter.arguments[0] type], @"%@ should be type %@", [(VVArgument *)baseCommenter.arguments[0] type], arg0.type);
Expand Down
25 changes: 25 additions & 0 deletions VVDocumenterTests/DocumenterTests/VVMethodTestsCode.plist
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@
* <#Description#>
*
* @return <#return value description#>
*/</string>
</dict>
<dict>
<key>source</key>
<string>-(void)whenLinked:(void (^)(void))actionHandler</string>
<key>uniform</key>
<string>-(void)whenLinked:(void (^)(void))actionHandler</string>
<key>result</key>
<string>/**
* &lt;#Description#&gt;
*
* @param actionHandler &lt;#actionHandler description#&gt;
*/</string>
</dict>
</array>
Expand Down Expand Up @@ -160,6 +172,19 @@
* @param x &lt;#x description#&gt;
* @param y &lt;#y description#&gt;
* @param idx &lt;#idx description#&gt;
*/</string>
</dict>
<dict>
<key>source</key>
<string>void print2DList(int rowCount, int (*p)[10]);</string>
<key>uniform</key>
<string>void print2DList(int rowCount, int (*p)[10]);</string>
<key>result</key>
<string>/**
* &lt;#Description#&gt;
*
* @param rowCount &lt;#rowCount description#&gt;
* @param p &lt;#p description#&gt;
*/</string>
</dict>
</array>
Expand Down

0 comments on commit c676f13

Please sign in to comment.