Skip to content
This repository
Newer
Older
100644 471 lines (400 sloc) 19.156 kb
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
1 //
2 // GBTokenizer.m
3 // appledoc
4 //
5 // Created by Tomaz Kragelj on 25.7.10.
6 // Copyright (C) 2010, Gentle Bytes. All rights reserved.
7 //
8
10fc1a29 »
2010-08-31 Replaced comments stripping with regular expressions.
9 #import "RegexKitLite.h"
28a51ce2 »
2010-07-26 Implemented class parsing for class name, superclass name, adopted pr…
10 #import "PKToken+GBToken.h"
c68cb86b »
2011-02-27 Implemented proper handling of @name sections in more complex circums…
11 #import "GBApplicationSettingsProvider.h"
49bc2550 »
2010-09-24 Implemented debugDescription method for returning detailed object des…
12 #import "GBSourceInfo.h"
13 #import "GBComment.h"
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
14 #import "GBTokenizer.h"
15
16 @interface GBTokenizer ()
17
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
18 - (BOOL)consumeComments;
95429b0e »
2011-12-08 Changed how single/multi line comments are parsed. Partially addresses
19 - (NSString *)commentValueFromString:(NSString *)value isMultiline:(BOOL)multiline;
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
20 - (NSString *)lineByPreprocessingHeaderDocDirectives:(NSString *)line;
21 - (NSArray *)linesByReorderingHeaderDocDirectives:(NSArray *)lines;
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
22 - (NSArray *)allTokensFromTokenizer:(PKTokenizer *)tokenizer;
2eb41ab5 »
2014-01-09 Allows single-line comments spanning multiple lines to be grouped if …
23 - (NSUInteger)offsetOfLineContainingOffset:(NSUInteger)offset;
24 - (NSInteger)indentationAtOffset:(NSUInteger)offset;
2796c5a6 »
2010-09-24 Added filename information to GBTokenizer to make it accessible for a…
25 @property (retain) NSString *filename;
6cfd48fd »
2010-09-24 Refactored file data creation by moving the method to GBTokenizer.
26 @property (retain) NSString *input;
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
27 @property (retain) NSArray *tokens;
28 @property (assign) NSUInteger tokenIndex;
95429b0e »
2011-12-08 Changed how single/multi line comments are parsed. Partially addresses
29 @property (assign) BOOL isLastCommentMultiline;
30 @property (assign) BOOL isPreviousCommentMultiline;
9047fcf4 »
2010-09-24 Refactored comment handling with GBModelBase by removing registerComm…
31 @property (retain) NSMutableString *lastCommentBuilder;
32 @property (retain) NSMutableString *previousCommentBuilder;
33 @property (retain) GBSourceInfo *lastCommentSourceInfo;
34 @property (retain) GBSourceInfo *previousCommentSourceInfo;
10fc1a29 »
2010-08-31 Replaced comments stripping with regular expressions.
35 @property (retain) NSString *singleLineCommentRegex;
36 @property (retain) NSString *multiLineCommentRegex;
7c06615a »
2010-08-31 Refactored tokenizer to use regex for parsing comment delimiters.
37 @property (retain) NSString *commentDelimiterRegex;
c68cb86b »
2011-02-27 Implemented proper handling of @name sections in more complex circums…
38 @property (retain) GBApplicationSettingsProvider *settings;
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
39
40 @end
41
42 #pragma mark -
43
44 @implementation GBTokenizer
45
46 #pragma mark Initialization & disposal
47
2796c5a6 »
2010-09-24 Added filename information to GBTokenizer to make it accessible for a…
48 + (id)tokenizerWithSource:(PKTokenizer *)tokenizer filename:(NSString *)filename {
c68cb86b »
2011-02-27 Implemented proper handling of @name sections in more complex circums…
49 return [self tokenizerWithSource:tokenizer filename:filename settings:nil];
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
50 }
51
c68cb86b »
2011-02-27 Implemented proper handling of @name sections in more complex circums…
52 + (id)tokenizerWithSource:(PKTokenizer *)tokenizer filename:(NSString *)filename settings:(id)settings {
53 return [[[self alloc] initWithSourceTokenizer:tokenizer filename:filename settings:settings] autorelease];
54 }
55
a136f4df »
2012-02-25 Fixed compiler warnings after upgrading to Xcode 4.3. Closes #186.
56 - (id)initWithSourceTokenizer:(PKTokenizer *)tokenizer filename:(NSString *)aFilename settings:(id)theSettings {
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
57 NSParameterAssert(tokenizer != nil);
a136f4df »
2012-02-25 Fixed compiler warnings after upgrading to Xcode 4.3. Closes #186.
58 NSParameterAssert(aFilename != nil);
59 NSParameterAssert([aFilename length] > 0);
be8fe38f »
2011-03-02 Added line numbers when logging matched objects and comments.
60 GBLogDebug(@"Initializing tokenizer...");
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
61 self = [super init];
62 if (self) {
a136f4df »
2012-02-25 Fixed compiler warnings after upgrading to Xcode 4.3. Closes #186.
63 self.settings = theSettings;
10fc1a29 »
2010-08-31 Replaced comments stripping with regular expressions.
64 self.singleLineCommentRegex = @"(?m-s:\\s*///(.*)$)";
05b2e460 »
2011-05-11 Added basic support for headerdoc comments. Closes #95.
65 self.multiLineCommentRegex = @"(?s:/\\*[*!](.*)\\*/)";
d7ece461 »
2011-01-24 Fixed HTML and XML handling within example blocks. Closes #54.
66 self.commentDelimiterRegex = @"^[!@#$%^&*()_=+`~,<.>/?;:'\"-]{3,}$";
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
67 self.tokenIndex = 0;
9047fcf4 »
2010-09-24 Refactored comment handling with GBModelBase by removing registerComm…
68 self.lastCommentBuilder = [NSMutableString string];
69 self.previousCommentBuilder = [NSMutableString string];
a136f4df »
2012-02-25 Fixed compiler warnings after upgrading to Xcode 4.3. Closes #186.
70 self.filename = aFilename;
6cfd48fd »
2010-09-24 Refactored file data creation by moving the method to GBTokenizer.
71 self.input = tokenizer.string;
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
72 self.tokens = [self allTokensFromTokenizer:tokenizer];
73 [self consumeComments];
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
74 }
75 return self;
76 }
77
78 #pragma mark Tokenizing handling
79
80 - (PKToken *)lookahead:(NSUInteger)offset {
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
81 NSUInteger delta = 0;
82 NSUInteger counter = 0;
83 while (counter <= offset) {
84 NSUInteger index = self.tokenIndex + delta;
85 if (index >= [self.tokens count]) return [PKToken EOFToken];
86 if ([[self.tokens objectAtIndex:index] isComment]) {
87 delta++;
88 continue;
89 }
90 delta++;
91 counter++;
92 }
93 return [self.tokens objectAtIndex:self.tokenIndex + delta - 1];
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
94 }
95
3d2d2a88 »
2011-10-15 Added support for termination macros for method declaration and prope…
96 - (void)lookaheadTo:(NSString *)end usingBlock:(void (^)(PKToken *token, BOOL *stop))block {
97 NSUInteger tokenCount = [self.tokens count];
98 BOOL quit = NO;
99 for (NSUInteger index = self.tokenIndex; index < tokenCount; ++index) {
100 PKToken *token = [self.tokens objectAtIndex:index];
101 if ([token isComment]) {
102 index++;
103 continue;
104 }
105 if ([token matches:end]) {
106 break;
107 }
108 block(token, &quit);
109 if (quit) break;
110 }
111 }
112
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
113 - (PKToken *)currentToken {
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
114 if ([self eof]) return [PKToken EOFToken];
115 return [self.tokens objectAtIndex:self.tokenIndex];
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
116 }
117
118 - (void)consume:(NSUInteger)count {
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
119 if (count == 0) return;
120 while (count > 0 && ![self eof]) {
121 self.tokenIndex++;
c190eaf1 »
2010-08-06 Implemented methods comments registration.
122 [self consumeComments];
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
123 count--;
124 }
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
125 }
126
8bebbe85 »
2010-07-27 Implemented class declaration parsing and renamed GBTokenizer consume…
127 - (void)consumeTo:(NSString *)end usingBlock:(void (^)(PKToken *token, BOOL *consume, BOOL *stop))block {
28a51ce2 »
2010-07-26 Implemented class parsing for class name, superclass name, adopted pr…
128 [self consumeFrom:nil to:end usingBlock:block];
129 }
130
dad75ed1 »
2010-08-10 Implemented simple block properties and method arguments parsing.
131 - (void)consumeFrom:(NSString *)start to:(NSString *)end usingBlock:(void (^)(PKToken *token, BOOL *consume, BOOL *stop))block {
28a51ce2 »
2010-07-26 Implemented class parsing for class name, superclass name, adopted pr…
132 // Skip starting token.
133 if (start) {
134 if (![[self currentToken] matches:start]) return;
135 [self consume:1];
136 }
137
138 // Report all tokens until EOF or ending token is found.
dad75ed1 »
2010-08-10 Implemented simple block properties and method arguments parsing.
139 NSUInteger level = 1;
72ab97cc »
2010-07-27 Refactored GBTokenizer block consuming method to allow quitting at an…
140 BOOL quit = NO;
dad75ed1 »
2010-08-10 Implemented simple block properties and method arguments parsing.
141 while (![self eof]) {
142 // Handle multiple hierarchy.
143 if (start && [[self currentToken] matches:start]) level++;
144 if ([[self currentToken] matches:end]) {
145 if (!start) break;
146 if (--level == 0) break;
147 }
148
149 // Report the token.
28a51ce2 »
2010-07-26 Implemented class parsing for class name, superclass name, adopted pr…
150 BOOL consume = YES;
72ab97cc »
2010-07-27 Refactored GBTokenizer block consuming method to allow quitting at an…
151 block([self currentToken], &consume, &quit);
28a51ce2 »
2010-07-26 Implemented class parsing for class name, superclass name, adopted pr…
152 if (consume) [self consume:1];
72ab97cc »
2010-07-27 Refactored GBTokenizer block consuming method to allow quitting at an…
153 if (quit) break;
28a51ce2 »
2010-07-26 Implemented class parsing for class name, superclass name, adopted pr…
154 }
155
156 // Skip ending token if found.
157 if ([[self currentToken] matches:end]) [self consume:1];
158 }
159
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
160 - (BOOL)eof {
161 return (self.tokenIndex >= [self.tokens count]);
162 }
163
6cfd48fd »
2010-09-24 Refactored file data creation by moving the method to GBTokenizer.
164 #pragma mark Token information handling
165
9a499e45 »
2010-09-26 Fixed comment source info handling when two consequtive comments are …
166 - (GBSourceInfo *)sourceInfoForCurrentToken {
167 return [self sourceInfoForToken:[self currentToken]];
6cfd48fd »
2010-09-24 Refactored file data creation by moving the method to GBTokenizer.
168 }
169
9a499e45 »
2010-09-26 Fixed comment source info handling when two consequtive comments are …
170 - (GBSourceInfo *)sourceInfoForToken:(PKToken *)token {
6cfd48fd »
2010-09-24 Refactored file data creation by moving the method to GBTokenizer.
171 NSParameterAssert(token != nil);
7d6a323e »
2010-11-14 Copied all the changes from the old generating branch.
172 NSUInteger lines = [self.input numberOfLinesInRange:NSMakeRange(0, [token offset])];
173 return [GBSourceInfo infoWithFilename:self.filename lineNumber:lines];
6cfd48fd »
2010-09-24 Refactored file data creation by moving the method to GBTokenizer.
174 }
175
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
176 #pragma mark Comments handling
177
178 - (BOOL)consumeComments {
0bb1c7d6 »
2010-08-27 Enabled line wrapping and updated comments to fit better.
179 // This method checks if current token is a comment and consumes all comments until non-comment token is detected or EOF reached. The result of the method is that current index is positioned on the first non-comment token. If current token is not comment, the method doesn't do anything, but simply returns NO to indicate it didn't find a comment and therefore it didn't move current token. This is also where we do initial comments handling such as removing starting and ending chars etc.
c80c3fec »
2010-09-24 Implemented comment source file information parsing for all objects t…
180 self.previousCommentSourceInfo = nil;
181 self.lastCommentSourceInfo = nil;
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
182 if ([self eof]) return NO;
183 if (![[self currentToken] isComment]) return NO;
9a499e45 »
2010-09-26 Fixed comment source info handling when two consequtive comments are …
184
185 PKToken *startingPreviousToken = nil;
186 PKToken *startingLastToken = nil;
2eb41ab5 »
2014-01-09 Allows single-line comments spanning multiple lines to be grouped if …
187 NSUInteger previousSingleLineEndOffset = NSNotFound;
188 NSInteger previousSingleLineIndentation = -1;
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
189 while (![self eof] && [[self currentToken] isComment]) {
190 PKToken *token = [self currentToken];
10fc1a29 »
2010-08-31 Replaced comments stripping with regular expressions.
191 NSString *value = nil;
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
192
2eb41ab5 »
2014-01-09 Allows single-line comments spanning multiple lines to be grouped if …
193 // Match single line comments. Note that we can simplify the code with assumption that there's only one single line comment per match. If regex finds more (should never happen though), we simply combine them together. Then we check if the comment is a continuation of previous single liner by testing the string offset and indentation. If so we group the values together, otherwise we create a new single line comment. Finally we remember current comment offset to allow grouping of next single line comment.
10fc1a29 »
2010-08-31 Replaced comments stripping with regular expressions.
194 NSArray *singleLiners = [[token stringValue] componentsMatchedByRegex:self.singleLineCommentRegex capture:1];
195 if ([singleLiners count] > 0) {
196 value = [NSString string];
197 for (NSString *match in singleLiners) value = [value stringByAppendingString:match];
2eb41ab5 »
2014-01-09 Allows single-line comments spanning multiple lines to be grouped if …
198 NSInteger tokenIndentation = [self indentationAtOffset:[token offset]];
10fc1a29 »
2010-08-31 Replaced comments stripping with regular expressions.
199 BOOL isContinuingPreviousSingleLiner = ([token offset] == previousSingleLineEndOffset + 1);
2eb41ab5 »
2014-01-09 Allows single-line comments spanning multiple lines to be grouped if …
200 if (!isContinuingPreviousSingleLiner && previousSingleLineIndentation > 0 && tokenIndentation == previousSingleLineIndentation) {
201 isContinuingPreviousSingleLiner = ([token offset] == previousSingleLineEndOffset + previousSingleLineIndentation + 1);
202 }
9a499e45 »
2010-09-26 Fixed comment source info handling when two consequtive comments are …
203 if (isContinuingPreviousSingleLiner) {
204 [self.lastCommentBuilder appendString:@"\n"];
205 } else {
206 [self.previousCommentBuilder setString:self.lastCommentBuilder];
207 startingPreviousToken = startingLastToken;
208 [self.lastCommentBuilder setString:@""];
95429b0e »
2011-12-08 Changed how single/multi line comments are parsed. Partially addresses
209 self.isPreviousCommentMultiline = self.isLastCommentMultiline;
210 self.isLastCommentMultiline = NO;
9a499e45 »
2010-09-26 Fixed comment source info handling when two consequtive comments are …
211 startingLastToken = token;
212 }
10fc1a29 »
2010-08-31 Replaced comments stripping with regular expressions.
213 previousSingleLineEndOffset = [token offset] + [[token stringValue] length];
2eb41ab5 »
2014-01-09 Allows single-line comments spanning multiple lines to be grouped if …
214 previousSingleLineIndentation = tokenIndentation;
10fc1a29 »
2010-08-31 Replaced comments stripping with regular expressions.
215 }
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
216
c7725768 »
2010-09-22 Implemented last stand-alone comment parsing.
217 // Match multiple line comments and only process last (in reality we should only have one comment in each mutliline comment token, but let's handle any strange cases graceosly).
10fc1a29 »
2010-08-31 Replaced comments stripping with regular expressions.
218 else {
219 NSArray *multiLiners = [[token stringValue] componentsMatchedByRegex:self.multiLineCommentRegex capture:1];
220 value = [multiLiners lastObject];
9a499e45 »
2010-09-26 Fixed comment source info handling when two consequtive comments are …
221 [self.previousCommentBuilder setString:self.lastCommentBuilder];
222 startingPreviousToken = startingLastToken;
9047fcf4 »
2010-09-24 Refactored comment handling with GBModelBase by removing registerComm…
223 [self.lastCommentBuilder setString:@""];
95429b0e »
2011-12-08 Changed how single/multi line comments are parsed. Partially addresses
224 self.isPreviousCommentMultiline = self.isLastCommentMultiline;
225 self.isLastCommentMultiline = YES;
9a499e45 »
2010-09-26 Fixed comment source info handling when two consequtive comments are …
226 startingLastToken = token;
10fc1a29 »
2010-08-31 Replaced comments stripping with regular expressions.
227 }
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
228
10fc1a29 »
2010-08-31 Replaced comments stripping with regular expressions.
229 // Append string value to current comment and proceed with next token.
dbf7903f »
2011-08-19 Fixed a crash when trying to append a nil value.
230 if (value)
231 [self.lastCommentBuilder appendString:value];
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
232 self.tokenIndex++;
9a499e45 »
2010-09-26 Fixed comment source info handling when two consequtive comments are …
233 }
234
c68cb86b »
2011-02-27 Implemented proper handling of @name sections in more complex circums…
235 // If last comment contains @name, we should assign it to previous one and reset current! This should ideally be handled by higher level component, but it's simplest to do it here. Note that we don't deal with source info here, we'll do immediately after this as long as we properly setup tokens.
236 if (self.settings && [self.lastCommentBuilder isMatchedByRegex:self.settings.commentComponents.methodGroupRegex]) {
237 self.previousCommentBuilder = [self.lastCommentBuilder mutableCopy];
238 [self.lastCommentBuilder setString:@""];
239 startingPreviousToken = startingLastToken;
240 startingLastToken = nil;
241 }
242
243 // Assign source information so that we can match comments to file and line number later on.
be8fe38f »
2011-03-02 Added line numbers when logging matched objects and comments.
244 if (startingPreviousToken) {
245 self.previousCommentSourceInfo = [self sourceInfoForToken:startingPreviousToken];
246 GBLogDebug(@"Matched comment '%@' at line %lu.", [self.previousCommentBuilder normalizedDescription], self.previousCommentSourceInfo.lineNumber);
247 }
248 if (startingLastToken) {
249 self.lastCommentSourceInfo = [self sourceInfoForToken:startingLastToken];
250 GBLogDebug(@"Matched comment '%@' at line %lu.", [self.lastCommentBuilder normalizedDescription], self.lastCommentSourceInfo.lineNumber);
251 }
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
252 return YES;
253 }
254
95429b0e »
2011-12-08 Changed how single/multi line comments are parsed. Partially addresses
255 - (NSString *)commentValueFromString:(NSString *)value isMultiline:(BOOL)multiline {
c7725768 »
2010-09-22 Implemented last stand-alone comment parsing.
256 if ([value length] == 0) return nil;
257 NSArray *lines = [value componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
258 NSMutableArray *strippedLines = [NSMutableArray arrayWithCapacity:[lines count]];
1aa458cb »
2010-08-06 Implemented comment prefixes and suffixes handling.
259
7c06615a »
2010-08-31 Refactored tokenizer to use regex for parsing comment delimiters.
260 // First pass: removes delimiters. We simply detect 3+ delimiter chars in any combination. If removing delimiter yields empty line, discard it.
4bb10f20 »
2010-09-15 Updated comments parsing to use regular expressions instead of NSStri…
261 [lines enumerateObjectsUsingBlock:^(NSString *line, NSUInteger idx, BOOL *stop) {
262 NSString *stripped = [line stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
7c06615a »
2010-08-31 Refactored tokenizer to use regex for parsing comment delimiters.
263 NSString *delimited = [stripped stringByReplacingOccurrencesOfRegex:self.commentDelimiterRegex withString:@""];
264 if ([stripped length] > [delimited length]) {
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
265 if ([delimited length] > 0) [strippedLines addObject:delimited];
7c06615a »
2010-08-31 Refactored tokenizer to use regex for parsing comment delimiters.
266 return;
1aa458cb »
2010-08-06 Implemented comment prefixes and suffixes handling.
267 }
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
268 [strippedLines addObject:line];
1aa458cb »
2010-08-06 Implemented comment prefixes and suffixes handling.
269 }];
95429b0e »
2011-12-08 Changed how single/multi line comments are parsed. Partially addresses
270
4bb10f20 »
2010-09-15 Updated comments parsing to use regular expressions instead of NSStri…
271 // If all lines start with a *, ignore the prefix. Note that we ignore first line as it can only contain /** and text! We also ignore last line as if it only contains */
3b971037 »
2010-09-24 Fixed comment delimiters detection regex and cleaned up some code.
272 NSString *prefixRegex = @"(?m:^\\s*\\*[ ]*)";
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
273 __block BOOL stripPrefix = ([strippedLines count] > 1);
1aa458cb »
2010-08-06 Implemented comment prefixes and suffixes handling.
274 if (stripPrefix) {
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
275 [strippedLines enumerateObjectsUsingBlock:^(NSString *line, NSUInteger idx, BOOL *stop) {
4bb10f20 »
2010-09-15 Updated comments parsing to use regular expressions instead of NSStri…
276 NSString *stripped = [line stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
277 if (idx == [strippedLines count]-1 && [stripped length] == 0) {
4bb10f20 »
2010-09-15 Updated comments parsing to use regular expressions instead of NSStri…
278 return;
279 }
95429b0e »
2011-12-08 Changed how single/multi line comments are parsed. Partially addresses
280 if ((!multiline || idx > 0) && ![stripped isMatchedByRegex:prefixRegex]) {
1aa458cb »
2010-08-06 Implemented comment prefixes and suffixes handling.
281 stripPrefix = NO;
282 *stop = YES;
283 }
284 }];
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
285 }
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
286
287 // Preprocess header doc directives.
288 NSArray *preprocessedLines = [self linesByReorderingHeaderDocDirectives:strippedLines];
0da48e11 »
2011-12-23 Improved support for HeaderDocs
289
d7ece461 »
2011-01-24 Fixed HTML and XML handling within example blocks. Closes #54.
290 // Finally remove common line prefix and a single prefix space (but leave multiple spaces to properly handle space prefixed example blocks!) and compose all objects into final comment.
1aa458cb »
2010-08-06 Implemented comment prefixes and suffixes handling.
291 NSCharacterSet *spacesSet = [NSCharacterSet characterSetWithCharactersInString:@" "];
d7ece461 »
2011-01-24 Fixed HTML and XML handling within example blocks. Closes #54.
292 NSString *spacesPrefixRegex = @"^ {2,}";
293 NSString *tabPrefixRegex = @"^\t";
c7725768 »
2010-09-22 Implemented last stand-alone comment parsing.
294 NSMutableString *result = [NSMutableString stringWithCapacity:[value length]];
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
295 [preprocessedLines enumerateObjectsUsingBlock:^(NSString *line, NSUInteger idx, BOOL *stop) {
d7ece461 »
2011-01-24 Fixed HTML and XML handling within example blocks. Closes #54.
296 if (stripPrefix) line = [line stringByReplacingOccurrencesOfRegex:prefixRegex withString:@""];
297 if (![line isMatchedByRegex:spacesPrefixRegex] && ![line isMatchedByRegex:tabPrefixRegex]) line = [line stringByTrimmingCharactersInSet:spacesSet];
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
298 line = [self lineByPreprocessingHeaderDocDirectives:line];
4bb10f20 »
2010-09-15 Updated comments parsing to use regular expressions instead of NSStri…
299 [result appendString:line];
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
300 if (idx < [strippedLines count] - 1) [result appendString:@"\n"];
1aa458cb »
2010-08-06 Implemented comment prefixes and suffixes handling.
301 }];
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
302
23666fb2 »
2010-08-10 Fixed comments reporting when empty comment is detected.
303 // If the result is empty string, return nil, otherwise return the comment string.
304 if ([result length] == 0) return nil;
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
305 return result;
306 }
307
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
308 - (NSString *)lineByPreprocessingHeaderDocDirectives:(NSString *)line {
309 if (!self.settings.preprocessHeaderDoc) return line;
310
311 // Remove the entire line when it contains @method or property or class.
3f0d4c7a »
2012-10-30 Ability to parse @discussion @abstract @brief @details
312 //line = [line stringByReplacingOccurrencesOfRegex:@"(?m:@(protocol|method|property|class).*$)" withString:@""];
d863afdb »
2012-03-01 Also preprocess doxygen tags
313
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
314 // Remove unsupported headerDoc words.
3f0d4c7a »
2012-10-30 Ability to parse @discussion @abstract @brief @details
315 //line = [line stringByReplacingOccurrencesOfRegex:@"(?m:^\\s*@(discussion|abstract))\\s?" withString:@"\n"];
d863afdb »
2012-03-01 Also preprocess doxygen tags
316
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
317 // Replace methodgroup with name.
318 line = [line stringByReplacingOccurrencesOfRegex:@"(?:@(methodgroup|group))" withString:@"@name"];
3de683a6 »
2012-03-02 Improved regular expressions for handling @brief and @details
319
320 // Remove unsupported Doxygen words. This should ease the pain of migrating large amount of comments using doxygen markup.
321 // Comments like the following are cleaned up, and made ready for the markup appledoc expects
322
323 /**
324 @brief Brief Comment
325 @details Detailed Comment.
326 */
327
328 // Becomes....
329
330 /**
331 Brief Comment
332
333 Detailed Comment.
334 */
335
336
3f0d4c7a »
2012-10-30 Ability to parse @discussion @abstract @brief @details
337 line = [line stringByReplacingOccurrencesOfRegex:@"(?m:^\\s*@updated).*$?" withString:@"\n"];
338
3de683a6 »
2012-03-02 Improved regular expressions for handling @brief and @details
339 // Removes any occurance of @brief and it's surrounding whitespace
3f0d4c7a »
2012-10-30 Ability to parse @discussion @abstract @brief @details
340 //line = [line stringByReplacingOccurrencesOfRegex:@"\\s*@brief\\s*" withString:@""];
3de683a6 »
2012-03-02 Improved regular expressions for handling @brief and @details
341
342 // Replaces any occurance of @details and it's surrounding whitespace with a newline
3f0d4c7a »
2012-10-30 Ability to parse @discussion @abstract @brief @details
343 //line = [line stringByReplacingOccurrencesOfRegex:@"^\\s*@details\\s*" withString:@"\n"];
3de683a6 »
2012-03-02 Improved regular expressions for handling @brief and @details
344
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
345 return line;
346 }
347
348 - (NSArray *)linesByReorderingHeaderDocDirectives:(NSArray *)lines {
d6db7d87 »
2012-02-24 proper way to test for MacOSX Lion
349 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
350 if (!self.settings.preprocessHeaderDoc) return lines;
351
352 // Make sure that @param and @return is placed at the end (after abstract etc.)
353 NSMutableArray *reorderedParams = [NSMutableArray array];
354 NSMutableArray *reorderedNonParams = [NSMutableArray array];
355 NSRegularExpression *directiveExpression = [NSRegularExpression regularExpressionWithPattern:@"^\\s*@(param|result|return)" options:NSRegularExpressionDotMatchesLineSeparators error:nil];
356 NSRegularExpression *lineExpression = [NSRegularExpression regularExpressionWithPattern:@"^\\s*@[a-z]" options:NSRegularExpressionDotMatchesLineSeparators error:nil];
357
358 BOOL isParamBlock = NO;
359 for (NSString *line in lines) {
360 if ([directiveExpression numberOfMatchesInString:line options:0 range:NSMakeRange(0, [line length])] > 0) {
361 isParamBlock = YES;
362 } else if ([lineExpression numberOfMatchesInString:line options:0 range:NSMakeRange(0, [line length])] > 0) {
363 isParamBlock = NO;
364 }
365
366 if (isParamBlock) {
367 [reorderedParams addObject:line];
368 } else {
369 [reorderedNonParams addObject:line];
370 }
371 }
372
373 [reorderedNonParams addObjectsFromArray:reorderedParams];
374 return reorderedNonParams;
89da7869 »
2012-02-24 Conditionally include code in method linesByReorderingHeaderDocDirect…
375 #else
376 return lines;
377 #endif
2e063c0e »
2011-12-24 Cleaned up HeaderDoc parsing code and made it optional. References #95
378 }
379
4262bb89 »
2011-01-06 Fixed comments parsing for non-trivial sources. Closes #43.
380 - (void)resetComments {
1bf79462 »
2011-01-29 Fixed undocumented methods and properties parsing. Closes #57.
381 GBLogDebug(@"Resetting comments...");
382 [self.lastCommentBuilder setString:@""];
383 [self.previousCommentBuilder setString:@""];
4262bb89 »
2011-01-06 Fixed comments parsing for non-trivial sources. Closes #43.
384 }
385
9047fcf4 »
2010-09-24 Refactored comment handling with GBModelBase by removing registerComm…
386 - (GBComment *)lastComment {
6d5bed5f »
2010-09-24 Refactored log messages to yield better information.
387 if ([self.lastCommentBuilder length] == 0) return nil;
95429b0e »
2011-12-08 Changed how single/multi line comments are parsed. Partially addresses
388 NSString *value = [self commentValueFromString:self.lastCommentBuilder isMultiline:self.isLastCommentMultiline];
9047fcf4 »
2010-09-24 Refactored comment handling with GBModelBase by removing registerComm…
389 return [GBComment commentWithStringValue:value sourceInfo:self.lastCommentSourceInfo];
390 }
391
392 - (GBComment *)previousComment {
6d5bed5f »
2010-09-24 Refactored log messages to yield better information.
393 if ([self.previousCommentBuilder length] == 0) return nil;
95429b0e »
2011-12-08 Changed how single/multi line comments are parsed. Partially addresses
394 NSString *value = [self commentValueFromString:self.previousCommentBuilder isMultiline:self.isPreviousCommentMultiline];
9047fcf4 »
2010-09-24 Refactored comment handling with GBModelBase by removing registerComm…
395 return [GBComment commentWithStringValue:value sourceInfo:self.previousCommentSourceInfo];
396 }
397
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
398 #pragma mark Helper methods
399
400 - (NSArray *)allTokensFromTokenizer:(PKTokenizer *)tokenizer {
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
401 // Return all appledoc comments too, but ignore ordinary C comments!
402 BOOL reportsComments = tokenizer.commentState.reportsCommentTokens;
403 tokenizer.commentState.reportsCommentTokens = YES;
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
404 NSMutableArray *result = [NSMutableArray array];
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
405 PKToken *token;
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
406 while ((token = [tokenizer nextToken]) != [PKToken EOFToken]) {
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
407 if ([token isComment] && ![token isAppledocComment]) continue;
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
408 [result addObject:token];
409 }
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
410 tokenizer.commentState.reportsCommentTokens = reportsComments;
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
411 return result;
412 }
413
2eb41ab5 »
2014-01-09 Allows single-line comments spanning multiple lines to be grouped if …
414 - (NSUInteger)offsetOfLineContainingOffset:(NSUInteger)offset {
415 // This method returns the offset of the first character in the line
416 // containing the character at the specific offset.
417 NSRange newlineRange = [self.input rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet]
418 options:NSBackwardsSearch
419 range:NSMakeRange(0, offset)];
420 if (newlineRange.location != NSNotFound) {
421 return newlineRange.location + 1;
422 }
423 // First line
424 return 0;
425 }
426
427 - (NSInteger)indentationAtOffset:(NSUInteger)offset {
428 // This method returns the number of tab or space characters preceding the
429 // offset if and only if it is only preceded by such indentation characters,
430 // otherwise returns -1.
431 NSUInteger lineOffset = [self offsetOfLineContainingOffset:offset];
432 NSRange lineToOffsetRange = NSMakeRange(lineOffset, offset - lineOffset);
433
434 // Short-circuit logic if offset is at the start of the line
435 if (lineToOffsetRange.length == 0) {
436 return 0;
437 }
438
439 NSCharacterSet * nonWhitespace = [[NSCharacterSet whitespaceCharacterSet] invertedSet];
440 NSRange nonWhitespaceRange = [self.input rangeOfCharacterFromSet:nonWhitespace
441 options:0
442 range:lineToOffsetRange];
443 // Line contains only whitespace preceding the offset: indentation
444 if (nonWhitespaceRange.location == NSNotFound) {
445 return lineToOffsetRange.length;
446 }
447 return -1;
448 }
449
450
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
451 #pragma mark Properties
452
2796c5a6 »
2010-09-24 Added filename information to GBTokenizer to make it accessible for a…
453 @synthesize filename;
6cfd48fd »
2010-09-24 Refactored file data creation by moving the method to GBTokenizer.
454 @synthesize input;
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
455 @synthesize tokens;
456 @synthesize tokenIndex;
47e2c012 »
2010-07-31 Implemented basic comments parsing and tests.
457 @synthesize lastComment;
9047fcf4 »
2010-09-24 Refactored comment handling with GBModelBase by removing registerComm…
458 @synthesize lastCommentBuilder;
459 @synthesize lastCommentSourceInfo;
c7725768 »
2010-09-22 Implemented last stand-alone comment parsing.
460 @synthesize previousComment;
9047fcf4 »
2010-09-24 Refactored comment handling with GBModelBase by removing registerComm…
461 @synthesize previousCommentBuilder;
462 @synthesize previousCommentSourceInfo;
95429b0e »
2011-12-08 Changed how single/multi line comments are parsed. Partially addresses
463 @synthesize isLastCommentMultiline;
464 @synthesize isPreviousCommentMultiline;
10fc1a29 »
2010-08-31 Replaced comments stripping with regular expressions.
465 @synthesize singleLineCommentRegex;
466 @synthesize multiLineCommentRegex;
7c06615a »
2010-08-31 Refactored tokenizer to use regex for parsing comment delimiters.
467 @synthesize commentDelimiterRegex;
c68cb86b »
2011-02-27 Implemented proper handling of @name sections in more complex circums…
468 @synthesize settings;
84598f71 »
2010-07-26 Implemented unit testing target and basic class parsing tests.
469
470 @end
Something went wrong with that request. Please try again.