Skip to content

Commit c676f13

Browse files
committed
Merge pull request onevcat#37 from onevcat/fix/brace-in-args
Fix/brace in args
2 parents 4c8e29d + 2ab2d6c commit c676f13

7 files changed

Lines changed: 69 additions & 31 deletions

File tree

VVDocumenter-Xcode/Commenter/VVArgument.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ -(void)setType:(NSString *)type
2222
-(void)setName:(NSString *)name
2323
{
2424
if (name != _name) {
25-
_name = [[[[[[name vv_stringByReplacingRegexPattern:@"^&" withString:@""]
25+
_name = [[[[[[[name vv_stringByReplacingRegexPattern:@"\\(|\\)" withString:@""]
26+
vv_stringByReplacingRegexPattern:@"^&" withString:@""]
2627
vv_stringByReplacingRegexPattern:@"^\\*+" withString:@""]
2728
vv_stringByReplacingRegexPattern:@"\\[.*$" withString:@""]
2829
vv_stringByReplacingRegexPattern:@",$" withString:@""]

VVDocumenter-Xcode/Commenter/VVBaseCommenter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
-(id) initWithIndentString:(NSString *)indent codeString:(NSString *)code;
1919
-(NSString *) document;
20-
-(void) parseArguments;
20+
21+
-(void) parseArgumentsInputArgs:(NSString *)rawArgsCode;
2122

2223
// Comment methods
2324
-(NSString *) startComment;

VVDocumenter-Xcode/Commenter/VVBaseCommenter.m

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,34 +118,34 @@ -(NSString *) prefixString
118118
}
119119
}
120120

121-
-(void) parseArguments
121+
-(void) parseArgumentsInputArgs:(NSString *)rawArgsCode
122122
{
123123
[self.arguments removeAllObjects];
124-
NSArray * braceGroups = [self.code vv_stringsByExtractingGroupsUsingRegexPattern:@"\\(([^\\^][^\\(\\)]*)\\)"];
125-
if (braceGroups.count > 0) {
126-
NSString *argumentGroupString = braceGroups[0];
127-
NSArray *argumentStrings = [argumentGroupString componentsSeparatedByString:@","];
128-
for (__strong NSString *argumentString in argumentStrings) {
129-
VVArgument *arg = [[VVArgument alloc] init];
130-
argumentString = [argumentString vv_stringByReplacingRegexPattern:@"=\\s*\\w*" withString:@""];
131-
argumentString = [argumentString vv_stringByReplacingRegexPattern:@"\\s+$" withString:@""];
132-
argumentString = [argumentString vv_stringByReplacingRegexPattern:@"\\s+" withString:@" "];
133-
NSMutableArray *tempArgs = [[argumentString componentsSeparatedByString:@" "] mutableCopy];
134-
while ([[tempArgs lastObject] isEqualToString:@" "]) {
135-
[tempArgs removeLastObject];
136-
}
137-
138-
arg.name = [tempArgs lastObject];
139-
124+
if (rawArgsCode.length == 0) {
125+
return;
126+
}
127+
128+
NSArray *argumentStrings = [rawArgsCode componentsSeparatedByString:@","];
129+
for (__strong NSString *argumentString in argumentStrings) {
130+
VVArgument *arg = [[VVArgument alloc] init];
131+
argumentString = [argumentString vv_stringByReplacingRegexPattern:@"=\\s*\\w*" withString:@""];
132+
argumentString = [argumentString vv_stringByReplacingRegexPattern:@"\\s+$" withString:@""];
133+
argumentString = [argumentString vv_stringByReplacingRegexPattern:@"\\s+" withString:@" "];
134+
NSMutableArray *tempArgs = [[argumentString componentsSeparatedByString:@" "] mutableCopy];
135+
while ([[tempArgs lastObject] isEqualToString:@" "]) {
140136
[tempArgs removeLastObject];
141-
arg.type = [tempArgs componentsJoinedByString:@" "];
142-
143-
VVLog(@"arg type: %@", arg.type);
144-
VVLog(@"arg name: %@", arg.name);
145-
146-
[self.arguments addObject:arg];
147137
}
138+
139+
arg.name = [tempArgs lastObject];
140+
141+
[tempArgs removeLastObject];
142+
arg.type = [tempArgs componentsJoinedByString:@" "];
143+
144+
VVLog(@"arg type: %@", arg.type);
145+
VVLog(@"arg name: %@", arg.name);
146+
147+
[self.arguments addObject:arg];
148148
}
149-
150149
}
150+
151151
@end

VVDocumenter-Xcode/Commenter/VVFunctionCommenter.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ -(void) captureReturnType
2222

2323
-(void) captureParameters
2424
{
25-
[self parseArguments];
25+
NSArray * braceGroups = [self.code vv_stringsByExtractingGroupsUsingRegexPattern:@"\\(([^\\^].*)\\)"];
26+
if (braceGroups.count > 0) {
27+
[self parseArgumentsInputArgs:braceGroups[0]];
28+
}
2629

2730
//Remove void arg in block
2831
NSArray *tempArray = [NSArray arrayWithArray:self.arguments];

VVDocumenter-Xcode/Commenter/VVMacroCommenter.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ -(void) captureReturnType
1717

1818
-(void) captureParameters
1919
{
20-
if ([self.code vv_matchesPatternRegexPattern:@"\\("]) {
21-
[self parseArguments];
20+
NSArray * braceGroups = [self.code vv_stringsByExtractingGroupsUsingRegexPattern:@"\\(([^\\^][^\\(\\)]*)\\)"];
21+
if (braceGroups.count > 0) {
22+
[self parseArgumentsInputArgs:braceGroups[0]];
2223
}
2324
}
2425

VVDocumenterTests/CommenterTests/CommenterTests.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ -(void) testParseArguments
6868
arg1.type = @"int";
6969
arg1.name = @"y";
7070

71-
[baseCommenter parseArguments];
71+
NSArray * braceGroups = [baseCommenter.code vv_stringsByExtractingGroupsUsingRegexPattern:@"\\(([^\\^][^\\(\\)]*)\\)"];
72+
if (braceGroups.count > 0) {
73+
[baseCommenter parseArgumentsInputArgs:braceGroups[0]];
74+
}
75+
7276
NSUInteger count = baseCommenter.arguments.count;
7377
STAssertEquals(count, (NSUInteger)2, @"There should be 2 args, %@",baseCommenter.arguments);
7478
STAssertEqualObjects(arg0.type, [(VVArgument *)baseCommenter.arguments[0] type], @"%@ should be type %@", [(VVArgument *)baseCommenter.arguments[0] type], arg0.type);
@@ -84,7 +88,10 @@ -(void) testParseArguments
8488
arg1.type = @"char";
8589
arg1.name = @"argv";
8690

87-
[baseCommenter parseArguments];
91+
braceGroups = [baseCommenter.code vv_stringsByExtractingGroupsUsingRegexPattern:@"\\(([^\\^][^\\(\\)]*)\\)"];
92+
if (braceGroups.count > 0) {
93+
[baseCommenter parseArgumentsInputArgs:braceGroups[0]];
94+
}
8895
count = baseCommenter.arguments.count;
8996
STAssertEquals(count, (NSUInteger)2, @"There should be 2 args, %@",baseCommenter.arguments);
9097
STAssertEqualObjects(arg0.type, [(VVArgument *)baseCommenter.arguments[0] type], @"%@ should be type %@", [(VVArgument *)baseCommenter.arguments[0] type], arg0.type);

VVDocumenterTests/DocumenterTests/VVMethodTestsCode.plist

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@
4545
* <#Description#>
4646
*
4747
* @return <#return value description#>
48+
*/</string>
49+
</dict>
50+
<dict>
51+
<key>source</key>
52+
<string>-(void)whenLinked:(void (^)(void))actionHandler</string>
53+
<key>uniform</key>
54+
<string>-(void)whenLinked:(void (^)(void))actionHandler</string>
55+
<key>result</key>
56+
<string>/**
57+
* &lt;#Description#&gt;
58+
*
59+
* @param actionHandler &lt;#actionHandler description#&gt;
4860
*/</string>
4961
</dict>
5062
</array>
@@ -160,6 +172,19 @@
160172
* @param x &lt;#x description#&gt;
161173
* @param y &lt;#y description#&gt;
162174
* @param idx &lt;#idx description#&gt;
175+
*/</string>
176+
</dict>
177+
<dict>
178+
<key>source</key>
179+
<string>void print2DList(int rowCount, int (*p)[10]);</string>
180+
<key>uniform</key>
181+
<string>void print2DList(int rowCount, int (*p)[10]);</string>
182+
<key>result</key>
183+
<string>/**
184+
* &lt;#Description#&gt;
185+
*
186+
* @param rowCount &lt;#rowCount description#&gt;
187+
* @param p &lt;#p description#&gt;
163188
*/</string>
164189
</dict>
165190
</array>

0 commit comments

Comments
 (0)