0

I just came across ParseKit, and I incorporated in my IOS project using the instructions from http://parsekit.com/iphone.html. I got it from Google Code, and the checked out version is 1543. Everything compiled and built fine.

Then I tried to use the (final working) simple example from one of the posts - Can't get simple ParseKit example working

NSString *test = @"FOO : BAR";

NSString *grammar = @"@start = foo ':' bar; foo = 'FOO'; bar = 'BAR';";

PKParser *parser = nil;
NSError *err = nil;
parser = [[PKParserFactory factory] parserFromGrammar:grammar assembler:self error:&err];
NSLog(@"parser: error1: %@", err);

[parser parse:test error:&err];
NSLog(@"parser: error2: %@", err);


- (void)didMatchFoo:(PKAssembly *)a
{
   NSLog(@"FOO");
}

- (void)didMatchBar:(PKAssembly *)a
{
   NSLog(@"BAR");
} 

when the execution gets to the line

    parser = [[PKParserFactory factory] parserFromGrammar:grammar assembler:self error:&err];

I see a lot of error messages in the console. The didMatchFoo and didMatchBar do not fire.

Here are the messages from the console:

objc[53244]: EXCEPTIONS: throwing 0xb47f040 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd2e0] for exception 0xb47f020
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd2e0] for exception 0xb47f020
objc[53244]: EXCEPTIONS: handling exception 0xb47f020 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler
objc[53244]: EXCEPTIONS: throwing 0xb47f5e0 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd170] for exception 0xb47f5c0
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd170] for exception 0xb47f5c0
objc[53244]: EXCEPTIONS: handling exception 0xb47f5c0 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler
objc[53244]: EXCEPTIONS: throwing 0xa589360 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd230] for exception 0xa589340
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd230] for exception 0xa589340
objc[53244]: EXCEPTIONS: handling exception 0xa589340 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler
objc[53244]: EXCEPTIONS: throwing 0xa589470 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd290] for exception 0xa589450
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd290] for exception 0xa589450
objc[53244]: EXCEPTIONS: handling exception 0xa589450 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler
objc[53244]: EXCEPTIONS: throwing 0xa58bd80 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd380] for exception 0xa58bd60
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd380] for exception 0xa58bd60
objc[53244]: EXCEPTIONS: handling exception 0xa58bd60 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler
objc[53244]: EXCEPTIONS: throwing 0x8b848e0 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd210] for exception 0x8b848c0
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd210] for exception 0x8b848c0
objc[53244]: EXCEPTIONS: handling exception 0x8b848c0 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler
objc[53244]: EXCEPTIONS: throwing 0x8ba5610 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd2d0] for exception  0x8ba55f0
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd2d0] for exception 0x8ba55f0
objc[53244]: EXCEPTIONS: handling exception 0x8ba55f0 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler
objc[53244]: EXCEPTIONS: throwing 0xb57a160 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd330] for exception 0xb57a140
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd330] for exception 0xb57a140
objc[53244]: EXCEPTIONS: handling exception 0xb57a140 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler
objc[53244]: EXCEPTIONS: throwing 0xb57a730 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd2e0] for exception 0xb57a710
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd2e0] for exception 0xb57a710
objc[53244]: EXCEPTIONS: handling exception 0xb57a710 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler
objc[53244]: EXCEPTIONS: throwing 0xb57ac90 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd170] for exception 0xb57ac70
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd170] for exception 0xb57ac70
objc[53244]: EXCEPTIONS: handling exception 0xb57ac70 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler
objc[53244]: EXCEPTIONS: throwing 0xb57af30 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd230] for exception 0xb57af10
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd230] for exception 0xb57af10
objc[53244]: EXCEPTIONS: handling exception 0xb57af10 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler 
objc[53244]: EXCEPTIONS: throwing 0x8ba5c40 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd290] for exception 0x8ba5c20
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd290] for exception 0x8ba5c20
objc[53244]: EXCEPTIONS: handling exception 0x8ba5c20 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler
objc[53244]: EXCEPTIONS: throwing 0x8ba5f40 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd380] for exception 0x8ba5f20
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd380] for exception 0x8ba5f20
objc[53244]: EXCEPTIONS: handling exception 0x8ba5f20 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler
objc[53244]: EXCEPTIONS: throwing 0x8e80b40 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd210] for exception 0x8e80b20
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd210] for exception 0x8e80b20
objc[53244]: EXCEPTIONS: handling exception 0x8e80b20 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler
objc[53244]: EXCEPTIONS: throwing 0x8e4ac80 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd2d0] for exception 0x8e4ac60
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd2d0] for exception 0x8e4ac60
objc[53244]: EXCEPTIONS: handling exception 0x8e4ac60 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler
objc[53244]: EXCEPTIONS: throwing 0x8ba6200 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd330] for exception 0x8ba61e0
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd330] for exception 0x8ba61e0
objc[53244]: EXCEPTIONS: handling exception 0x8ba61e0 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler
objc[53244]: EXCEPTIONS: throwing 0x8ba62c0 (object 0xa17b7b0, a PEGRecognitionException)
objc[53244]: EXCEPTIONS: searching through frame [ip=0xf23ac sp=0xbfffd420] for exception 0x8ba62a0
objc[53244]: EXCEPTIONS: catch(PEGRecognitionException)
objc[53244]: EXCEPTIONS: unwinding through frame [ip=0xf23ac sp=0xbfffd420] for exception 0x8ba62a0
objc[53244]: EXCEPTIONS: handling exception 0x8ba62a0 at 0xf2406
objc[53244]: EXCEPTIONS: finishing handler

[parser parse:test error:&err];

Does not invoke callbacks, and does not return any error either.

Any pointers or help would be greatly appreciated!

PS - I uncommented some NSLOG statements in ParseKit to see what the exceptions above were:

For a grammar of

    NSString *grammar = @"@start = expr; expr = abc col def; abc = 'ABC'; col = ':'; def = 'DEF';";

I got

Expected : @
Line : 1
Near : ; expr = abc 
Found : =

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def 
Found : col

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def 
Found : def

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def 
Found : def

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def ; abc 
Found : ;

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def ; abc 
Found : ;

No viable alternative found in rule 'primaryExpr'.
Line : 1
Near : ; expr = abc col def ; abc 
Found : ;

Expected : |
Line : 1
Near : ; expr = abc col def ; abc 
Found : ;

Expected : @
Line : 1
Near : ; expr = abc col def ; abc 
Found : =

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def ; abc 
Found : col

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def ; abc 
Found : def

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def ; abc 
Found : def

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def ; abc 
Found : ;

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def ; abc 
Found : ;

No viable alternative found in rule 'primaryExpr'.
Line : 1
Near : ; expr = abc col def ; abc 
Found : ;

Expected : |
Line : 1
Near : ; expr = abc col def ; abc 
Found : ;

Expected : @
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' 
Found : =

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col 
Found : ;

No viable alternative found in rule 'primaryExpr'.
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col 
Found : ;

Expected : |
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col 
Found : ;

Expected : @
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col 
Found : =

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col 
Found : ;

No viable alternative found in rule 'primaryExpr'.
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col 
Found : ;

Expected : |
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col 
Found : ;

Expected : @
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' 
Found : =

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' ; def 
Found : ;

No viable alternative found in rule 'primaryExpr'.
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' ; def 
Found : ;

Expected : |
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' ; def 
Found : ;

Expected : @
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' ; def 
Found : =

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' ; def 
Found : ;

No viable alternative found in rule 'primaryExpr'.
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' ; def 
Found : ;

Expected : |
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' ; def 
Found : ;

Expected : @
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' ; def = 'DEF' 
Found : =

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' ; def = 'DEF' ; 
Found : ;

No viable alternative found in rule 'primaryExpr'.
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' ; def = 'DEF' ; 
Found : ;

Expected : |
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' ; def = 'DEF' ; 
Found : ;

Expected : @
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' ; def = 'DEF' ; 
Found : =

No viable alternative found in rule 'predicate'.
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' ; def = 'DEF' ; 
Found : ;

No viable alternative found in rule 'primaryExpr'.
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' ; def = 'DEF' ; 
Found : ;

Expected : |
Line : 1
Near : ; expr = abc col def ; abc = 'ABC' ; col = ':' ; def = 'DEF' ; 
Found : ;

No viable alternative found in rule 'statement'.
Line : 2147483647
Near : «EOF» 
Found : «EOF»
Community
  • 1
  • 1

1 Answers1

0

I got it to work ... sort of!

Where things differ from the documentation ...

I linked with libParseKitMobile.a ... it was obvious since it was the only target for iOS.

I used ParserGenApp to first generate the .h and .m for my grammar

I included these generated files in my project. My project was not built with ARC, and ParseKit does, so I added -fobjc-arc to the compile flag of the generated .m

Then usage in my code was as follows:

NSString *test = @"ABC : DEF";

MyParser *parser = [[MyParser alloc] init];
NSError *err = nil;
PKAssembly *result = [parser parseString:test
                               assembler:self
                                   error:&err];

if (!result) {
    if (err) NSLog(@"%@", err);
} else {
    NSLog(@"%@", [result description]);
}

The callback needs to be of the form:

- (void)parser:(PKParser *)p didMatchAbc:(PKAssembly *)a;

(the ParseKit documentation mentions -(void)didMatchAbc:(PKAssembly *a); but that won't work as the required signature is different)

Downloading and trying the full MiniMath project from Github helped me figure some of it out - https://github.com/itod/ParseKitMiniMathExample

MiniMath example was also available for download as a zip, but that does not seem to have the embedded ParseKit files and I had some problems with that.

Hope this helps others looking to use ParseKit in their iOS projects!

Todd Ditchendorf, thanks a lot for your work on ParseKit! Unfortunately, it is a little fragmented - Github version, Google Code version, and the documentation in the website is sparse, and interesting, has links to both Github and Google code, adding to the confusion.

parser = [[PKParserFactory factory] parserFromGrammar:grammar assembler:self error:&err];

does not seem to work. However, generating the parser code first and then using it seems to work.

It will be great if ParseKit can be cleaned up and brought up-to-date! It is a very useful tool, and all the more so because I don't see any other alternative being mentioned. If you would like help in cleaning up ParseKit and its documentation, I would be glad to help!

Cheers, Sridhar