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

Problem when there are consecutive function calls on the right side of the assignment statement

Open Dongyang0810 opened this issue 5 months ago • 9 comments

local a = GetClass(data).OtherFunc(self, ohterData) GetClass is a function that returns an object with a member function OtherFunc. GetClass(data).OtherFunc(self, otherData) should be parsed as a tree structure where the root node is a function call, and the child node is also a function call.

The parsing result of GetClass(data).OtherFunc(self, ohterData) when parsing in a single line is inconsistent with the parsing result when placed on the right side of the assignment statement.

local a = GetClass(data).OtherFunc(self, ohterData)
GetClass(data).OtherFunc(self, ohterData)

image

How can I resolve this issue?

Dongyang0810 avatar Jan 11 '24 08:01 Dongyang0810

Please clarify the grammar you are talking about.

KvanTTT avatar Jan 11 '24 12:01 KvanTTT

Got it, I've seen Lua on the image.

KvanTTT avatar Jan 11 '24 12:01 KvanTTT

Instead of:

prefixexp
    : NAME ('[' exp ']' | '.' NAME)*
    | functioncall ('[' exp ']' | '.' NAME)*
    | '(' exp ')' ('[' exp ']' | '.' NAME)*
    ;

try this:

prefixexp
    : functioncall ('[' exp ']' | '.' NAME)*
    | NAME ('[' exp ']' | '.' NAME)*
    | '(' exp ')' ('[' exp ']' | '.' NAME)*
    ;

bkiers avatar Jan 11 '24 17:01 bkiers

This seems to be an exact duplicate of https://github.com/antlr/grammars-v4/issues/3885

bkiers avatar Jan 11 '24 17:01 bkiers

This seems to be an exact duplicate of https://github.com/antlr/grammars-v4/issues/3885

yes,I saw the question after I asked it.

Dongyang0810 avatar Jan 12 '24 01:01 Dongyang0810

Instead of:

prefixexp
    : NAME ('[' exp ']' | '.' NAME)*
    | functioncall ('[' exp ']' | '.' NAME)*
    | '(' exp ')' ('[' exp ']' | '.' NAME)*
    ;

try this:

prefixexp
    : functioncall ('[' exp ']' | '.' NAME)*
    | NAME ('[' exp ']' | '.' NAME)*
    | '(' exp ')' ('[' exp ']' | '.' NAME)*
    ;

Yes, I have reordered the syntax rules like this, but I saw kaby76's comment: https://github.com/antlr/grammars-v4/issues/3885#issuecomment-1852090676, so this issue might require a different solution.

Dongyang0810 avatar Jan 12 '24 01:01 Dongyang0810

Yes, I have reordered the syntax rules like this, but I saw kaby76's comment: #3885 (comment), so this issue might require a different solution.

Of course, I may be wrong! Reordering may fix your problem, but I think the problem is that it doesn't solve the reported ambiguity.

kaby76 avatar Jan 14 '24 14:01 kaby76

Yes, I have reordered the syntax rules like this, but I saw kaby76's comment: #3885 (comment), so this issue might require a different solution.

Of course, I may be wrong! Reordering may fix your problem, but I think the problem is that it doesn't solve the reported ambiguity.

Is there a plan to fix this issue?

Dongyang0810 avatar Jan 16 '24 01:01 Dongyang0810

... Is there a plan to fix this issue?

Feel free to submit a PR including some tests to validate it 😄

bkiers avatar Jan 16 '24 06:01 bkiers