Skip to content

Commit

Permalink
support for defined protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
caged committed Feb 8, 2010
1 parent fe51eb6 commit c2f895b
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 8 deletions.
18 changes: 15 additions & 3 deletions lib/exposition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ def initialize(*source_files)
end

def self.generate!(*source_files)
new(*source_files).parse
if block_given?
parser = new(*source_files)
yield @options
parser.parse
else
new(*source_files).parse
end
end

def parse
Expand Down Expand Up @@ -49,6 +55,7 @@ def parse
def show_stats
total_classes = sum(@parsed_docs.collect { |doc| doc.info.objc_classes.size })
total_categories = sum(@parsed_docs.collect { |doc| doc.info.objc_categories.size })
total_protocols = sum(@parsed_docs.collect { |doc| doc.info.objc_protocols.size })
total_class_methods = sum(@parsed_docs.collect { |doc| sum(doc.info.objc_classes.collect { |c| c.class_methods.size })})
total_instance_methods = sum(@parsed_docs.collect { |doc| sum(doc.info.objc_classes.collect { |c| c.instance_methods.size })})
total_properties = sum(@parsed_docs.collect { |doc| sum(doc.info.objc_classes.collect { |c| c.properties.size })})
Expand All @@ -68,9 +75,14 @@ def show_stats

klasses = objc.objc_classes
categories = objc.objc_categories
protocols = objc.objc_protocols
properties = klasses.collect { |c| c.properties }.flatten
instance_methods = klasses.collect { |c| c.instance_methods }.flatten + categories.collect { |c| c.instance_methods }.flatten
class_methods = klasses.collect { |c| c.class_methods }.flatten + categories.collect { |c| c.class_methods }.flatten
instance_methods = klasses.collect { |c| c.instance_methods }.flatten +
categories.collect { |c| c.instance_methods }.flatten +
protocols.collect { |p| p.instance_methods }.flatten
class_methods = klasses.collect { |c| c.class_methods }.flatten +
categories.collect { |c| c.class_methods }.flatten +
protocols.collect { |p| p.class_methods }.flatten

# HEADER
puts '+' << ('-' * (cols - 2)) << '+'
Expand Down
Empty file added lib/exposition/generator.rb
Empty file.
14 changes: 11 additions & 3 deletions lib/exposition/parser/grammars/objcclasses.treetop
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ grammar ObjCClasses
include Comments

rule objc_object
objc_class / objc_category
objc_class / objc_category / objc_protocol
end

rule objc_class
docs:block_comment? class_start class_decleration members:(property / instance_method / class_method / empty_line)+ class_end <ObjCClass>
docs:block_comment? class_start class_decleration members:(visibility / property / instance_method / class_method / empty_line)+ class_end <ObjCClass>
end

rule objc_category
docs:block_comment? class_start category_decleration members:(instance_method / class_method / empty_line)+ class_end <ObjCCategory>
docs:block_comment? class_start category_decleration members:(visibility / instance_method / class_method / empty_line)+ class_end <ObjCCategory>
end

rule objc_protocol
docs:block_comment? line_break+ '@protocol' space+ protocol_name:type_name pcalls:protocols? members:(visibility / instance_method / class_method / empty_line)+ class_end <ObjCProtocol>
end

rule category_decleration
Expand Down Expand Up @@ -44,4 +48,8 @@ grammar ObjCClasses
rule class_end
line_break* '@end' space* line_break+
end

rule visibility
'@optional'
end
end
4 changes: 2 additions & 2 deletions lib/exposition/parser/grammars/properties.treetop
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ grammar Properties
include Comments

rule property
docs:block_comment? line_break space* prop:("@property" space* attrs:attributes* property_type protocols* space* prop_name:type_name ';') <Property>
docs:block_comment? line_break space* prop:("@property" space* attrs:attributes* property_type protocols* '*'? space* prop_name:type_name ';') <Property>
end

rule attributes
Expand All @@ -20,7 +20,7 @@ grammar Properties
end

rule property_type
(ib_outlet / garbage_collection_modifiers)* space* type_name space* '*'*
space* (ib_outlet / garbage_collection_modifiers)* space* type_name space*
end

rule garbage_collection_modifiers
Expand Down
4 changes: 4 additions & 0 deletions lib/exposition/parser/nodes/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ def objc_classes
def objc_categories
select { |e| e.is_a?(ObjCCategory) }
end

def objc_protocols
select { |e| e.is_a?(ObjCProtocol) }
end
end
end
4 changes: 4 additions & 0 deletions lib/exposition/parser/nodes/objcclasses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class ObjCCategory < ObjCObject

end

class ObjCProtocol < ObjCObject

end

class InstanceVariable < Treetop::Runtime::SyntaxNode
include Language

Expand Down
58 changes: 58 additions & 0 deletions test/samples/HRRequestOperationQueue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* The object which all requests are routed through. You shouldn't need to use
* this class directly, but instead use HRRestModel which wraps the method
* of this class neatly.
*/
@interface HRRequestOperation : NSOperation {
NSObject <HRResponseDelegate>*_delegate;
NSURLConnection *_connection;
NSMutableData *_responseData;
NSString *_path;
NSDictionary *_options;
NSTimeInterval _timeout;
HRRequestMethod _requestMethod;
id _formatter;
id _object;
BOOL _isFinished;
BOOL _isExecuting;
BOOL _isCancelled;
}

/**
* The HRResponseDelegate responsible for handling the success and failure of
* a request.
*/
@property (nonatomic, readonly, assign) NSObject <HRResponseDelegate>*delegate;

/**
* Sets the length of time in seconds before a request will timeout.
* This defaults to <tt>30.0</tt>.
*/
@property (nonatomic, assign) NSTimeInterval timeout;

/**
* This defaults to HRRequestMethodGet. Valid options are ::HRRequestMethod.
*/
@property (nonatomic, assign) HRRequestMethod requestMethod;

/**
* If you provide a relative path here, you must set the baseURL option.
* If given a full url this will overide the baseURL option.
*/
@property (nonatomic, copy) NSString *path;

/**
* This needs documented
*/
@property (nonatomic, retain) NSDictionary *options;

/**
* Currently, only JSON is supported.
*/
@property (nonatomic, readonly, retain) id formatter;

/**
* Returns an HRRequestOperation
*/
+ (HRRequestOperation *)requestWithMethod:(HRRequestMethod)method path:(NSString*)urlPath options:(NSDictionary*)requestOptions object:(id)obj;
@end
60 changes: 60 additions & 0 deletions test/samples/HRResponseDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// HRResponseDelegate.h
// HTTPRiot
//
// Created by Justin Palmer on 6/24/09.
// Copyright 2009 LabratRevenge LLC.. All rights reserved.
//

/**
* Implementing the HRResponseDelegate protocol allows you to handle requests.
*/
@protocol HRResponseDelegate <NSObject>
@optional
/**
* Called when the resource was succeffully fetched and encoded
*
* @param connection The connection object for the current request
* @param resource The converted objc representation of the response data returned by the server.
* @param object Any custom object you passed in while making the request.
*/
- (void)restConnection:(NSURLConnection *)connection didReturnResource:(id)resource object:(id)object;

/**
* Called when the connection fails in situations where the server is not available, etc.
*
* @param connection The connection object for the current request
* @param error The error returned by the connection.
* @param object Any custom object you passed in while making the request.
*/
- (void)restConnection:(NSURLConnection *)connection didFailWithError:(NSError *)error object:(id)object;

/**
* Called when the connection receieves any type of response
*
* @param connection The connection object for the current request
* @param response The response object returned by the server.
* @param object Any custom object you passed in while making the request.
*/
- (void)restConnection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response object:(id)object;

/**
* Called when the connection receieves a statusCode that isn't a success code.
*
* @param connection The connection object for the current request
* @param error The error returned by the connection.
* @param response The response object returned by the server.
* @param object Any custom object you passed in while making the request.
*/
- (void)restConnection:(NSURLConnection *)connection didReceiveError:(NSError *)error response:(NSHTTPURLResponse *)response object:(id)object;

/**
* Called when the HRFormatter recieved an error parsing the response data.
*
* @param connection The connection object for the current request
* @param error The parser error returned by the formatter.
* @param body A string representation of the response body returned by the server.
* @param object Any custom object you passed in while making the request.
*/
- (void)restConnection:(NSURLConnection *)connection didReceiveParseError:(NSError *)error responseBody:(NSString *)body object:(id)object;
@end

0 comments on commit c2f895b

Please sign in to comment.