boolangery / py-lua-parser

A Lua parser and AST builder written in Python.
MIT License
124 stars 39 forks source link

Failure to reject incorrect inputs: missing function call arguments #50

Closed bendrissou closed 1 month ago

bendrissou commented 1 year ago

Hi,

The parser doesn't reject incorrect function calls.

As a short example, consider the following Lua input:

var = function(...)
    (4)
end

The parser parses and labels function call (4) as a valid statement, without raising an error!

Here is the output:

{
    "Chunk": {
        "body": {
            "Block": {
                "body": [
                    {
                        "Assign": {
                            "targets": [
                                {
                                    "Name": {
                                        "id": "var",
                                        "start_char": 0,
                                        "stop_char": 2,
                                        "line": 1
                                    }
                                }
                            ],
                            "values": [
                                {
                                    "AnonymousFunction": {
                                        "args": [
                                            {
                                                "Varargs": {
                                                    "start_char": null,
                                                    "stop_char": null,
                                                    "line": null
                                                }
                                            }
                                        ],
                                        "body": {
                                            "Block": {
                                                "body": [
                                                    {
                                                        "Number": {
                                                            "n": 4,
                                                            "start_char": 25,
                                                            "stop_char": 25,
                                                            "line": 2
                                                        }
                                                    }
                                                ],
                                                "start_char": 24,
                                                "stop_char": 30,
                                                "line": 2
                                            }
                                        },
                                        "start_char": 6,
                                        "stop_char": 30,
                                        "line": 1
                                    }
                                }
                            ],
                            "start_char": 0,
                            "stop_char": 30,
                            "line": 1
                        }
                    }
                ],
                "start_char": 0,
                "stop_char": 30,
                "line": 1
            }
        },
        "start_char": 0,
        "stop_char": 30,
        "line": 1
    }
}

In comparison to the official Lua grammar, and official Lua implementation, the input is invalid. This is because a function call should be followed by one or more arguments.

So my question is : is this behaviour intended? Or is it a parsing error?

Thank you.

boolangery commented 1 month ago

Fixed on master, will release a version soon