Skip to content

Commit

Permalink
Added grammar support to enum defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoRoos committed Nov 28, 2024
1 parent 1e27886 commit f240279
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/plcdoc/st_declaration.tx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ TypeEnum:
CommentAny*
')'
(base_type=Fqn)?
(default=EnumDefault)?
';'
;

Expand All @@ -78,6 +79,12 @@ EnumOption:
(comment=CommentLine)?
;

EnumDefault:
':='
option=ID
// Enum default must be a literal field, it cannot be e.g. an integer
;

TypeAlias:
base=VariableType
CommentAny*
Expand Down
8 changes: 8 additions & 0 deletions tests/plc_code/E_Filter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ TYPE E_Filter :
Filter697nm := 6 // Note: non-consecutive number!
) USINT; // Specify base type so API is explicit
END_TYPE

TYPE E_FilterDefault :
(
NoFilter := 0,
Filter434nm,
Filter697nm
) USINT := NoFilter;
END_TYPE
10 changes: 9 additions & 1 deletion tests/plc_code/E_Options.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
TYPE E_Options :
(
Default := 0,
Default := 0,
Option1,
Option2
);
END_TYPE

TYPE E_OptionsDefault :
(
Default := 0,
Option1,
Option2
) := DEFAULT;
END_TYPE

0 comments on commit f240279

Please sign in to comment.