ParseKit assembler call responses are not being called: what am I doing wrong?

After catching a little bit with the ParseKit grammar syntax (playing the demo app), I am now trying to get my own mini demo, but without much success so far. The assembler callbacks are not called.

Below is a condensed version of the relevant code. When testParse

runs the parser it seems to do it fine and matches my string correctly for my anything

production (which also works in the demo), but didMatchAnything: just doesn't get called.

#import <Foundation/Foundation.h>

@class PKParser;

@interface FileParserThing : NSObject {
    PKParser* _parser;
- (void)testParse;

#import <ParseKit/ParseKit.h>
#import "FileParserThing.h"

@interface FileParserThing ()
@property (nonatomic, retain)PKParser* parser;
- (void)didMatchAnything:(PKAssembly *)a;

@implementation FileParserThing

@synthesize parser = _parser;

    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



Digging into the ParseKit code, I see that line 129 PKParser

[assembler performSelector:assemblerSelector withObject:self withObject:a];


Not executed because it assembler

is zero. Which in turn leads me to a parser factory; where my understanding of what is going on starts to fail.

Denial of responsibility; I know I should probably read The Book, but one at a time. I want to get a little proof of work before putting out 30 mice for a book that I might never read again if my project isn't a starter :)


source to share

1 answer

The ParseKit developer is here.

And back I changed the signature of the assembler callbacks to accept two arguments :

  • A parser that matches the current token.
  • Assembly containing the current parsing state of the input.

Previously, there was only one argument: Assembly.

I'm not sure if the docs are fully updated to reflect this.

So I suspect that if you just change the assembler callback method to this, it will work:

- (void)parser:(PKParser *)p didMatchAnything:(PKAssembly *)a {
    NSLog(@"%s %@", __PRETTY_FUNCTION__, a);


If not, please let me know and I will help further debug.

For background: I made this change because I ran into a situation where my Assembler callback was actually needed to validate the Parser, which just made the current match.

It also more closely aligned Cocoa's strong convention of delegated callbacks, which always have a delegate object as the first argument. In hindsight, I would like me to rename the whole concept of Assemblers in ParseKit to Delegates . Since in Cocoa, this is basically what Assemblers are.



All Articles