我刚遇到ParseKit,我使用http://parsekit.com/iphone.html的说明将我的IOS项目纳入其中。我是从Google Code获得的,签出的版本是1543。 所有编译和建造都很好。
然后我尝试使用其中一篇文章中的(最终工作)简单示例 - 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");
}
当执行到达行
时 parser = [[PKParserFactory factory] parserFromGrammar:grammar assembler:self error:&err];
我在控制台中看到很多错误消息。 didMatchFoo和didMatchBar不会触发。
以下是来自控制台的消息:
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];
不调用回调,也不返回任何错误。
非常感谢任何指示或帮助!
PS - 我在ParseKit中取消注释了一些NSLOG语句,看看上面的例外是什么:
语法为
NSString *grammar = @"@start = expr; expr = abc col def; abc = 'ABC'; col = ':'; def = 'DEF';";
我得到了
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»
答案 0 :(得分:0)
我让它工作......有点儿!
与文件有所不同......
我与libParseKitMobile.a链接...很明显,因为它是iOS的唯一目标。
我使用ParserGenApp首先为我的语法生成.h和.m
我在项目中包含了这些生成的文件。我的项目不是用ARC构建的,而ParseKit也是如此,所以我将-fobjc-arc添加到生成的.m的编译标志中
然后在我的代码中使用如下:
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]);
}
回调需要采用以下形式:
- (void)parser:(PKParser *)p didMatchAbc:(PKAssembly *)a;
(ParseKit文档提到 - (void)didMatchAbc:(PKAssembly * a);但是因为所需的签名不同而不起作用)
从Github下载并尝试完整的MiniMath项目帮助我解决了一些问题 - https://github.com/itod/ParseKitMiniMathExample
MiniMath示例也可以作为zip下载,但似乎没有嵌入的ParseKit文件,我遇到了一些问题。
希望这有助于其他人在他们的iOS项目中使用ParseKit!
Todd Ditchendorf,非常感谢你在ParseKit上的工作!不幸的是,它有点碎片--Github版本,谷歌代码版本,网站上的文档稀疏,有趣,链接到Github和谷歌代码,增加了混乱。
parser = [[PKParserFactory factory] parserFromGrammar:grammar assembler:self error:&err];
似乎不起作用。但是,首先生成解析器代码然后使用它似乎工作。
如果可以清理ParseKit并使其更新,那将是很棒的!这是一个非常有用的工具,更是如此,因为我没有看到任何其他替代方案被提及。如果您想帮助清理ParseKit及其文档,我很乐意为您提供帮助!
干杯, 斯里达尔