lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sat, Sep 25, 2010 at 7:05 PM, Scott Vokes <vokes.s@gmail.com> wrote:
> For matching { [1 or 2], [1 or 2] }...There could probably be a
> utility function added to tamale, "any(array_of_values)", that tamale
> would recognize and turn into multiple rows.

The syntax M { {pat1, ret1}, {pat2, ret2} } combines the more
primitive operations of alternation and capture, but we may at times
like this want direct expression of the more primitive operations.

>> -- test false/nil result (ok?)
>> print(M {{1}} (1)) --> nil, table
> This is nil because there's no result in the rule. Should I add an
> assert for this? It'd almost certainly be an error, like a typo in a
> variable name.

Since Lua can't distinguish {1} and {1, nil}, that leads to the
question of what a nil return value means.  Currently, it is allowed
and means capture nil.

Note also this questionable behavior:

  M {{ {V'_'}, true }} ({}) --> false, ...
  M {{ {V'_'}, true }} ({nil, [10]=1}) --> true, ...
  M {{ {V'_'}, true }} ({x=1})) --> true, ...

>>> I also added a special variable, V"...", which sets the partial flag
>>> and captures all subsequent array-portion values. (e.g. { "foo, V"..." }).
>> Maybe decompose V"..." into Star(V"_").  This generalization allows
>> {Star(isnumber)} to match an array of numbers.
>   I'm not sure what you mean here. V"_" means "don't capture or test
> against this value", sort of like . in regular expressions. (It's a
> Prolog-ism.)

{ {{V'x', Star(pat)}, true} }
would perhaps mean
{ {{V'x'}, true}, {{V'x', pat}, true}, {{V'x', pat, pat}, true}, .....etc.....}
where one possible value for pat would be V'_', but see above concerns on nil.