Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Bilge Taylan Ulusoy <bilge.ulusoy@me.com>
  • Loading branch information
bulusoy committed Oct 30, 2012
1 parent 6abd243 commit 3f0d4c7
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Application/GBCommentComponentsProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
/** Returns the regex used for matching cross reference directive with capture 1 containing directive, capture 2 description text. */
@property (readonly) NSString *availabilityRegex;

@property (readonly) NSString *abstractRegex;
@property (readonly) NSString *discussionRegex;

///---------------------------------------------------------------------------------------
/// @name Markdown specific definitions
///---------------------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions Application/GBCommentComponentsProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ - (id)init {

#pragma mark Sections detection

- (NSString *)abstractRegex {
GBRETURN_ON_DEMAND([self descriptionCaptureRegexForKeyword:@"(abstract|brief)"]);
}

- (NSString *)discussionRegex {
GBRETURN_ON_DEMAND([self descriptionCaptureRegexForKeyword:@"(discussion|details)"]);
}

- (NSString *)noteSectionRegex {
GBRETURN_ON_DEMAND([self descriptionCaptureRegexForKeyword:@"note"]);
}
Expand Down
10 changes: 6 additions & 4 deletions Parsing/GBTokenizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ - (NSString *)lineByPreprocessingHeaderDocDirectives:(NSString *)line {
if (!self.settings.preprocessHeaderDoc) return line;

// Remove the entire line when it contains @method or property or class.
line = [line stringByReplacingOccurrencesOfRegex:@"(?m:@(protocol|method|property|class).*$)" withString:@""];
//line = [line stringByReplacingOccurrencesOfRegex:@"(?m:@(protocol|method|property|class).*$)" withString:@""];

// Remove unsupported headerDoc words.
line = [line stringByReplacingOccurrencesOfRegex:@"(?m:^\\s*@(discussion|abstract))\\s?" withString:@"\n"];
//line = [line stringByReplacingOccurrencesOfRegex:@"(?m:^\\s*@(discussion|abstract))\\s?" withString:@"\n"];

// Replace methodgroup with name.
line = [line stringByReplacingOccurrencesOfRegex:@"(?:@(methodgroup|group))" withString:@"@name"];
Expand All @@ -326,11 +326,13 @@ - (NSString *)lineByPreprocessingHeaderDocDirectives:(NSString *)line {
*/


line = [line stringByReplacingOccurrencesOfRegex:@"(?m:^\\s*@updated).*$?" withString:@"\n"];

// Removes any occurance of @brief and it's surrounding whitespace
line = [line stringByReplacingOccurrencesOfRegex:@"\\s*@brief\\s*" withString:@""];
//line = [line stringByReplacingOccurrencesOfRegex:@"\\s*@brief\\s*" withString:@""];

// Replaces any occurance of @details and it's surrounding whitespace with a newline
line = [line stringByReplacingOccurrencesOfRegex:@"^\\s*@details\\s*" withString:@"\n"];
//line = [line stringByReplacingOccurrencesOfRegex:@"^\\s*@details\\s*" withString:@"\n"];

return line;
}
Expand Down
73 changes: 70 additions & 3 deletions Processing/GBCommentsProcessor.m
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ - (void)processCommentBlockInLines:(NSArray *)lines blockRange:(NSRange)blockRan
NSArray *block = [lines subarrayWithRange:blockRange];
if ([self isLineMatchingDirectiveStatement:[block firstObject]]) {
NSString *string = [self stringByCombiningTrimmedLines:block];
if ([self processDiscussionBlockInString:string lines:lines blockRange:blockRange shortRange:shortRange]) return;
if ([self processAbstractBlockInString:string lines:lines blockRange:blockRange shortRange:shortRange]) return;
if ([self processNoteBlockInString:string lines:lines blockRange:blockRange shortRange:shortRange]) return;
if ([self processWarningBlockInString:string lines:lines blockRange:blockRange shortRange:shortRange]) return;
if ([self processBugBlockInString:string lines:lines blockRange:blockRange shortRange:shortRange]) return;
Expand Down Expand Up @@ -229,8 +231,9 @@ - (void)processCommentBlockInLines:(NSArray *)lines blockRange:(NSRange)blockRan
if ([blockString length] == 0) return;

// Process the string and register long description component.
GBCommentComponent *component = [self commentComponentByPreprocessingString:blockString withFlags:0];
[self.currentComment.longDescription registerComponent:component];
//GBCommentComponent *component = [self commentComponentByPreprocessingString:blockString withFlags:0];

//[self.currentComment.longDescription registerComponent:component];
}

- (void)registerShortDescriptionFromLines:(NSArray *)lines range:(NSRange)range removePrefix:(NSString *)remove {
Expand Down Expand Up @@ -383,7 +386,7 @@ - (BOOL)processAvailabilityBlockInString:(NSString *)string lines:(NSArray *)lin
if ([components count] == 0) return NO;

// Get data from captures. Index 1 is directive, index 2 description text.
NSString *description = [components objectAtIndex:2];
NSString *description = [components objectAtIndex:3];
NSRange range = [string rangeOfString:description];
NSString *prefix = nil;
if (range.location < [string length]) {
Expand All @@ -401,6 +404,68 @@ - (BOOL)processAvailabilityBlockInString:(NSString *)string lines:(NSArray *)lin
return YES;
}

- (BOOL)processDiscussionBlockInString:(NSString *)string lines:(NSArray *)lines blockRange:(NSRange)blockRange shortRange:(NSRange)shortRange {
NSArray *components = [string captureComponentsMatchedByRegex:self.components.discussionRegex];
if ([components count] == 0) return NO;

// Get data from captures. Index 1 is directive, index 2 description text.
NSString *description = [components objectAtIndex:3];
NSRange range = [string rangeOfString:description];
NSString *prefix = nil;
if (range.location < [string length]) {
prefix = [string substringToIndex:range.location];
} else {
prefix = @"";
}

GBLogDebug(@"- Registering discussion description %@ at %@...", [description normalizedDescription], self.currentSourceInfo);
[self reserveShortDescriptionFromLines:lines range:shortRange removePrefix:prefix];

// Prepare object representation from the description and register the result to the comment.
GBCommentComponent *component = [self commentComponentByPreprocessingString:description withFlags:0];
[self.currentComment.longDescription registerComponent:component];
return YES;
}

- (BOOL)processAbstractBlockInString:(NSString *)string lines:(NSArray *)lines blockRange:(NSRange)blockRange shortRange:(NSRange)shortRange {
NSArray *components = [string captureComponentsMatchedByRegex:self.components.abstractRegex];
if ([components count] == 0) return NO;

// Get data from captures. Index 1 is directive, index 2 description text.
NSString *description = [components objectAtIndex:3];
NSRange index;
index = [description rangeOfString:@"@discussion"];

if (index.location == NSNotFound) {
index = [description rangeOfString:@"\s+"];
}

NSRange range;
@try {
description = [description substringToIndex:index.location];
}
@catch (NSException *exception) {

}
@finally {
range = [string rangeOfString:description];
}
NSString *prefix = nil;
if (range.location < [string length]) {
prefix = [string substringToIndex:range.location];
} else {
prefix = @"";
}

GBLogDebug(@"- Registering abstract description %@ at %@...", [description normalizedDescription], self.currentSourceInfo);
[self reserveShortDescriptionFromLines:lines range:shortRange removePrefix:prefix];

// Prepare object representation from the description and register the result to the comment.
GBCommentComponent *component = [self commentComponentByPreprocessingString:description withFlags:0];
self.currentComment.shortDescription = component;
return YES;
}

- (BOOL)processReturnBlockInString:(NSString *)string lines:(NSArray *)lines blockRange:(NSRange)blockRange shortRange:(NSRange)shortRange {
NSArray *components = [string captureComponentsMatchedByRegex:self.components.returnDescriptionRegex];
if ([components count] == 0) return NO;
Expand Down Expand Up @@ -457,6 +522,8 @@ - (BOOL)processRelatedBlockInString:(NSString *)string lines:(NSArray *)lines bl
}

- (BOOL)isLineMatchingDirectiveStatement:(NSString *)string {
if ([string isMatchedByRegex:self.components.discussionRegex]) return YES;
if ([string isMatchedByRegex:self.components.abstractRegex]) return YES;
if ([string isMatchedByRegex:self.components.noteSectionRegex]) return YES;
if ([string isMatchedByRegex:self.components.warningSectionRegex]) return YES;
if ([string isMatchedByRegex:self.components.bugSectionRegex]) return YES;
Expand Down

0 comments on commit 3f0d4c7

Please sign in to comment.