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:
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,
States.Array() will produce a tree like
{:states_array=>{:args=>nil}}
States.Array(null) will produce a tree like
{:states_array=>{:args=>{:null_literal=>"null"@13}}}, and when that null_literal is processed from the bottom up, you'll get an intermediate tree of
{:states_array=>{:args=>nil}}
So, to solve this, we ensure that each arg is explicitly defined as an :arg in the parser. Thus the case above becomes:
States.Array() will produce a tree like
{:states_array=>{:args=>nil}}
States.Array(null) will produce a tree like
{:states_array=>{:args=>{:arg=>{:null_literal=>"null"@13}}}} and when that null_literal is processed from the bottom up, you'll get an intermediate tree of
@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:
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,
States.Array()
will produce a tree like{:states_array=>{:args=>nil}}
States.Array(null)
will produce a tree like{:states_array=>{:args=>{:null_literal=>"null"@13}}}
, and when that null_literal is processed from the bottom up, you'll get an intermediate tree of{:states_array=>{:args=>nil}}
So, to solve this, we ensure that each arg is explicitly defined as an
:arg
in the parser. Thus the case above becomes:States.Array()
will produce a tree like{:states_array=>{:args=>nil}}
States.Array(null)
will produce a tree like{:states_array=>{:args=>{:arg=>{:null_literal=>"null"@13}}}}
and when that null_literal is processed from the bottom up, you'll get an intermediate tree of{:states_array=>{:args=>{:arg=>nil}}}