Skip to content

Parsing Error: Chained method calls in assignment incorrectly split into multiple statements #66

@K1nG11

Description

@K1nG11

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:

  1. The LocalAssign node for result only receives hmac.setBlockSize (as an Index node) as its value.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions