Skip to content

INCORRECT handling of () parens and ; semicolon #88

@cohler

Description

@cohler

These are two major BUGS that make luamin produced code incorrect. Given that these are very commonly used syntactical elements, this needs to be fixed promptly.

  1. In LUA if you put parens around a function call that returns a list of values, it means extract only the first return from the list. BUT luamin simply removes the parens as superfluous, thereby changing/breaking the code. As it states in the LUA manual:

"Any expression enclosed in parentheses always results in only one value. Thus, (f(x,y,z)) is always a single value, even if f returns several values. (The value of (f(x,y,z)) is the first value returned by f or nil if f does not return any values.)"

  1. luamin removes syntactically significant semicolons such as those described in the LUA manual here:

Lua has empty statements that allow you to separate statements with semicolons, start a block with a semicolon or write two semicolons in sequence:

stat ::= ‘;’

Function calls and assignments can start with an open parenthesis. This possibility leads to an ambiguity in Lua's grammar. Consider the following fragment:

 a = b + c
 (print or io.write)('done')

The grammar could see it in two ways:

 a = b + c(print or io.write)('done')
 
 a = b + c; (print or io.write)('done')

The current parser always sees such constructions in the first way, interpreting the open parenthesis as the start of the arguments to a call. To avoid this ambiguity, it is a good practice to always precede with a semicolon statements that start with a parenthesis:

 ;(print or io.write)('done')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions