grammars-v4 icon indicating copy to clipboard operation
grammars-v4 copied to clipboard

Lua Grammar seems off, does not parse Pound / # / Length operator properly?

Open N0K0 opened this issue 9 months ago • 1 comments

Hey, I'm relatively new to Antlr so sorry if this is intended to be fixed downstream by implementers of the parser. Running the Lua grammar i hit a undefined token

http://lab.antlr.org/

https://github.com/antlr/grammars-v4/blob/master/lua/LuaLexer.g4 https://github.com/antlr/grammars-v4/blob/master/lua/LuaParser.g4

start rule: start_

Sample:

local a, b
a = "test"
b = #a

return b

Error message

5:0 extraneous input 'return' expecting {'function', 'nil', 'false', 'true', '~', '-', '#', '(', 'not', '{', '...', NAME, NORMALSTRING, CHARSTRING, LONGSTRING, INT, HEX, FLOAT, HEX_FLOAT}

Image

The python lua parser has fixed it in the builder for example: https://github.com/boolangery/py-lua-parser/blob/master/luaparser/builder.py#L393

N0K0 avatar Mar 02 '25 09:03 N0K0

lab.antlr.org cannot be used with lua because it contains Antlr "actions". https://github.com/antlr/grammars-v4/blob/a9c0af477e3047be24abf525043db4e3b71d5f08/lua/LuaLexer.g4#L123 It should not even offer the list of grammars UI because lab.antlr.org uses grammars.json, which is constructed to weed out grammars that have actions.

kaby76 avatar Mar 02 '25 11:03 kaby76