Skip to content

Commit 6f01bf6

Browse files
committed
change logic to allow all data types inside struct
1 parent 2ddd246 commit 6f01bf6

2 files changed

Lines changed: 5 additions & 23 deletions

File tree

ComplexParser.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,14 @@ def ParseSTFile(self, file):
6666
f"Error: {STRUCT_TOKEN} found out of {TYPE_TOKEN} block declaration."
6767
)
6868
name = f"{line.split(':')[0].strip()}"
69-
complex_vars.append((name, {}))
69+
complex_vars.append((name, []))
7070
parsing = True
7171
continue
7272
elif f"END_{STRUCT_TOKEN}" in line:
7373
parsing = False
7474
continue
7575
elif parsing:
76-
splitted_line = line.replace(":=", ":").split(":")
77-
if len(splitted_line) == 3:
78-
# Handle complex variable with type and initial value
79-
name, type, value = (
80-
splitted_line[0].strip(),
81-
splitted_line[1].strip(),
82-
splitted_line[2].replace(";", "").strip(),
83-
)
84-
complex_vars[-1][1][name] = {"type": type, "value": value}
85-
continue
86-
name, type = (
87-
splitted_line[0].strip(),
88-
splitted_line[1].replace(";", "").strip(),
89-
)
90-
complex_vars[-1][1][name] = {"type": type, "value": None}
76+
complex_vars[-1][1].append(line)
9177
continue
9278
# Remove type block if empty
9379
elif f"END_{TYPE_TOKEN}" in line:
@@ -96,7 +82,7 @@ def ParseSTFile(self, file):
9682
new_lines.pop()
9783
continue
9884
# Skip consecutive empty lines
99-
elif not l.strip() and not (new_lines and new_lines[-1].strip()):
85+
elif not line and not (new_lines and new_lines[-1].strip()):
10086
continue
10187

10288
new_lines.append(l)

templates/function_block.st.j2

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
FUNCTION_BLOCK {{name}}
22
VAR_INPUT
3-
{%-for k,v in vars.items()%}
4-
{%- if v.value is not none %}
5-
{{k}} : {{v.type}} := {{v.value}};
6-
{%- else %}
7-
{{k}} : {{v.type}};
8-
{%- endif %}
3+
{%-for line in vars%}
4+
{{line}}
95
{%- endfor %}
106
END_VAR
117
VAR

0 commit comments

Comments
 (0)