-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added object structure for parser, parser rules, and renderer
- Loading branch information
Showing
16 changed files
with
248 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
#import "OCLRule.h" | ||
|
||
@interface OCLBaseRule : NSObject <OCLRule> {} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
#import "OCLBaseRule.h" | ||
|
||
@implementation OCLBaseRule | ||
|
||
- (NSArray *)handleToken:(NSArray *)tokens atIndex:(int)index { | ||
|
||
return nil; | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
#import "OCLRenderer.h" | ||
|
||
@interface OCLConsoleRenderer : NSObject <OCLRenderer> {} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
#import "OCLConsoleRenderer.h" | ||
|
||
@implementation OCLConsoleRenderer | ||
|
||
- (void)renderErrors:(NSArray *)errors { | ||
|
||
NSLog( @"Renderer..." ); | ||
|
||
if ( [errors count] > 0 ) { | ||
NSLog( @"Errors..." ); | ||
} | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
#import "OCLRule.h" | ||
|
||
@interface OCLDirectoryParser : NSObject { | ||
NSMutableArray *rules_; | ||
} | ||
|
||
// add a validation rule to the parser | ||
- (void)addRule:(id <OCLRule>)rule; | ||
|
||
// parse all the source files in the directory and return any errors | ||
- (NSArray *)parseDirectory:(NSString *)dirPath; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
|
||
#import "OCLDirectoryParser.h" | ||
#import "OCLFileIterator.h" | ||
#import "OCLTokeniser.h" | ||
#import "OCLToken.h" | ||
|
||
@interface OCLDirectoryParser (Private) | ||
|
||
- (NSArray *)parseFile:(NSString *)filePath; | ||
|
||
@end | ||
|
||
@implementation OCLDirectoryParser | ||
|
||
#pragma mark - | ||
#pragma mark Init | ||
|
||
- (id)init { | ||
|
||
if ( (self = [super init]) ) { | ||
rules_ = [[[NSMutableArray alloc] init] retain]; | ||
} | ||
|
||
return self; | ||
|
||
} | ||
|
||
- (void)dealloc { | ||
|
||
[rules_ release]; | ||
|
||
[super dealloc]; | ||
|
||
} | ||
|
||
#pragma mark - | ||
#pragma mark Methods | ||
|
||
- (NSArray *)parseDirectory:(NSString *)dirPath { | ||
|
||
NSMutableArray *errors = [[[NSMutableArray alloc] init] autorelease]; | ||
OCLFileIterator *iterator = [[[OCLFileIterator alloc] initWithPath:dirPath] autorelease]; | ||
NSString *filePath = nil; | ||
|
||
while ( (filePath = [iterator next]) ) { | ||
NSArray *fileErrors = [self parseFile:filePath]; | ||
[errors addObjectsFromArray:fileErrors]; | ||
} | ||
|
||
return [NSArray arrayWithArray:errors]; | ||
|
||
} | ||
|
||
- (void)addRule:(id<OCLRule>)rule { | ||
|
||
[rules_ addObject:rule]; | ||
|
||
} | ||
|
||
#pragma mark - | ||
#pragma mark Private | ||
|
||
- (NSArray *)parseFile:(NSString *)filePath { | ||
|
||
OCLTokeniser *tokeniser = [[[OCLTokeniser alloc] initWithPath:filePath] autorelease]; | ||
NSMutableArray *fileErrors = [[[NSMutableArray alloc] init] autorelease]; | ||
NSArray *tokens = [tokeniser getAllTokens]; | ||
|
||
for ( OCLToken *token in tokens ) { | ||
// @todo dispatch tokens to parser rules | ||
} | ||
|
||
return fileErrors; | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
@interface OCLError : NSObject {} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
#import "OCLError.h" | ||
|
||
@implementation OCLError | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
@protocol OCLRenderer <NSObject> | ||
|
||
- (void)renderErrors:(NSArray *)errors; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
@protocol OCLRule <NSObject> | ||
|
||
// return array of OCLError objects, or nil if none | ||
- (NSArray *)handleToken:(NSArray *)tokens atIndex:(int)index; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
#import "OCLBaseRule.h" | ||
|
||
@interface OCLRuleUnderscoredIvars : OCLBaseRule {} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
#import "OCLRuleUnderscoredIvars.h" | ||
|
||
@implementation OCLRuleUnderscoredIvars | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.