Skip to content

Commit 1e27886

Browse files
committed
Added grammar support for alias types
1 parent 0bd8c74 commit 1e27886

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

src/plcdoc/interpreter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ def __init__(self, meta_model: TextXMetaClass, file=None):
289289
self._objtype = "struct"
290290
elif "Union" in type_str:
291291
self._objtype = "union"
292+
elif "Alias" in type_str:
293+
self._objtype = "alias"
292294
else:
293295
raise ValueError(f"Could not categorize type `{type_str}`")
294296

src/plcdoc/st_declaration.tx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ TypeDef:
4242
;
4343

4444
AnyType:
45-
TypeStruct | TypeUnion | TypeEnum
45+
TypeStruct | TypeUnion | TypeEnum | TypeAlias
4646
;
4747

4848
TypeStruct:
@@ -78,6 +78,13 @@ EnumOption:
7878
(comment=CommentLine)?
7979
;
8080

81+
TypeAlias:
82+
base=VariableType
83+
CommentAny*
84+
// Catch trailing comments here, not at the end of `Variable`
85+
';'
86+
;
87+
8188
/*
8289
---------------------------------------------------
8390
*/

tests/plc_code/T_ALIAS.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
TYPE T_INTERLOCK : WORD;
1+
TYPE T_INTERLOCK : WORD; END_TYPE
2+
3+
TYPE T_Message : STRING[50];
24
END_TYPE

tests/test_plc_project.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def test_project_interpret(app, status, warning):
1919
"program": ["MAIN"],
2020
"enum": ["E_Error"],
2121
"struct": ["ST_MyStruct"],
22+
"alias": ["T_ALIAS"],
2223
}
2324

2425
for objtype, objects in expected.items():

0 commit comments

Comments
 (0)