0

ParseKit に出会い、http://parsekit.com/iphone.htmlの指示に従って IOS プロジェクトに組み込みました。Google Code から取得しました。チェックアウトしたバージョンは 1543 です。すべてが正常にコンパイルおよびビルドされました。

次に、投稿の1つから(最終的に機能する)単純な例を使用しようとしました-単純なParseKitの例が機能しません

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»
4

1 に答える 1

0

私はそれを働かせました...ちょっと!

ドキュメントと異なるところ...

libParseKitMobile.a とリンクしました... iOS の唯一のターゲットだったので、それは明らかでした。

ParserGenApp を使用して、最初に文法の .h と .m を生成しました

これらの生成されたファイルをプロジェクトに含めました。私のプロジェクトは ARC で構築されていませんが、ParseKit は構築されているため、生成された .m のコンパイル フラグに -fobjc-arc を追加しました。

次に、私のコードでの使用法は次のとおりです。

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 を使用しようとしている他の人に役立つことを願っています!

トッド・ディッチェンドルフ、ParseKit での作業に感謝します! 残念ながら、それは少し断片化されています.Githubバージョン、Googleコードバージョン、そしてウェブサイトのドキュメントはまばらで興味深いものであり、GithubとGoogleコードの両方へのリンクがあり、混乱を助長しています.

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

動作しないようです。ただし、最初にパーサー コードを生成してから使用するとうまくいくようです。

ParseKit をクリーンアップして最新の状態にすることができれば素晴らしいことです。これは非常に便利なツールであり、他の代替手段が言及されていないためなおさらです。ParseKit とそのドキュメントのクリーンアップについてサポートが必要な場合は、喜んでお手伝いします。

乾杯、スリダール

于 2013-09-04T00:56:59.970 に答える