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

Add support for INTERFACE and IMPLEMENTS in function blocks #16

Closed klauer closed 1 year ago

klauer commented 2 years ago

https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/4262436875.html&id=

Also find a better reference for it.

TODO:

engineerjoe440 commented 1 year ago

I was beginning to look at this item, to see if I might be able to help with it. I do feel a bit confused, so I want to check my understanding. Were you intending to support INTERFACE objects specifically, almost like FUNCTION_BLOCKs, but specifically with the appropriate interface syntax (i.e., no implementation sections). I think what might make sense (at least at the top level) would be to carve out unique interface_declaration, interface_method_declaration, and interface_property_declaration to follow the similarly named FUNCTION_BLOCK items:

image

Am I following your train-of-thought here?

klauer commented 1 year ago

Yeah, sorry about the very terse "TODO"-style issue here.

It looks like I added FUNCTION_BLOCK ... IMPLEMENTS at some point in the grammar (30bda8eb), so the core of this issue is then supporting library-element-level INTERFACE declarations (just as you've laid out above). I'll tweak the original issue text.

There's a bit of investigation to do to properly implement this, I think. And pytmc needs a bit of work to parse TcIO files and dump out compatible code, too - but that shouldn't stop blark from implementing the INTERFACE declaration grammar.

These INTERFACE definitions will then be of the form:

INTERFACE I_Name [EXTENDS I_Base1, ...]
[METHOD ...]
[PROPERTY ...]
END_INTERFACE

From what I understand these can only include PROPERTY and METHOD (without implementation sections as you've noted). Here's some code examples that might be of use while coming up with the grammar:

I'm not sure if any existing parsers work on INTERFACE objects (a 5 minute glance at related projects https://github.com/klauer/blark/issues/27 indicates probably not)