author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Mon, 14 Aug 2017 22:30:41 +0300 | |
changeset 1735 | c02818d7e29f |
parent 1734 | 750eeb7230a1 |
child 1736 | 7e61baa047f0 |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
6 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
8 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
10 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
15 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
19 |
# GNU General Public License for more details. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
20 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1390
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
1732
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
25 |
import string |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
26 |
import re |
1313
85c167bfff93
Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents:
1310
diff
changeset
|
27 |
from plcopen import LoadProject |
1320
bb04c41cbee9
Used OrderedDict for keeping of standard function blocks library defined
Laurent Bessard
parents:
1313
diff
changeset
|
28 |
from collections import OrderedDict |
1390 | 29 |
from definitions import * |
30 |
||
31 |
TypeHierarchy = dict(TypeHierarchy_list) |
|
32 |
||
33 |
""" |
|
34 |
returns true if the given data type is the same that "reference" meta-type or one of its types. |
|
35 |
""" |
|
36 |
def IsOfType(type, reference): |
|
37 |
if reference is None: |
|
38 |
return True |
|
39 |
elif type == reference: |
|
40 |
return True |
|
41 |
else: |
|
42 |
parent_type = TypeHierarchy[type] |
|
43 |
if parent_type is not None: |
|
44 |
return IsOfType(parent_type, reference) |
|
45 |
return False |
|
46 |
||
47 |
""" |
|
48 |
returns list of all types that correspont to the ANY* meta type |
|
49 |
""" |
|
50 |
def GetSubTypes(type): |
|
51 |
return [typename for typename, parenttype in TypeHierarchy.items() if not typename.startswith("ANY") and IsOfType(typename, type)] |
|
52 |
||
53 |
DataTypeRange = dict(DataTypeRange_list) |
|
54 |
||
55 |
""" |
|
56 |
Ordered list of common Function Blocks defined in the IEC 61131-3 |
|
814 | 57 |
Each block have this attributes: |
58 |
- "name" : The block name |
|
59 |
- "type" : The block type. It can be "function", "functionBlock" or "program" |
|
60 |
- "extensible" : Boolean that define if the block is extensible |
|
61 |
- "inputs" : List of the block inputs |
|
62 |
- "outputs" : List of the block outputs |
|
63 |
- "comment" : Comment that will be displayed in the block popup |
|
64 |
- "generate" : Method that generator will call for generating ST block code |
|
65 |
Inputs and outputs are a tuple of characteristics that are in order: |
|
66 |
- The name |
|
67 |
- The data type |
|
68 |
- The default modifier which can be "none", "negated", "rising" or "falling" |
|
69 |
""" |
|
70 |
||
1390 | 71 |
StdBlckLibs = {libname : LoadProject(tc6fname)[0] |
72 |
for libname, tc6fname in StdTC6Libs} |
|
73 |
StdBlckLst = [{"name" : libname, "list": |
|
74 |
[GetBlockInfos(pous) for pous in lib.getpous()]} |
|
75 |
for libname, lib in StdBlckLibs.iteritems()] |
|
814 | 76 |
|
77 |
#------------------------------------------------------------------------------- |
|
78 |
# Test identifier |
|
79 |
#------------------------------------------------------------------------------- |
|
80 |
||
965 | 81 |
IDENTIFIER_MODEL = re.compile( |
82 |
"(?:%(letter)s|_(?:%(letter)s|%(digit)s))(?:_?(?:%(letter)s|%(digit)s))*$" % |
|
83 |
{"letter": "[a-zA-Z]", "digit": "[0-9]"}) |
|
814 | 84 |
|
85 |
# Test if identifier is valid |
|
86 |
def TestIdentifier(identifier): |
|
965 | 87 |
return IDENTIFIER_MODEL.match(identifier) is not None |
814 | 88 |
|
89 |
#------------------------------------------------------------------------------- |
|
90 |
# Standard functions list generation |
|
91 |
#------------------------------------------------------------------------------- |
|
92 |
||
93 |
||
94 |
""" |
|
95 |
take a .csv file and translate it it a "csv_table" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
96 |
""" |
814 | 97 |
def csv_file_to_table(file): |
98 |
return [ map(string.strip,line.split(';')) for line in file.xreadlines()] |
|
99 |
||
100 |
""" |
|
101 |
seek into the csv table to a section ( section_name match 1st field ) |
|
102 |
return the matching row without first field |
|
103 |
""" |
|
104 |
def find_section(section_name, table): |
|
105 |
fields = [None] |
|
106 |
while(fields[0] != section_name): |
|
107 |
fields = table.pop(0) |
|
108 |
return fields[1:] |
|
109 |
||
110 |
""" |
|
111 |
extract the standard functions standard parameter names and types... |
|
112 |
return a { ParameterName: Type, ...} |
|
113 |
""" |
|
114 |
def get_standard_funtions_input_variables(table): |
|
115 |
variables = find_section("Standard_functions_variables_types", table) |
|
116 |
standard_funtions_input_variables = {} |
|
117 |
fields = [True,True] |
|
118 |
while(fields[1]): |
|
119 |
fields = table.pop(0) |
|
120 |
variable_from_csv = dict([(champ, val) for champ, val in zip(variables, fields[1:]) if champ!='']) |
|
121 |
standard_funtions_input_variables[variable_from_csv['name']] = variable_from_csv['type'] |
|
122 |
return standard_funtions_input_variables |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
123 |
|
814 | 124 |
""" |
125 |
translate .csv file input declaration into PLCOpenEditor interessting values |
|
126 |
in : "(ANY_NUM, ANY_NUM)" and { ParameterName: Type, ...} |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
127 |
return [("IN1","ANY_NUM","none"),("IN2","ANY_NUM","none")] |
814 | 128 |
""" |
129 |
def csv_input_translate(str_decl, variables, base): |
|
130 |
decl = str_decl.replace('(','').replace(')','').replace(' ','').split(',') |
|
131 |
params = [] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
132 |
|
814 | 133 |
len_of_not_predifined_variable = len([True for param_type in decl if param_type not in variables]) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
134 |
|
814 | 135 |
for param_type in decl: |
136 |
if param_type in variables.keys(): |
|
137 |
param_name = param_type |
|
138 |
param_type = variables[param_type] |
|
139 |
elif len_of_not_predifined_variable > 1: |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
140 |
param_name = "IN%d" % base |
814 | 141 |
base += 1 |
142 |
else: |
|
143 |
param_name = "IN" |
|
144 |
params.append((param_name, param_type, "none")) |
|
145 |
return params |
|
146 |
||
147 |
||
148 |
""" |
|
149 |
Returns this kind of declaration for all standard functions |
|
150 |
||
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
151 |
[{"name" : "Numerical", 'list': [ { |
814 | 152 |
'baseinputnumber': 1, |
153 |
'comment': 'Addition', |
|
154 |
'extensible': True, |
|
155 |
'inputs': [ ('IN1', 'ANY_NUM', 'none'), |
|
156 |
('IN2', 'ANY_NUM', 'none')], |
|
157 |
'name': 'ADD', |
|
158 |
'outputs': [('OUT', 'ANY_NUM', 'none')], |
|
159 |
'type': 'function'}, ...... ] },.....] |
|
160 |
""" |
|
161 |
def get_standard_funtions(table): |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
162 |
|
814 | 163 |
variables = get_standard_funtions_input_variables(table) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
164 |
|
814 | 165 |
fonctions = find_section("Standard_functions_type",table) |
166 |
||
167 |
Standard_Functions_Decl = [] |
|
168 |
Current_section = None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
169 |
|
814 | 170 |
translate = { |
171 |
"extensible" : lambda x: {"yes":True, "no":False}[x], |
|
172 |
"inputs" : lambda x:csv_input_translate(x,variables,baseinputnumber), |
|
173 |
"outputs":lambda x:[("OUT",x,"none")]} |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
174 |
|
814 | 175 |
for fields in table: |
176 |
if fields[1]: |
|
177 |
# If function section name given |
|
178 |
if fields[0]: |
|
179 |
words = fields[0].split('"') |
|
180 |
if len(words) > 1: |
|
181 |
section_name = words[1] |
|
182 |
else: |
|
183 |
section_name = fields[0] |
|
184 |
Current_section = {"name" : section_name, "list" : []} |
|
185 |
Standard_Functions_Decl.append(Current_section) |
|
186 |
Function_decl_list = [] |
|
187 |
if Current_section: |
|
188 |
Function_decl = dict([(champ, val) for champ, val in zip(fonctions, fields[1:]) if champ]) |
|
189 |
baseinputnumber = int(Function_decl.get("baseinputnumber",1)) |
|
190 |
Function_decl["baseinputnumber"] = baseinputnumber |
|
191 |
for param, value in Function_decl.iteritems(): |
|
192 |
if param in translate: |
|
193 |
Function_decl[param] = translate[param](value) |
|
194 |
Function_decl["type"] = "function" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
195 |
|
814 | 196 |
if Function_decl["name"].startswith('*') or Function_decl["name"].endswith('*') : |
197 |
input_ovrloading_types = GetSubTypes(Function_decl["inputs"][0][1]) |
|
198 |
output_types = GetSubTypes(Function_decl["outputs"][0][1]) |
|
199 |
else: |
|
200 |
input_ovrloading_types = [None] |
|
201 |
output_types = [None] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
202 |
|
814 | 203 |
funcdeclname_orig = Function_decl["name"] |
204 |
funcdeclname = Function_decl["name"].strip('*_') |
|
205 |
fdc = Function_decl["inputs"][:] |
|
206 |
for intype in input_ovrloading_types: |
|
207 |
if intype != None: |
|
208 |
Function_decl["inputs"] = [] |
|
209 |
for decl_tpl in fdc: |
|
210 |
if IsOfType(intype, decl_tpl[1]): |
|
211 |
Function_decl["inputs"] += [(decl_tpl[0], intype, decl_tpl[2])] |
|
212 |
else: |
|
213 |
Function_decl["inputs"] += [(decl_tpl)] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
214 |
|
814 | 215 |
if funcdeclname_orig.startswith('*'): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
216 |
funcdeclin = intype + '_' + funcdeclname |
814 | 217 |
else: |
218 |
funcdeclin = funcdeclname |
|
219 |
else: |
|
220 |
funcdeclin = funcdeclname |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
221 |
|
814 | 222 |
for outype in output_types: |
223 |
if outype != None: |
|
224 |
decl_tpl = Function_decl["outputs"][0] |
|
225 |
Function_decl["outputs"] = [ (decl_tpl[0] , outype, decl_tpl[2])] |
|
226 |
if funcdeclname_orig.endswith('*'): |
|
227 |
funcdeclout = funcdeclin + '_' + outype |
|
228 |
else: |
|
229 |
funcdeclout = funcdeclin |
|
230 |
else: |
|
231 |
funcdeclout = funcdeclin |
|
232 |
Function_decl["name"] = funcdeclout |
|
233 |
||
1390 | 234 |
# apply filter given in "filter" column |
235 |
filter_name = Function_decl["filter"] |
|
236 |
store = True |
|
237 |
for (InTypes, OutTypes) in ANY_TO_ANY_FILTERS.get(filter_name,[]): |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
238 |
outs = reduce(lambda a,b: a or b, |
1390 | 239 |
map(lambda testtype : IsOfType( |
240 |
Function_decl["outputs"][0][1], |
|
241 |
testtype), OutTypes)) |
|
242 |
inps = reduce(lambda a,b: a or b, |
|
243 |
map(lambda testtype : IsOfType( |
|
244 |
Function_decl["inputs"][0][1], |
|
245 |
testtype), InTypes)) |
|
246 |
if inps and outs and Function_decl["outputs"][0][1] != Function_decl["inputs"][0][1]: |
|
247 |
store = True |
|
248 |
break |
|
249 |
else: |
|
250 |
store = False |
|
251 |
if store : |
|
814 | 252 |
# create the copy of decl dict to be appended to section |
253 |
Function_decl_copy = Function_decl.copy() |
|
254 |
Current_section["list"].append(Function_decl_copy) |
|
255 |
else: |
|
256 |
raise "First function must be in a category" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
257 |
|
814 | 258 |
return Standard_Functions_Decl |
259 |
||
1390 | 260 |
StdBlckLst.extend(get_standard_funtions(csv_file_to_table(open(StdFuncsCSV)))) |
1283
f3cfe1ff917e
More optimization attemps in type handling
Edouard Tisserant
parents:
1239
diff
changeset
|
261 |
|
f3cfe1ff917e
More optimization attemps in type handling
Edouard Tisserant
parents:
1239
diff
changeset
|
262 |
# Dictionary to speedup block type fetching by name |
1320
bb04c41cbee9
Used OrderedDict for keeping of standard function blocks library defined
Laurent Bessard
parents:
1313
diff
changeset
|
263 |
StdBlckDct = OrderedDict() |
1283
f3cfe1ff917e
More optimization attemps in type handling
Edouard Tisserant
parents:
1239
diff
changeset
|
264 |
|
f3cfe1ff917e
More optimization attemps in type handling
Edouard Tisserant
parents:
1239
diff
changeset
|
265 |
for section in StdBlckLst: |
814 | 266 |
for desc in section["list"]: |
267 |
words = desc["comment"].split('"') |
|
268 |
if len(words) > 1: |
|
269 |
desc["comment"] = words[1] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
270 |
desc["usage"] = ("\n (%s) => (%s)" % |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
271 |
(", ".join(["%s:%s" % (input[1], input[0]) |
1313
85c167bfff93
Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents:
1310
diff
changeset
|
272 |
for input in desc["inputs"]]), |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
273 |
", ".join(["%s:%s" % (output[1], output[0]) |
1313
85c167bfff93
Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents:
1310
diff
changeset
|
274 |
for output in desc["outputs"]]))) |
1283
f3cfe1ff917e
More optimization attemps in type handling
Edouard Tisserant
parents:
1239
diff
changeset
|
275 |
BlkLst = StdBlckDct.setdefault(desc["name"],[]) |
f3cfe1ff917e
More optimization attemps in type handling
Edouard Tisserant
parents:
1239
diff
changeset
|
276 |
BlkLst.append((section["name"], desc)) |
814 | 277 |
|
278 |
#------------------------------------------------------------------------------- |
|
279 |
# Languages Keywords |
|
280 |
#------------------------------------------------------------------------------- |
|
281 |
||
282 |
# Keywords for Pou Declaration |
|
283 |
POU_BLOCK_START_KEYWORDS = ["FUNCTION", "FUNCTION_BLOCK", "PROGRAM"] |
|
284 |
POU_BLOCK_END_KEYWORDS = ["END_FUNCTION", "END_FUNCTION_BLOCK", "END_PROGRAM"] |
|
285 |
POU_KEYWORDS = ["EN", "ENO", "F_EDGE", "R_EDGE"] + POU_BLOCK_START_KEYWORDS + POU_BLOCK_END_KEYWORDS |
|
1283
f3cfe1ff917e
More optimization attemps in type handling
Edouard Tisserant
parents:
1239
diff
changeset
|
286 |
for category in StdBlckLst: |
814 | 287 |
for block in category["list"]: |
288 |
if block["name"] not in POU_KEYWORDS: |
|
289 |
POU_KEYWORDS.append(block["name"]) |
|
290 |
||
291 |
||
292 |
# Keywords for Type Declaration |
|
293 |
TYPE_BLOCK_START_KEYWORDS = ["TYPE", "STRUCT"] |
|
294 |
TYPE_BLOCK_END_KEYWORDS = ["END_TYPE", "END_STRUCT"] |
|
295 |
TYPE_KEYWORDS = ["ARRAY", "OF", "T", "D", "TIME_OF_DAY", "DATE_AND_TIME"] + TYPE_BLOCK_START_KEYWORDS + TYPE_BLOCK_END_KEYWORDS |
|
296 |
TYPE_KEYWORDS.extend([keyword for keyword in TypeHierarchy.keys() if keyword not in TYPE_KEYWORDS]) |
|
297 |
||
298 |
||
299 |
# Keywords for Variable Declaration |
|
300 |
VAR_BLOCK_START_KEYWORDS = ["VAR", "VAR_INPUT", "VAR_OUTPUT", "VAR_IN_OUT", "VAR_TEMP", "VAR_EXTERNAL"] |
|
301 |
VAR_BLOCK_END_KEYWORDS = ["END_VAR"] |
|
302 |
VAR_KEYWORDS = ["AT", "CONSTANT", "RETAIN", "NON_RETAIN"] + VAR_BLOCK_START_KEYWORDS + VAR_BLOCK_END_KEYWORDS |
|
303 |
||
304 |
||
305 |
# Keywords for Configuration Declaration |
|
306 |
CONFIG_BLOCK_START_KEYWORDS = ["CONFIGURATION", "RESOURCE", "VAR_ACCESS", "VAR_CONFIG", "VAR_GLOBAL"] |
|
307 |
CONFIG_BLOCK_END_KEYWORDS = ["END_CONFIGURATION", "END_RESOURCE", "END_VAR"] |
|
308 |
CONFIG_KEYWORDS = ["ON", "PROGRAM", "WITH", "READ_ONLY", "READ_WRITE", "TASK"] + CONFIG_BLOCK_START_KEYWORDS + CONFIG_BLOCK_END_KEYWORDS |
|
309 |
||
310 |
# Keywords for Structured Function Chart |
|
311 |
SFC_BLOCK_START_KEYWORDS = ["ACTION", "INITIAL_STEP", "STEP", "TRANSITION"] |
|
312 |
SFC_BLOCK_END_KEYWORDS = ["END_ACTION", "END_STEP", "END_TRANSITION"] |
|
949 | 313 |
SFC_KEYWORDS = ["FROM", "TO"] + SFC_BLOCK_START_KEYWORDS + SFC_BLOCK_END_KEYWORDS |
814 | 314 |
|
315 |
||
316 |
# Keywords for Instruction List |
|
317 |
IL_KEYWORDS = ["TRUE", "FALSE", "LD", "LDN", "ST", "STN", "S", "R", "AND", "ANDN", "OR", "ORN", |
|
318 |
"XOR", "XORN", "NOT", "ADD", "SUB", "MUL", "DIV", "MOD", "GT", "GE", "EQ", "NE", |
|
319 |
"LE", "LT", "JMP", "JMPC", "JMPCN", "CAL", "CALC", "CALCN", "RET", "RETC", "RETCN"] |
|
320 |
||
321 |
||
322 |
# Keywords for Structured Text |
|
323 |
ST_BLOCK_START_KEYWORDS = ["IF", "ELSIF", "ELSE", "CASE", "FOR", "WHILE", "REPEAT"] |
|
324 |
ST_BLOCK_END_KEYWORDS = ["END_IF", "END_CASE", "END_FOR", "END_WHILE", "END_REPEAT"] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
325 |
ST_KEYWORDS = ["TRUE", "FALSE", "THEN", "OF", "TO", "BY", "DO", "DO", "UNTIL", "EXIT", |
814 | 326 |
"RETURN", "NOT", "MOD", "AND", "XOR", "OR"] + ST_BLOCK_START_KEYWORDS + ST_BLOCK_END_KEYWORDS |
327 |
||
328 |
# All the keywords of IEC |
|
329 |
IEC_BLOCK_START_KEYWORDS = [] |
|
330 |
IEC_BLOCK_END_KEYWORDS = [] |
|
331 |
IEC_KEYWORDS = ["E", "TRUE", "FALSE"] |
|
332 |
for all_keywords, keywords_list in [(IEC_BLOCK_START_KEYWORDS, [POU_BLOCK_START_KEYWORDS, TYPE_BLOCK_START_KEYWORDS, |
|
333 |
VAR_BLOCK_START_KEYWORDS, CONFIG_BLOCK_START_KEYWORDS, |
|
334 |
SFC_BLOCK_START_KEYWORDS, ST_BLOCK_START_KEYWORDS]), |
|
335 |
(IEC_BLOCK_END_KEYWORDS, [POU_BLOCK_END_KEYWORDS, TYPE_BLOCK_END_KEYWORDS, |
|
336 |
VAR_BLOCK_END_KEYWORDS, CONFIG_BLOCK_END_KEYWORDS, |
|
337 |
SFC_BLOCK_END_KEYWORDS, ST_BLOCK_END_KEYWORDS]), |
|
338 |
(IEC_KEYWORDS, [POU_KEYWORDS, TYPE_KEYWORDS, VAR_KEYWORDS, CONFIG_KEYWORDS, |
|
339 |
SFC_KEYWORDS, IL_KEYWORDS, ST_KEYWORDS])]: |
|
340 |
for keywords in keywords_list: |
|
341 |
all_keywords.extend([keyword for keyword in keywords if keyword not in all_keywords]) |