ManageIQ / floe

Floe is a runner for Amazon States Language workflows
Apache License 2.0
0 stars 5 forks source link

Fix edge cases with States.Array #237

Closed Fryguy closed 2 months ago

Fryguy commented 2 months ago

@agrare Please review.


To understand this better it's important to understand how parslet deals with maybe values. So, after fixing the simple args list to be a maybe (to allow 0 parameters), we'd end up with:

$ bin/console
irb(main):001:0> Floe::Workflow::IntrinsicFunction::Parser.new.parse("States.Array()")
=> {:states_array=>"States.Array()"@0}
irb(main):002:0> Floe::Workflow::IntrinsicFunction::Parser.new.parse("States.Array(1)")
=> {:states_array=>{:number=>"1"@13}}
irb(main):003:0> Floe::Workflow::IntrinsicFunction::Parser.new.parse("States.Array(1, 2)")
=> {:states_array=>[{:number=>"1"@13}, {:number=>"2"@16}]}

In other words, if you don't have any args, it returns the parsed slice (weird). With 1 arg it returns the arg directly, and with >1 arg, it returns them as an Array. So, to make this less complicated to transform, this PR introduces the args as a dedicated token.

The next problem you hit is as it resolves the args from the bottom up, you can end up with cases which conflict with existing transforms. For example,

So, to solve this, we ensure that each arg is explicitly defined as an :arg in the parser. Thus the case above becomes: