-
Notifications
You must be signed in to change notification settings - Fork 48
Description
Bug Description:
The Lua parser incorrectly parses chained method calls when they appear on the right-hand side (RHS) of an assignment statement. Instead of creating a single Abstract Syntax Tree (AST) node representing the entire chained call as the value of the assignment, the parser prematurely terminates the expression.
Specifically, for a statement like:
local result = hmac.setBlockSize(v.blockSize).setDigest(v.digest).setKey(v.key).init().update(v.message).finish().asHex();
The current parser behavior results in an AST where:
- The
LocalAssign
node forresult
only receiveshmac.setBlockSize
(as anIndex
node) as its value. - The arguments for the initial call (e.g.,
(v.blockSize)
) and all subsequent chained calls (e.g.,.setDigest(v.digest)...
) are detached and incorrectly parsed as a new, separate statement. This subsequent statement itself is often malformed, for instance, treating the arguments of the first call as the object for the second call in the chain.
This misparsing leads to an incorrect AST structure, and consequently, any code regenerated from this AST will be syntactically incorrect and different from the original source code. The root cause appears to be in the ANTLR grammar (LuaParser.g4
) definitions for expressions (exp
), prefix expressions (prefixexp
), and function calls (functioncall
), where the parser does not correctly prioritize or consume the full function call chain as a single expression unit within the explist
of an assignment.