stevenjohnstone / lua-grammar

ANTLRv4 lexer and parser grammars for Lua
1 stars 0 forks source link

Problems detecting some function calls #1

Closed britzl closed 3 years ago

britzl commented 3 years ago

I've found two instances where the grammar is incorrect and doesn't detect function calls properly. The first scenario doesn't detect the function call at all:

local a = foo().bar

The second scenario includes too much in the function call:

foo("bar")

"hello"

This gets detected as foo("bar", "hello") as can be seen here:

Also discussed here: https://github.com/antlr/grammars-v4/issues/1824#issuecomment-765591643

stevenjohnstone commented 3 years ago

HI @britzl . I've started some work on this in https://github.com/stevenjohnstone/lua-grammar/commit/7b4bad968d57e28c62bfe5deac6a4610a6a46594.

Which language are you targeting? Do you have any example code so I can indicate how it'd need to be changed to accommodate the grammar changes?

britzl commented 3 years ago

I'm working on the Defold game engine (www.defold.com) which uses LuaJIT/Lua 5.1 for game logic scripting. We're going to use Antlr and the Lua grammar to parse all game logic and strip comments, identify all require()'d Lua modules and find use of a couple of game engine specific APIs. We used to have a bunch of regular expressions to do these tasks but it has always been pretty brittle and prone to miss things or include things that should have been excluded.

britzl commented 3 years ago

Oh, and we plan to use the Java runtime for Antlr (currently antlr-runtime-4.9.1.jar).

stevenjohnstone commented 3 years ago

Hi @britzl! Could you take a look at https://github.com/stevenjohnstone/lua-grammar/commit/afcca492e7ea2203ade5b4d374f4128b33d0981f to see if my changes make sense for your use case?

stevenjohnstone commented 3 years ago

Fixed by by https://github.com/stevenjohnstone/lua-grammar/pull/2.

britzl commented 3 years ago

Thanks! I'm going to give this a try now!

britzl commented 3 years ago

I can confirm that your changes solved the problems I had. Thanks Steven!