1 #!/usr/bin/env python |
1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- |
2 # -*- coding: utf-8 -*- |
3 |
|
4 import string, os, sys |
|
5 |
3 |
6 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
7 #based on the plcopen standard. |
5 #based on the plcopen standard. |
8 # |
6 # |
9 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
7 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
22 # |
20 # |
23 #You should have received a copy of the GNU General Public |
21 #You should have received a copy of the GNU General Public |
24 #License along with this library; if not, write to the Free Software |
22 #License along with this library; if not, write to the Free Software |
25 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
26 |
24 |
|
25 import string, os, sys, re |
27 |
26 |
28 LANGUAGES = ["IL","ST","FBD","LD","SFC"] |
27 LANGUAGES = ["IL","ST","FBD","LD","SFC"] |
29 |
28 |
30 LOCATIONDATATYPES = {"X" : ["BOOL"], |
29 LOCATIONDATATYPES = {"X" : ["BOOL"], |
31 "B" : ["SINT", "USINT", "BYTE", "STRING"], |
30 "B" : ["SINT", "USINT", "BYTE", "STRING"], |
373 |
372 |
374 #------------------------------------------------------------------------------- |
373 #------------------------------------------------------------------------------- |
375 # Test identifier |
374 # Test identifier |
376 #------------------------------------------------------------------------------- |
375 #------------------------------------------------------------------------------- |
377 |
376 |
378 |
377 IDENTIFIER_MODEL = re.compile( |
|
378 "(?:%(letter)s|_(?:%(letter)s|%(digit)s))(?:_?(?:%(letter)s|%(digit)s))*$" % |
|
379 {"letter": "[a-zA-Z]", "digit": "[0-9]"}) |
379 |
380 |
380 # Test if identifier is valid |
381 # Test if identifier is valid |
381 def TestIdentifier(identifier): |
382 def TestIdentifier(identifier): |
382 if identifier[0].isdigit(): |
383 return IDENTIFIER_MODEL.match(identifier) is not None |
383 return False |
|
384 words = identifier.split('_') |
|
385 for i, word in enumerate(words): |
|
386 if len(word) == 0 and i != 0: |
|
387 return False |
|
388 if len(word) != 0 and not word.isalnum(): |
|
389 return False |
|
390 return True |
|
391 |
|
392 |
384 |
393 #------------------------------------------------------------------------------- |
385 #------------------------------------------------------------------------------- |
394 # Standard functions list generation |
386 # Standard functions list generation |
395 #------------------------------------------------------------------------------- |
387 #------------------------------------------------------------------------------- |
396 |
388 |