gpt4 book ai didi

syntax-error - 结合断言子句和where子句

转载 作者:行者123 更新时间:2023-12-03 08:26:50 25 4
gpt4 key购买 nike

我注意到,当我有多个where子句和多个asserting子句时,将它们组合在一起经常会出现语法错误。该错误将显示“where之后出现意外 token ”。我应该如何编写以避免发生此错误?这是最新的示例:

尝试1:

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

我还尝试以另一种方式重写它,这也导致了“where where之后的意外标记”语法错误。

尝试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 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

示例3:

我认为这是另一个突出问题的示例:
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子句之前加了 where,否则它可以正常工作。

最佳答案

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

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日添加了错误定位点。

关于syntax-error - 结合断言子句和where子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50546337/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com