Skip to content

Commit f319054

Browse files
committed
Added grammar support to enum defaults
1 parent bf8f383 commit f319054

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/plcdoc/st_declaration.tx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ TypeEnum:
6767
CommentAny*
6868
')'
6969
(base_type=Fqn)?
70+
(default=EnumDefault)?
7071
';'
7172
;
7273

@@ -78,6 +79,12 @@ EnumOption:
7879
(comment=CommentLine)?
7980
;
8081

82+
EnumDefault:
83+
':='
84+
option=ID
85+
// Enum default must be a literal field, it cannot be e.g. an integer
86+
;
87+
8188
TypeAlias:
8289
base=VariableType
8390
CommentAny*

tests/plc_code/E_Filter.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ TYPE E_Filter :
1414
Filter697nm := 6 // Note: non-consecutive number!
1515
) USINT; // Specify base type so API is explicit
1616
END_TYPE
17+
18+
TYPE E_FilterDefault :
19+
(
20+
NoFilter := 0,
21+
Filter434nm,
22+
Filter697nm
23+
) USINT := NoFilter;
24+
END_TYPE

tests/plc_code/E_Options.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
TYPE E_Options :
22
(
3-
Default := 0,
3+
Default := 0,
44
Option1,
55
Option2
66
);
77
END_TYPE
8+
9+
TYPE E_OptionsDefault :
10+
(
11+
Default := 0,
12+
Option1,
13+
Option2
14+
) := DEFAULT;
15+
END_TYPE

0 commit comments

Comments
 (0)