I have noticed that when I have multiple where
clauses and multiple asserting
clauses, that I get often get syntax errors when I combine them together. The error will say "unexpected token after where". How should I write it to avoid this error? Here is the latest example:
Attempt 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
I also tried rewriting it a different way, that also resulted in the "unexpected token after where" syntax error.
Attempt 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
Example 3:
Here is another example that, I think, highlights the problem:
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 */ ]
)
As you can see from this example, asserting a=b
works fine unless it is preceded by a where
clause.