diff --git a/src/plcdoc/st_declaration.tx b/src/plcdoc/st_declaration.tx index 6a7ef3f..7b4a5a1 100644 --- a/src/plcdoc/st_declaration.tx +++ b/src/plcdoc/st_declaration.tx @@ -67,6 +67,7 @@ TypeEnum: CommentAny* ')' (base_type=Fqn)? + (default=EnumDefault)? ';' ; @@ -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* diff --git a/tests/plc_code/E_Filter.txt b/tests/plc_code/E_Filter.txt index 1090563..80843db 100644 --- a/tests/plc_code/E_Filter.txt +++ b/tests/plc_code/E_Filter.txt @@ -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 diff --git a/tests/plc_code/E_Options.txt b/tests/plc_code/E_Options.txt index cb9ff7f..5927810 100644 --- a/tests/plc_code/E_Options.txt +++ b/tests/plc_code/E_Options.txt @@ -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