Permalink
Switch branches/tags
Find file
Fetching contributors…
Cannot retrieve contributors at this time
77 lines (64 sloc) 2.43 KB
#import "{{className}}.h"
#import <ParseKit/ParseKit.h>
#define LT(i) [self LT:(i)]
#define LA(i) [self LA:(i)]
#define LS(i) [self LS:(i)]
#define LF(i) [self LF:(i)]
#define POP() [self.assembly pop]
#define POP_STR() [self _popString]
#define POP_TOK() [self _popToken]
#define POP_BOOL() [self _popBool]
#define POP_INT() [self _popInteger]
#define POP_FLOAT() [self _popDouble]
#define PUSH(obj) [self.assembly push:(id)(obj)]
#define PUSH_BOOL(yn) [self _pushBool:(BOOL)(yn)]
#define PUSH_INT(i) [self _pushInteger:(NSInteger)(i)]
#define PUSH_FLOAT(f) [self _pushDouble:(double)(f)]
#define EQ(a, b) [(a) isEqual:(b)]
#define NE(a, b) (![(a) isEqual:(b)])
#define EQ_IGNORE_CASE(a, b) (NSOrderedSame == [(a) compare:(b)])
#define ABOVE(fence) [self.assembly objectsAbove:(fence)]
#define LOG(obj) do { NSLog(@"%@", (obj)); } while (0);
#define PRINT(str) do { printf("%s\n", (str)); } while (0);
@interface PKSParser ()
@property (nonatomic, retain) NSMutableDictionary *_tokenKindTab;
@property (nonatomic, retain) NSMutableArray *_tokenKindNameTab;
- (BOOL)_popBool;
- (NSInteger)_popInteger;
- (double)_popDouble;
- (PKToken *)_popToken;
- (NSString *)_popString;
- (void)_pushBool:(BOOL)yn;
- (void)_pushInteger:(NSInteger)i;
- (void)_pushDouble:(double)d;
{%if parseTree %}
- (void)fireSyntaxSelector:(SEL)sel withRuleName:(NSString *)ruleName;
{%/if%}@end
@interface {{className}} ()
{%if enableMemoization %}{%for methodName in ruleMethodNames %}@property (nonatomic, retain) NSMutableDictionary *{{methodName}}_memo;
{%/for%}{%/if%}@end
@implementation {{className}}
- (id)init {
self = [super init];
if (self) {
{%if enableAutomaticErrorRecovery %} self.enableAutomaticErrorRecovery = YES;
{%/if%}{%for kind in tokenKinds %} self._tokenKindTab[@"{{kind.stringValue}}"] = @({{kind.name}});
{%/for%}
{%for kind in tokenKinds %} self._tokenKindNameTab[{{kind.name}}] = @"{{kind.stringValue}}";
{%/for%}
{%if enableMemoization %}{%for methodName in ruleMethodNames %} self.{{methodName}}_memo = [NSMutableDictionary dictionary];
{%/for%}{%/if%} }
return self;
}
{%if manualMemory && enableMemoization %}
- (void)dealloc {
{%for methodName in ruleMethodNames %} self.{{methodName}}_memo = nil;
{%/for%}
[super dealloc];
}
{%/if%}{%if enableMemoization %}
- (void)_clearMemo {
{%for methodName in ruleMethodNames %} [_{{methodName}}_memo removeAllObjects];
{%/for%}}{%/if%}
{{methods}}
@end