boolangery / py-lua-parser

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

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

Open bendrissou opened 10 months ago

bendrissou commented 10 months 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.