klauer / blark

Beckhoff TwinCAT ST (IEC 61131-3) code parsing in Python using Lark (Earley)
https://klauer.github.io/blark/
GNU General Public License v2.0
42 stars 5 forks source link

Array of Pointer to Structure using Addresses Dereferencing by Index Failing to Parse #69

Closed engineerjoe440 closed 1 year ago

engineerjoe440 commented 1 year ago

Ok, so I think this one is much simpler than the title may suggest, but it's the use-case I found this issue with, so I'm going to run with its full complexity for the sake of testing. Here's a snippet that seems to fail:

FUNCTION_BLOCK class_SomethingCool
VAR
        currentChannel : ARRAY[1..g_c_someConstant] OF POINTER TO struct_groupData :=
                [       ADR(_object[1].someValue),
                        ADR(_object[2].someValue),
                        ADR(_object[3].someValue),
                        ADR(_object[4].someValue),
                        ADR(_object[5].someValue),
                        ADR(_object[6].someValue),
                        ADR(_object[7].someValue),
                        ADR(_object[8].someValue),
                        ADR(_object[9].someValue),
                        ADR(_object[10].someValue)
                ];
END_VAR
END_FUNCTION_BLOCK

With the following pytest exception (shortened significantly):

E           lark.exceptions.UnexpectedCharacters: No terminal matches '[' in the current parser context, at line 4 col 36
E
E                           [       ADR(_object[1].someValue),
E                                              ^
E           Expected one of: 
E               * HASH
E               * LPAR
E               * COMMA
E               * RPAR
E               * ASSIGNMENT

C:\Python311\Lib\site-packages\lark\parsers\xearley.py:119: UnexpectedCharacters

Development branch is here: https://github.com/engineerjoe440/blark/tree/bugfix/advanced-array-development Clearly, I've added a simple sanity-check test, but haven't completed a fix, yet. May not have a chance until later this week at the earliest.

engineerjoe440 commented 1 year ago

Just updated the (above-linked) branch with other relevant fixes related to #70.