Skip to content

Commit

Permalink
added object structure for parser, parser rules, and renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
rodnaph committed Aug 9, 2011
1 parent d1cd0a3 commit 37d5a01
Show file tree
Hide file tree
Showing 16 changed files with 248 additions and 32 deletions.
42 changes: 42 additions & 0 deletions objc-lint.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
objects = {

/* Begin PBXBuildFile section */
DC1C5D0F13F19DD800527196 /* OCLConsoleRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = DC1C5D0E13F19DD800527196 /* OCLConsoleRenderer.m */; };
DC1C5D1413F1E84C00527196 /* OCLBaseRule.m in Sources */ = {isa = PBXBuildFile; fileRef = DC1C5D1313F1E84C00527196 /* OCLBaseRule.m */; };
DC1C5D1713F1E89B00527196 /* OCLError.m in Sources */ = {isa = PBXBuildFile; fileRef = DC1C5D1613F1E89B00527196 /* OCLError.m */; };
DC1C5D1A13F1EA0100527196 /* OCLDirectoryParser.m in Sources */ = {isa = PBXBuildFile; fileRef = DC1C5D1913F1EA0100527196 /* OCLDirectoryParser.m */; };
DC1C5D1D13F1EDE700527196 /* OCLRuleUnderscoredIvars.m in Sources */ = {isa = PBXBuildFile; fileRef = DC1C5D1C13F1EDE700527196 /* OCLRuleUnderscoredIvars.m */; };
DC206A4513F078C5001661CD /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC206A4413F078C5001661CD /* Foundation.framework */; };
DC206A4813F078C5001661CD /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DC206A4713F078C5001661CD /* main.m */; };
DC206A5613F07C29001661CD /* OCLTokeniser.m in Sources */ = {isa = PBXBuildFile; fileRef = DC206A5513F07C29001661CD /* OCLTokeniser.m */; };
Expand All @@ -27,6 +32,18 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
DC1C5D0D13F19DD800527196 /* OCLConsoleRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCLConsoleRenderer.h; sourceTree = "<group>"; };
DC1C5D0E13F19DD800527196 /* OCLConsoleRenderer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCLConsoleRenderer.m; sourceTree = "<group>"; };
DC1C5D1013F19E1000527196 /* OCLRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCLRenderer.h; sourceTree = "<group>"; };
DC1C5D1113F19E5700527196 /* OCLRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCLRule.h; sourceTree = "<group>"; };
DC1C5D1213F1E84C00527196 /* OCLBaseRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCLBaseRule.h; sourceTree = "<group>"; };
DC1C5D1313F1E84C00527196 /* OCLBaseRule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCLBaseRule.m; sourceTree = "<group>"; };
DC1C5D1513F1E89B00527196 /* OCLError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCLError.h; sourceTree = "<group>"; };
DC1C5D1613F1E89B00527196 /* OCLError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCLError.m; sourceTree = "<group>"; };
DC1C5D1813F1EA0100527196 /* OCLDirectoryParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCLDirectoryParser.h; sourceTree = "<group>"; };
DC1C5D1913F1EA0100527196 /* OCLDirectoryParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCLDirectoryParser.m; sourceTree = "<group>"; };
DC1C5D1B13F1EDE700527196 /* OCLRuleUnderscoredIvars.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCLRuleUnderscoredIvars.h; sourceTree = "<group>"; };
DC1C5D1C13F1EDE700527196 /* OCLRuleUnderscoredIvars.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCLRuleUnderscoredIvars.m; sourceTree = "<group>"; };
DC206A4013F078C5001661CD /* objc-lint */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "objc-lint"; sourceTree = BUILT_PRODUCTS_DIR; };
DC206A4413F078C5001661CD /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
DC206A4713F078C5001661CD /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
Expand All @@ -52,6 +69,18 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
DC1C5D0C13F19D2D00527196 /* Rule */ = {
isa = PBXGroup;
children = (
DC1C5D1113F19E5700527196 /* OCLRule.h */,
DC1C5D1213F1E84C00527196 /* OCLBaseRule.h */,
DC1C5D1313F1E84C00527196 /* OCLBaseRule.m */,
DC1C5D1B13F1EDE700527196 /* OCLRuleUnderscoredIvars.h */,
DC1C5D1C13F1EDE700527196 /* OCLRuleUnderscoredIvars.m */,
);
name = Rule;
sourceTree = "<group>";
};
DC206A3513F078C4001661CD = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -86,6 +115,8 @@
DC206A4913F078C5001661CD /* Supporting Files */,
DC206A5813F095BE001661CD /* OCLFileIterator.h */,
DC206A5913F095BE001661CD /* OCLFileIterator.m */,
DC1C5D1513F1E89B00527196 /* OCLError.h */,
DC1C5D1613F1E89B00527196 /* OCLError.m */,
DC206A4713F078C5001661CD /* main.m */,
);
path = "objc-lint";
Expand Down Expand Up @@ -114,13 +145,19 @@
DC206A5213F07BDA001661CD /* Parser */ = {
isa = PBXGroup;
children = (
DC1C5D0C13F19D2D00527196 /* Rule */,
DC1C5D1813F1EA0100527196 /* OCLDirectoryParser.h */,
DC1C5D1913F1EA0100527196 /* OCLDirectoryParser.m */,
);
name = Parser;
sourceTree = "<group>";
};
DC206A5313F07BE2001661CD /* Renderer */ = {
isa = PBXGroup;
children = (
DC1C5D0D13F19DD800527196 /* OCLConsoleRenderer.h */,
DC1C5D0E13F19DD800527196 /* OCLConsoleRenderer.m */,
DC1C5D1013F19E1000527196 /* OCLRenderer.h */,
);
name = Renderer;
sourceTree = "<group>";
Expand Down Expand Up @@ -176,6 +213,11 @@
DC206A5613F07C29001661CD /* OCLTokeniser.m in Sources */,
DC206A5A13F095BE001661CD /* OCLFileIterator.m in Sources */,
DC22B21A13F10B110067DC1E /* OCLToken.m in Sources */,
DC1C5D0F13F19DD800527196 /* OCLConsoleRenderer.m in Sources */,
DC1C5D1413F1E84C00527196 /* OCLBaseRule.m in Sources */,
DC1C5D1713F1E89B00527196 /* OCLError.m in Sources */,
DC1C5D1A13F1EA0100527196 /* OCLDirectoryParser.m in Sources */,
DC1C5D1D13F1EDE700527196 /* OCLRuleUnderscoredIvars.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 6 additions & 0 deletions objc-lint/OCLBaseRule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#import "OCLRule.h"

@interface OCLBaseRule : NSObject <OCLRule> {}

@end
12 changes: 12 additions & 0 deletions objc-lint/OCLBaseRule.m
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
6 changes: 6 additions & 0 deletions objc-lint/OCLConsoleRenderer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#import "OCLRenderer.h"

@interface OCLConsoleRenderer : NSObject <OCLRenderer> {}

@end
16 changes: 16 additions & 0 deletions objc-lint/OCLConsoleRenderer.m
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
14 changes: 14 additions & 0 deletions objc-lint/OCLDirectoryParser.h
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
77 changes: 77 additions & 0 deletions objc-lint/OCLDirectoryParser.m
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
4 changes: 4 additions & 0 deletions objc-lint/OCLError.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

@interface OCLError : NSObject {}

@end
6 changes: 6 additions & 0 deletions objc-lint/OCLError.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#import "OCLError.h"

@implementation OCLError

@end
6 changes: 6 additions & 0 deletions objc-lint/OCLRenderer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

@protocol OCLRenderer <NSObject>

- (void)renderErrors:(NSArray *)errors;

@end
7 changes: 7 additions & 0 deletions objc-lint/OCLRule.h
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
6 changes: 6 additions & 0 deletions objc-lint/OCLRuleUnderscoredIvars.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#import "OCLBaseRule.h"

@interface OCLRuleUnderscoredIvars : OCLBaseRule {}

@end
6 changes: 6 additions & 0 deletions objc-lint/OCLRuleUnderscoredIvars.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#import "OCLRuleUnderscoredIvars.h"

@implementation OCLRuleUnderscoredIvars

@end
5 changes: 4 additions & 1 deletion objc-lint/OCLTokeniser.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@interface OCLTokeniser : NSObject {
NSString *fileContent_;
int currentPos_, lastChr_;
int currentPos_;
}

@property (nonatomic, retain) NSString *path;
Expand All @@ -22,4 +22,7 @@
// return the next token if there is one, or nil
- (OCLToken *)next;

// read configured file and return all tokens
- (NSArray *)getAllTokens;

@end
30 changes: 22 additions & 8 deletions objc-lint/OCLTokeniser.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@

@interface OCLTokeniser (Private)

// read a single character from the file (return any putBack)
- (int)read;

// put a character back to be read again
- (void)putBack:(int)chr;

- (BOOL)isAlpha:(int)chr;

- (BOOL)isAlphaNumeric:(int)chr;

- (BOOL)isNumeric:(int)chr;

@end
Expand Down Expand Up @@ -56,7 +62,6 @@ - (id)initWithPath:(NSString *)path {

fileContent_ = [[NSString alloc] initWithContentsOfFile:path_ encoding:NSUTF8StringEncoding error:nil];
currentPos_ = 0;
lastChr_ = -1;

}

Expand All @@ -76,6 +81,19 @@ - (void)dealloc {
#pragma mark -
#pragma mark Methods

- (NSArray *)getAllTokens {

NSMutableArray *tokens = [[[NSMutableArray alloc] init] autorelease];
OCLToken *token;

while ( (token = [self next]) != nil ) {
[tokens addObject:token];
}

return [NSArray arrayWithArray:tokens];

}

- (OCLToken *)next {

OCLToken *currentToken_ = nil;
Expand Down Expand Up @@ -208,19 +226,15 @@ - (OCLToken *)next {

- (int)read {

if ( lastChr_ != -1 ) {
int chr = lastChr_;
lastChr_ = -1;
return chr;
}

return [fileContent_ characterAtIndex:currentPos_++];

}

- (void)putBack:(int)chr {

lastChr_ = chr;
if ( currentPos_ > 0 ) {
currentPos_--;
}

}

Expand Down
Loading

0 comments on commit 37d5a01

Please sign in to comment.