将断言子句与where子句结合使用

时间:2018-05-26 19:27:21

标签: syntax-error where-clause assertion ffl anura

我注意到当我有多个settings.xml子句和多个where子句时,当我将它们组合在一起时,我经常会遇到语法错误。该错误将显示“在其后的意外令牌”。我该怎么写它来避免这个错误?这是最新的例子:

尝试1:

asserting

我也试过用不同的方式重写它,这也导致了“意外的令牌之后”语法错误。

尝试2:

def(class game_state game) ->commands [
        set(attack, cost),
        set(life, cost),
        set(abilities, []),
    ] where cost=(card.cost + (card.loyalty_cost * size(card.school)))
      where card=crypt_spells[choices[0]]
//      asserting size(choices) = 1 //FIXME: syntax error uncommented
        asserting choices != null
      where crypt_spells=filter(game.crypt.cards_of(player), value.type='spell')
      where player=game.player_obj

示例3:

我认为这是另一个例子,突出了问题:

def(class game_state game) ->commands [
        set(attack, cost),
        set(life, cost),
        set(abilities, []),
    ] where cost=(card.cost + (card.loyalty_cost * size(card.school)))
      where card=crypt_spells[choices[0]]
      asserting choices != null, size(choices)=1 | choices //FIXME: syntax error
      where crypt_spells=filter(game.crypt.cards_of(player), value.type='spell')
      where player=game.player_obj

从这个示例中可以看出,def(class game_state game, class message.play_card info) ->commands if(info.choices, ([ /* do stuff */ ] where entry=game.crypt.get_entry(info.choices[0]) asserting size(info.targets)=1 | info.targets /* PARSE ERROR! */ ) asserting size(info.choices)=1 | info.choices, /* WORKS */ [ /* else */ ] ) 工作正常,除非前面有asserting a=b子句。

1 个答案:

答案 0 :(得分:1)

让我尝试将您的代码转换为通用调试控制台代码:

f()
where f = def
        () -> commands [
                debug(['something']),
                debug(['more stuff']),
                debug(['yet more stuff']),
        ]
        where aaa = (0 + (1 * 2))
        where bbb = 4
//        asserting 2 + 2 = 4 // FIXME: syntax error uncommented
        asserting '000' != null
        where ccc = [0, 1, 2, 3]
        where ddd = {'0': 0, '1': 1, }

调试控制台可以执行:

(debug console):0: ['something']
(debug console):0: ['more stuff']
(debug console):0: ['yet more stuff']
[(Command Object: N10game_logic12_GLOBAL__N_113debug_commandE),
 (Command Object: N10game_logic12_GLOBAL__N_113debug_commandE),
 (Command Object: N10game_logic12_GLOBAL__N_113debug_commandE)]

在取消注释断言时,让我们检查一下你的语法错误是否存在,或者至少有一些语法错误:

f()
where f = def
        () -> commands [
                debug(['something']),
                debug(['more stuff']),
                debug(['yet more stuff']),
        ]
        where aaa = (0 + (1 * 2))
        where bbb = 4
        asserting 2 + 2 = 4 // FIXME: syntax error uncommented
        asserting '000' != null
        where ccc = [0, 1, 2, 3]
        where ddd = {'0': 0, '1': 1, }

调试控制台无法执行:

error parsing formula: formula.cpp:3942 ASSERTION FAILED: Unexpected tokens after
where
At (debug console) 0:
... where bbb = 4       asserting 2 + 2 = 4 // FIXME syntax error uncommen...
                                        ^

引擎使用简单的解析,目前whereasserting=(甚至可能,?)可以直观的方式组合,但管理不善解析器。

在此,我认为它在=之前找到where的辅助,,但我不知道。现在我不确切地知道完成where解析的标准是什么。您只需调试解析器即可知道。

这是一个重要的问题,但可能并不重要,现在必须解决,因为大多数情况下可以通过包含更多的详尽无遗来管理。

让我们只放一个parens对,让我们从失败的断言开始:

f()
where f = def
        () -> commands [
                debug(['something']),
                debug(['more stuff']),
                debug(['yet more stuff']),
        ]
        where aaa = (0 + (1 * 2))
        where bbb = 4
        asserting (2 + 2 = 4) // FIXME: syntax error uncommented
        asserting '000' != null
        where ccc = [0, 1, 2, 3]
        where ddd = {'0': 0, '1': 1, }

调试控制台可以再次执行:

(debug console):0: ['something']
(debug console):0: ['more stuff']
(debug console):0: ['yet more stuff']
[(Command Object: N10game_logic12_GLOBAL__N_113debug_commandE),
 (Command Object: N10game_logic12_GLOBAL__N_113debug_commandE),
 (Command Object: N10game_logic12_GLOBAL__N_113debug_commandE)]

2018年5月27日添加了错误精确位置。