3

我正在为 vim 开发一个模块。目前我有以下代码:

alphabet_rule = Sequence([Repetition(RuleRef(name="x", rule=MappingRule(name="t", mapping=ALPHABET)), min=1, max=20)])
numbers_rule = Sequence([Repetition(RuleRef(name="y", rule=MappingRule(name="u",        mapping=DIGITS)), min=1, max=20)])
symbols_rule = Sequence([Repetition(RuleRef(name="z", rule=MappingRule(name="v", mapping=SYMBOLS)), min=1, max=20)])
alphanumeric = [alphabet_rule, numbers_rule, symbols_rule]

class FindRule(CompoundRule):
  spec = ("(bind | find | tank | bank) <alphanumeric> [<n>]")
  extras = [IntegerRef("n", 1, 10), Alternative(alphanumeric, name="alphanumeric")]
  defaults = {"n": 1}

  def value(self, node, extras):
    words = node.words()
    rule = words[0]
    times = extras["n"]
    print words
    print "Times: %d" % times


    find = Events('key->key=%d;key->key=f' % times)
    bind = Events('key->key=%d;key->key=f&modifier=shift' % times)
    bank = Events('key->key=%d;key->key=t&modifier=shift' % times)
    tank = Events('key->key=%d;key->key=t' % times)

    search = extras["alphanumeric"][0][0]
    if rule == 'bind':
        return (bind + search)
    elif rule == 'find':
        return (find + search)
    elif rule == 'bank':
        return (bank + search)
    elif rule == 'tank':
        return (tank + search)

  def _process_recognition(self, node, extras):
    self.value(node, extras).execute()

find_rule = RuleRef(name="find_rule", rule=FindRule(name="i"))

class ClipRule(CompoundRule):
    spec = ("(clip | dip) <find_rule>")
    extras = [find_rule]

    def _process_recognition(self, node, extras):
        words = node.words()
        if words[0] == 'clip':
            action = Events('key->key=c')
        elif words[0] == 'dip':
            action = Events('key->key=d')

        (action + extras["find_rule"]).execute()

代码在这里给出了我想要做什么的想法,因为它不能在没有蜻蜓的所有花里胡哨和我定义的一些字母、数字和符号的情况下运行。

我可以按预期使用 FindRule,但是当我尝试使用 ClipRule 时,出现以下错误:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\dragonfly\engines\engine_natlink.py", line 248, in results_callback
    r.process_recognition(root)
  File "C:\Python27\lib\site-packages\dragonfly\grammar\rule_compound.py", line 143, in process_recognition
    self._process_recognition(node, extras)
  File "C:\NatLink\NatLink\MacroSystem\_vim.py", line 232, in _process_recognition
    (action + extras["find_rule"]).execute()
  File "C:\Python27\lib\site-packages\dragonfly\actions\action_base.py", line 84, in __add__
    copy.append(other)
  File "C:\Python27\lib\site-packages\dragonfly\actions\action_base.py", line 79, in     append
    assert isinstance(other, ActionBase)
AssertionError

当我在 ClipRule._process_recognition 中执行 => print extras['find_rule'] 时,我得到“无”。我认为这意味着我错误地覆盖了valueFindRule 中的方法。想知道其他人是否有过这方面的经验。谢谢

4

0 回答 0