ParseKit汇编程序回调未调用:我在做什么错? [英] ParseKit assembler callbacks not called: What am I doing wrong?

查看:88
本文介绍了ParseKit汇编程序回调未调用:我在做什么错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ParseKit语法语法(在演示应用程序中播放)方面必须有所了解,我现在正在尝试使自己的微型演示正常工作,但到目前为止并没有取得太大的成功.汇编程序回调不会被调用.

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.

下面是相关代码的精简版本.当testParse运行时,解析器似乎可以正常运行,并且可以将我的字符串正确匹配到我的anything生产中(在演示中也可以使用),但didMatchAnything:只是没有被调用.

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

在ParseKit代码中浏览,我可以看到PKParser的第129行

Digging around in the ParseKit code I can see that line 129 of PKParser

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

未执行,因为assembler为nil.反过来,这又将我带到了解析器工厂.我对正在发生的事情的理解开始失败.

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.

免责声明;我知道,我可能需要阅读这本书,但一次只能读一本书.我想得到一个小的概念证明,然后拿出30只老鼠买一本书,如果我的项目不是初学者,我可能再也不会读过它了:)

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 :)

推荐答案

ParseKit的开发人员在这里.

Developer of ParseKit here.

前一段时间,我将Assembler回调的签名更改为接受两个参数:

A while back I changed the signature of the Assembler callbacks to accept two arguments:

  1. 与当前令牌匹配的解析器.
  2. 程序集,其中包含输入解析的当前状态.
  1. The Parser which matched the current token.
  2. The Assembly containing the current state of the input parsing.

以前,只有一个论点:议会.

Previously, there had only been one argument: The Assembly.

我不确定文档是否已完全更新以反映这一点.

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

因此,我怀疑如果您仅将Assembler回调方法更改为此,它将起作用:

So I suspect that if you simply change your Assembler callback method to this, it will work:

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

如果没有,请告诉我,我将帮助进一步调试.

If not, let me know, and I'll help to further debug.

对于背景:我进行了此更改是因为遇到了一种情况,我的汇编器回调确实需要检查刚刚进行了当前匹配的解析器.

For background: I made this change because I ran into a situation where my Assembler callback really needed to inspect the Parser which had just made the current match.

它还更加紧密地结合了 Delegate 回调的强大可可约定,该约定始终将 delegator 对象作为其第一个参数.事后看来,我还是希望我将ParseKit中的整个组装器重命名为代表.从可可的角度来说,基本上就是汇编程序.

It also aligned more closely the strong Cocoa convention of Delegate callbacks which always have the delegator object as their first argument. In hindsight I kinda wish I had renamed the whole concept of Assemblers in ParseKit to Delegates. Since in Cocoa parlance, that's basically what Assemblers are.

这篇关于ParseKit汇编程序回调未调用:我在做什么错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆