Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Grammar to Support Enumeration Default Values Defined by Functions #104

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions blark/iec.lark
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,11 @@ enumerated_spec_init: [ indirection_type ] enumerated_specification [ ":=" enume
enumerated_specification: "(" enumerated_value ( "," enumerated_value )* ")" [ ENUM_DATA_TYPE_NAME ]
| enumerated_type_name

enumerated_value: [ enumerated_type_name "#" ] DOTTED_IDENTIFIER [ ":=" integer_or_constant ]
enumerated_value: [ enumerated_type_name "#" ] DOTTED_IDENTIFIER [ ":=" integer_constant_or_func ]

?integer_or_constant: integer_literal
| DOTTED_IDENTIFIER
?integer_constant_or_func: integer_literal
| function_call
| DOTTED_IDENTIFIER

// The following is a Beckhoff extensions of the IEC61131-3 standard
// https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/2529504395.html
Expand Down
9 changes: 9 additions & 0 deletions blark/tests/source/enum_with_function_calls.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{attribute 'qualified_only'}
{attribute 'to_string'}
TYPE color :
(
off := ANY_TO_DINT(someColor.off),
red := ANY_TO_DINT(someColor.red),
green := ANY_TO_DINT(someColor.green)
) DINT;
END_TYPE
2 changes: 1 addition & 1 deletion blark/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ class EnumeratedValue:
# TODO: coverage?
type_name: Optional[lark.Token]
name: lark.Token
value: Optional[Union[Integer, lark.Token]]
value: Optional[Union[Integer, FunctionCall, lark.Token]]
meta: Optional[Meta] = meta_field()

def __str__(self) -> str:
Expand Down