Skip to content

Commit

Permalink
Refactored objective C parser to make core more readable.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaz committed Jun 15, 2012
1 parent 62c35e1 commit a976fa6
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions appledoc/Parsing/ObjectiveC/ObjectiveCParser.m
Expand Up @@ -25,7 +25,9 @@
@interface ObjectiveCParser ()
- (GBResult)parseTokens;
- (void)prepareParserForParsingString:(NSString *)string;
- (BOOL)parseTokensWithData:(ObjectiveCParseData *)data result:(GBResult *)result;
- (BOOL)parseCommentToken:(PKToken *)token;
- (BOOL)registerComments;
- (BOOL)isParseResultFailure:(GBResult)result;
@property (nonatomic, strong) TokensStream *tokensStream;
@property (nonatomic, strong) CommentParser *commentParser;
Expand Down Expand Up @@ -90,18 +92,23 @@ - (GBResult)parseTokens {
PKToken *token = self.tokensStream.current;
LogParDebug(@"Parsing token '%@'...", token.stringValue);
if ([self parseCommentToken:token]) continue;
[self.commentParser notifyAndReset];
GBResult stateResult = [self.currentState parseWithData:data];
if ([self isParseResultFailure:result]) {
LogParDebug(@"State %@ reported error code %ld, bailing out!", self.currentState, stateResult);
result = stateResult;
break;
}
if (![self registerComments]) break;
if (![self parseTokensWithData:data result:&result]) break;
}
[self.commentParser notifyAndReset];
[self registerComments];
return result;
}

- (BOOL)parseTokensWithData:(ObjectiveCParseData *)data result:(GBResult *)result {
GBResult stateResult = [self.currentState parseWithData:data];
if ([self isParseResultFailure:stateResult]) {
LogParDebug(@"State %@ reported error code %ld, bailing out!", self.currentState, stateResult);
if (result) *result = stateResult;
return NO;
}
return YES;
}

- (BOOL)parseCommentToken:(PKToken *)token {
if (!token.isComment) return NO;
LogParDebug(@"Token is comment, testing for appledoc comments...");
Expand All @@ -114,6 +121,12 @@ - (BOOL)parseCommentToken:(PKToken *)token {
return YES;
}

- (BOOL)registerComments {
// We're always returning YES; in fact, the only reason for introducing result is to have all lines of main loop code looking the same (kind of nerdy, I know, but that's how I am :)
[self.commentParser notifyAndReset];
return YES;
}

#pragma mark - Helper methods

- (BOOL)isParseResultFailure:(GBResult)result {
Expand Down

0 comments on commit a976fa6

Please sign in to comment.