Having got to grips a bit with the ParseKit grammar syntax (playing around in the demo app) I'm now trying to get my own mini demo working, but so far without much success. The assembler callbacks are not getting called.
Below is a condensed version of the relevant code. When testParse
runs the parser seems to do it's thing OK and correctly match my string to my anything
production (which also works in the demo) but didMatchAnything: is just not getting called.
#import <Foundation/Foundation.h>
@class PKParser;
@interface FileParserThing : NSObject {
PKParser* _parser;
}
- (void)testParse;
@end
#import <ParseKit/ParseKit.h>
#import "FileParserThing.h"
@interface FileParserThing ()
@property (nonatomic, retain)PKParser* parser;
- (void)didMatchAnything:(PKAssembly *)a;
@end
@implementation FileParserThing
@synthesize parser = _parser;
-(id)init
{
if (!(self = [super init])) return nil;
NSString *g = @"@start = anything; anything = Any+;";
self.parser = [[PKParserFactory factory] parserFromGrammar:g assembler:self];
return self;
}
- (void)testParse
{
NSString *s = @"Foo Bar";
NSLog(@"test parse with: %@", s);
[self.parser parse:s];
}
- (void)didMatchAnything:(PKAssembly *)a
{
NSLog(@"Hooray!");
}
@end
Digging around in the ParseKit code I can see that line 129 of PKParser
[assembler performSelector:assemblerSelector withObject:self withObject:a];
Isn't being executed, because assembler
is nil. Which, in turn, leads me to the parser factory; where my understanding of what's going on begins to fail.
Disclaimer; I know, I probably need to read The Book, but one thing at a time. I want to get a small proof of concept working, before forking out 30 mice for a book I might never read again if my project is a non-starter :)