[Metalua-list] Patch

Fabien Fleutot fleutot at gmail.com
Thu Sep 4 04:37:10 GMT+2 2008


The place is mlp_stat, function return_expr_list_parser(), and the bug isn't
completely trivial.

The idiom that isn't recognized is "return ;" (semicolon and no returned
value). That's because of the way gg.list works: for it to accept empty
lists, it needs to know the list of keywords indicating the end of a list
(gg.list is properly documented in the manual). In the return arguments
parser return_expr_list_parser(), the terminators are the same as block
terminators: "end", "until", "else" etc. This list is stored in
mlp.block_teminators (mlp_stat.lua). So the first idea would be to make a
copy of this list, adding ";" as an extra value, but it won't work:
mlp.block_terminators might be extended at runtime when new syntaxes define
new blocks, and your return_terminators list wouldn't be properly updated,
so the bug would reappear.

A more correct fix would be to explicitly check for initial ";" with a
multisequance.

Old version:

--------------------------------------------------------------------------------
-- Helper function for "return <expr_list>" parsing.
-- Called when parsing return statements.
--------------------------------------------------------------------------------
local return_expr_list_parser = gg.list {
      expr, separators = ",", terminators = table.copy (block_terminators) }
--------------------------------------------------------------------------------

New version:

--------------------------------------------------------------------------------
-- Helper function for "return <expr_list>" parsing.
-- Called when parsing return statements.
-- The specific test for initial ";" is because it's not a block terminator,
-- so without itgg.list would choke on "return ;" statements.
-- We don't make a modified copy of block_terminators because this list
-- is sometimes modified at runtime, and the return parser would get out of
-- sync if it was relying on a copy.
--------------------------------------------------------------------------------
local return_expr_list_parser = gg.multisequence{
   { ";" , builder = function return { } end },
   default = gg.list {
      expr, separators = ",", terminators = table.copy (block_terminators) }
}
--------------------------------------------------------------------------------


On Thu, Sep 4, 2008 at 7:47 AM, Alexander Gladysh <agladysh at gmail.com>wrote:

> On Thu, Sep 4, 2008 at 2:57 AM, Fabien Fleutot <fleutot at gmail.com> wrote:
> > I don't understand the cause of the "else return; end" issue, I'll need
> to
> > look more carefully.
>
> May you point me where to start looking, so I would try to debug it too?
>
> Alexander.
>
> _______________________________________________
> Metalua-list mailing list
> Metalua-list at lists.luaforge.net
> http://lists.luaforge.net/cgi-bin/mailman/listinfo/metalua-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.luaforge.net/pipermail/metalua-list/attachments/20080904/842a30da/attachment.html


More information about the Metalua-list mailing list