src/eric7/Utilities/ModuleParser.py

branch
eric7
changeset 9693
a7e9fd398e5a
parent 9653
e67609152c5e
child 9733
c5c2a74e9382
equal deleted inserted replaced
9692:a0be29ab700a 9693:a7e9fd398e5a
19 import os 19 import os
20 import re 20 import re
21 import sys 21 import sys
22 22
23 from functools import reduce 23 from functools import reduce
24
25 from PyQt6.QtCore import QRegularExpression
24 26
25 from eric7 import Utilities 27 from eric7 import Utilities
26 28
27 __all__ = [ 29 __all__ = [
28 "Attribute", 30 "Attribute",
62 return TYPE_MAPPING[name] 64 return TYPE_MAPPING[name]
63 else: 65 else:
64 return -1 66 return -1
65 67
66 68
67 _py_getnext = re.compile( 69 _py_getnext = QRegularExpression(
68 r""" 70 r"""
69 (?P<Comment> 71 (?P<Comment>
70 \# .*? $ # ignore everything in comments 72 \# .*? $ # ignore everything in comments
71 ) 73 )
72 74
210 ^ 212 ^
211 (?P<ConditionalDefineIndent> [ \t]* ) 213 (?P<ConditionalDefineIndent> [ \t]* )
212 (?: (?: if | elif ) [ \t]+ [^:]* | else [ \t]* ) : 214 (?: (?: if | elif ) [ \t]+ [^:]* | else [ \t]* ) :
213 (?= \s* (?: async [ \t]+ )? def) 215 (?= \s* (?: async [ \t]+ )? def)
214 )""", 216 )""",
215 re.VERBOSE | re.DOTALL | re.MULTILINE, 217 QRegularExpression.PatternOption.MultilineOption
216 ).search 218 | QRegularExpression.PatternOption.DotMatchesEverythingOption
217 219 | QRegularExpression.PatternOption.ExtendedPatternSyntaxOption
218 _rb_getnext = re.compile( 220 | QRegularExpression.PatternOption.UseUnicodePropertiesOption,
221 ).match
222
223 _rb_getnext = QRegularExpression(
219 r""" 224 r"""
220 (?P<Docstring> 225 (?P<Docstring>
221 =begin [ \t]+ edoc (?P<DocstringContents> .*? ) =end 226 =begin [ \t]+ edoc (?P<DocstringContents> .*? ) =end
222 ) 227 )
223 228
348 end [ \t]* $ 353 end [ \t]* $
349 | 354 |
350 end \b [^_] 355 end \b [^_]
351 ) 356 )
352 )""", 357 )""",
353 re.VERBOSE | re.DOTALL | re.MULTILINE, 358 QRegularExpression.PatternOption.MultilineOption
354 ).search 359 | QRegularExpression.PatternOption.DotMatchesEverythingOption
360 | QRegularExpression.PatternOption.ExtendedPatternSyntaxOption
361 | QRegularExpression.PatternOption.UseUnicodePropertiesOption,
362 ).match
355 363
356 _hashsub = re.compile(r"""^([ \t]*)#[ \t]?""", re.MULTILINE).sub 364 _hashsub = re.compile(r"""^([ \t]*)#[ \t]?""", re.MULTILINE).sub
357 365
358 _commentsub = re.compile(r"""#[^\n]*\n|#[^\n]*$""").sub 366 _commentsub = re.compile(r"""#[^\n]*\n|#[^\n]*$""").sub
359 367
579 cur_obj = self 587 cur_obj = self
580 modifierType = Function.General 588 modifierType = Function.General
581 modifierIndent = -1 589 modifierIndent = -1
582 while True: 590 while True:
583 m = self._getnext(src, i) 591 m = self._getnext(src, i)
584 if not m: 592 if not m.hasMatch():
585 break 593 break
586 start, i = m.span() 594 start, i = m.capturedStart(), m.capturedEnd()
587 595
588 if m.start("MethodModifier") >= 0: 596 if m.hasCaptured("MethodModifier"):
589 modifierIndent = _indent(m.group("MethodModifierIndent")) 597 modifierIndent = _indent(m.captured("MethodModifierIndent"))
590 modifierType = m.group("MethodModifierType") 598 modifierType = m.captured("MethodModifierType")
591 599
592 elif m.start("Method") >= 0: 600 elif m.hasCaptured("Method"):
593 # found a method definition or function 601 # found a method definition or function
594 thisindent = _indent(m.group("MethodIndent")) 602 thisindent = _indent(m.captured("MethodIndent"))
595 meth_name = m.group("MethodName") 603 meth_name = m.captured("MethodName")
596 meth_sig = m.group("MethodSignature") 604 meth_sig = m.captured("MethodSignature")
597 meth_sig = meth_sig.replace("\\\n", "") 605 meth_sig = meth_sig.replace("\\\n", "")
598 meth_ret = m.group("MethodReturnAnnotation") 606 meth_ret = m.captured("MethodReturnAnnotation")
599 meth_ret = meth_ret.replace("\\\n", "") 607 meth_ret = meth_ret.replace("\\\n", "")
600 if m.group("MethodPyQtSignature") is not None: 608 if m.captured("MethodPyQtSignature"):
601 meth_pyqtSig = ( 609 meth_pyqtSig = (
602 m.group("MethodPyQtSignature") 610 m.captured("MethodPyQtSignature")
603 .replace("\\\n", "") 611 .replace("\\\n", "")
604 .split("result")[0] 612 .split("result")[0]
605 .split("name")[0] 613 .split("name")[0]
606 .strip("\"', \t") 614 .strip("\"', \t")
607 ) 615 )
694 702
695 # reset the modifier settings 703 # reset the modifier settings
696 modifierType = Function.General 704 modifierType = Function.General
697 modifierIndent = -1 705 modifierIndent = -1
698 706
699 elif m.start("Docstring") >= 0: 707 elif m.hasCaptured("Docstring"):
700 contents = m.group("DocstringContents3") 708 contents = m.captured("DocstringContents3")
701 if contents is not None: 709 if contents:
702 contents = _hashsub(r"\1", contents) 710 contents = _hashsub(r"\1", contents)
703 else: 711 else:
704 if self.file.lower().endswith(".ptl"): 712 if self.file.lower().endswith(".ptl"):
705 contents = "" 713 contents = ""
706 else: 714 else:
707 contents = m.group("DocstringContents1") or m.group( 715 contents = m.captured("DocstringContents1") or m.captured(
708 "DocstringContents2" 716 "DocstringContents2"
709 ) 717 )
710 if cur_obj: 718 if cur_obj:
711 cur_obj.addDescription(contents) 719 cur_obj.addDescription(contents)
712 720
713 elif m.start("String") >= 0: 721 elif m.hasCaptured("String"):
714 if modulelevel and ( 722 if modulelevel and (
715 src[start - len("\r\n") : start] == "\r\n" 723 src[start - len("\r\n") : start] == "\r\n"
716 or src[start - len("\n") : start] == "\n" 724 or src[start - len("\n") : start] == "\n"
717 or src[start - len("\r") : start] == "\r" 725 or src[start - len("\r") : start] == "\r"
718 ): 726 ):
719 contents = m.group("StringContents3") 727 contents = m.captured("StringContents3")
720 if contents is not None: 728 if contents:
721 contents = _hashsub(r"\1", contents) 729 contents = _hashsub(r"\1", contents)
722 else: 730 else:
723 if self.file.lower().endswith(".ptl"): 731 if self.file.lower().endswith(".ptl"):
724 contents = "" 732 contents = ""
725 else: 733 else:
726 contents = m.group("StringContents1") or m.group( 734 contents = m.captured("StringContents1") or m.captured(
727 "StringContents2" 735 "StringContents2"
728 ) 736 )
729 if cur_obj: 737 if cur_obj:
730 cur_obj.addDescription(contents) 738 cur_obj.addDescription(contents)
731 739
732 elif m.start("Class") >= 0: 740 elif m.hasCaptured("Class"):
733 # we found a class definition 741 # we found a class definition
734 thisindent = _indent(m.group("ClassIndent")) 742 thisindent = _indent(m.captured("ClassIndent"))
735 lineno += src.count("\n", last_lineno_pos, start) 743 lineno += src.count("\n", last_lineno_pos, start)
736 last_lineno_pos = start 744 last_lineno_pos = start
737 # close all classes indented at least as much 745 # close all classes indented at least as much
738 while classstack and classstack[-1][1] >= thisindent: 746 while classstack and classstack[-1][1] >= thisindent:
739 del classstack[-1] 747 del classstack[-1]
740 class_name = m.group("ClassName") 748 class_name = m.captured("ClassName")
741 inherit = m.group("ClassSupers") 749 inherit = m.captured("ClassSupers")
742 if inherit: 750 if inherit:
743 # the class inherits from other classes 751 # the class inherits from other classes
744 inherit = inherit[1:-1].strip() 752 inherit = inherit[1:-1].strip()
745 inherit = _commentsub("", inherit) 753 inherit = _commentsub("", inherit)
746 names = [] 754 names = []
785 cur_obj = cur_class 793 cur_obj = cur_class
786 self.addClass(class_name, cur_class) 794 self.addClass(class_name, cur_class)
787 # add nested classes to the module 795 # add nested classes to the module
788 classstack.append((cur_class, thisindent)) 796 classstack.append((cur_class, thisindent))
789 797
790 elif m.start("Attribute") >= 0: 798 elif m.hasCaptured("Attribute"):
791 lineno += src.count("\n", last_lineno_pos, start) 799 lineno += src.count("\n", last_lineno_pos, start)
792 last_lineno_pos = start 800 last_lineno_pos = start
793 index = -1 801 index = -1
794 while index >= -len(classstack): 802 while index >= -len(classstack):
795 if classstack[index][0] is not None: 803 if classstack[index][0] is not None:
796 attrName = m.group("AttributeName") 804 attrName = m.captured("AttributeName")
797 attr = Attribute(self.name, attrName, self.file, lineno) 805 attr = Attribute(self.name, attrName, self.file, lineno)
798 self.__py_setVisibility(attr) 806 self.__py_setVisibility(attr)
799 classstack[index][0].addAttribute(attrName, attr) 807 classstack[index][0].addAttribute(attrName, attr)
800 break 808 break
801 else: 809 else:
802 index -= 1 810 index -= 1
803 811
804 elif m.start("Main") >= 0: 812 elif m.hasCaptured("Main"):
805 # 'main' part of the script, reset class stack 813 # 'main' part of the script, reset class stack
806 lineno += src.count("\n", last_lineno_pos, start) 814 lineno += src.count("\n", last_lineno_pos, start)
807 last_lineno_pos = start 815 last_lineno_pos = start
808 classstack = [] 816 classstack = []
809 817
810 elif m.start("Variable") >= 0: 818 elif m.hasCaptured("Variable"):
811 thisindent = _indent(m.group("VariableIndent")) 819 thisindent = _indent(m.captured("VariableIndent"))
812 variable_name = m.group("VariableName") 820 variable_name = m.captured("VariableName")
813 isSignal = m.group("VariableSignal") != "" 821 isSignal = m.captured("VariableSignal") != ""
814 lineno += src.count("\n", last_lineno_pos, start) 822 lineno += src.count("\n", last_lineno_pos, start)
815 last_lineno_pos = start 823 last_lineno_pos = start
816 if thisindent == 0: 824 if thisindent == 0:
817 # global variable 825 # global variable
818 attr = Attribute( 826 attr = Attribute(
838 ) 846 )
839 self.__py_setVisibility(attr) 847 self.__py_setVisibility(attr)
840 classstack[index][0].addGlobal(variable_name, attr) 848 classstack[index][0].addGlobal(variable_name, attr)
841 break 849 break
842 850
843 elif m.start("Import") >= 0: 851 elif m.hasCaptured("Import"):
844 # - import module 852 # - import module
845 names = [ 853 names = [
846 n.strip() 854 n.strip()
847 for n in "".join(m.group("ImportList").splitlines()) 855 for n in "".join(m.captured("ImportList").splitlines())
848 .replace("\\", "") 856 .replace("\\", "")
849 .split(",") 857 .split(",")
850 ] 858 ]
851 self.imports.extend( 859 self.imports.extend(
852 [name for name in names if name not in self.imports] 860 [name for name in names if name not in self.imports]
853 ) 861 )
854 862
855 elif m.start("ImportFrom") >= 0: 863 elif m.hasCaptured("ImportFrom"):
856 # - from module import stuff 864 # - from module import stuff
857 mod = m.group("ImportFromPath") 865 mod = m.captured("ImportFromPath")
858 namesLines = ( 866 namesLines = (
859 m.group("ImportFromList") 867 m.captured("ImportFromList")
860 .replace("(", "") 868 .replace("(", "")
861 .replace(")", "") 869 .replace(")", "")
862 .replace("\\", "") 870 .replace("\\", "")
863 .strip() 871 .strip()
864 .splitlines() 872 .splitlines()
869 self.from_imports[mod] = [] 877 self.from_imports[mod] = []
870 self.from_imports[mod].extend( 878 self.from_imports[mod].extend(
871 [name for name in names if name not in self.from_imports[mod]] 879 [name for name in names if name not in self.from_imports[mod]]
872 ) 880 )
873 881
874 elif m.start("ConditionalDefine") >= 0: 882 elif m.hasCaptured("ConditionalDefine"):
875 # a conditional function/method definition 883 # a conditional function/method definition
876 thisindent = _indent(m.group("ConditionalDefineIndent")) 884 thisindent = _indent(m.captured("ConditionalDefineIndent"))
877 while conditionalsstack and conditionalsstack[-1] >= thisindent: 885 while conditionalsstack and conditionalsstack[-1] >= thisindent:
878 del conditionalsstack[-1] 886 del conditionalsstack[-1]
879 if deltastack: 887 if deltastack:
880 del deltastack[-1] 888 del deltastack[-1]
881 conditionalsstack.append(thisindent) 889 conditionalsstack.append(thisindent)
882 deltaindentcalculated = 0 890 deltaindentcalculated = 0
883 891
884 elif m.start("Comment") >= 0 and modulelevel: 892 elif m.hasCaptured("Comment") and modulelevel:
885 continue 893 continue
886 894
887 modulelevel = False 895 modulelevel = False
888 896
889 def __rb_scan(self, src): 897 def __rb_scan(self, src):
901 i = 0 909 i = 0
902 cur_obj = self 910 cur_obj = self
903 lastGlobalEntry = None 911 lastGlobalEntry = None
904 while True: 912 while True:
905 m = self._getnext(src, i) 913 m = self._getnext(src, i)
906 if not m: 914 if not m.hasMatch():
907 break 915 break
908 start, i = m.span() 916 start, i = m.capturedStart(), m.capturedEnd()
909 917
910 if m.start("Method") >= 0: 918 if m.hasCaptured("Method"):
911 # found a method definition or function 919 # found a method definition or function
912 thisindent = indent 920 thisindent = indent
913 indent += 1 921 indent += 1
914 meth_name = ( 922 meth_name = (
915 m.group("MethodName") 923 m.captured("MethodName")
916 or m.group("MethodName2") 924 or m.captured("MethodName2")
917 or m.group("MethodName3") 925 or m.captured("MethodName3")
918 ) 926 )
919 meth_sig = m.group("MethodSignature") 927 meth_sig = m.captured("MethodSignature")
920 meth_sig = meth_sig and meth_sig.replace("\\\n", "") or "" 928 meth_sig = meth_sig and meth_sig.replace("\\\n", "") or ""
921 lineno += src.count("\n", last_lineno_pos, start) 929 lineno += src.count("\n", last_lineno_pos, start)
922 last_lineno_pos = start 930 last_lineno_pos = start
923 if meth_name.startswith("self."): 931 if meth_name.startswith("self."):
924 meth_name = meth_name[5:] 932 meth_name = meth_name[5:]
972 if cur_obj and isinstance(cur_obj, Function): 980 if cur_obj and isinstance(cur_obj, Function):
973 cur_obj.setEndLine(lineno - 1) 981 cur_obj.setEndLine(lineno - 1)
974 cur_obj = f 982 cur_obj = f
975 classstack.append((None, thisindent)) # Marker for nested fns 983 classstack.append((None, thisindent)) # Marker for nested fns
976 984
977 elif m.start("Docstring") >= 0: 985 elif m.hasCaptured("Docstring"):
978 contents = m.group("DocstringContents") 986 contents = m.captured("DocstringContents")
979 if contents is not None: 987 if contents:
980 contents = _hashsub(r"\1", contents) 988 contents = _hashsub(r"\1", contents)
981 if cur_obj: 989 if cur_obj:
982 cur_obj.addDescription(contents) 990 cur_obj.addDescription(contents)
983 991
984 elif m.start("Class") >= 0: 992 elif m.hasCaptured("Class"):
985 # we found a class definition 993 # we found a class definition
986 thisindent = indent 994 thisindent = indent
987 indent += 1 995 indent += 1
988 lineno += src.count("\n", last_lineno_pos, start) 996 lineno += src.count("\n", last_lineno_pos, start)
989 last_lineno_pos = start 997 last_lineno_pos = start
993 classstack[-1][0], (Class, Function, RbModule) 1001 classstack[-1][0], (Class, Function, RbModule)
994 ): 1002 ):
995 # record the end line of this class, function or module 1003 # record the end line of this class, function or module
996 classstack[-1][0].setEndLine(lineno - 1) 1004 classstack[-1][0].setEndLine(lineno - 1)
997 del classstack[-1] 1005 del classstack[-1]
998 class_name = m.group("ClassName") or m.group("ClassName2") 1006 class_name = m.captured("ClassName") or m.captured("ClassName2")
999 inherit = m.group("ClassSupers") 1007 inherit = m.captured("ClassSupers")
1000 if inherit: 1008 if inherit:
1001 # the class inherits from other classes 1009 # the class inherits from other classes
1002 inherit = inherit[1:].strip() 1010 inherit = inherit[1:].strip()
1003 inherit = [_commentsub("", inherit)] 1011 inherit = [_commentsub("", inherit)]
1004 # remember this class 1012 # remember this class
1027 while acstack and acstack[-1][1] >= thisindent: 1035 while acstack and acstack[-1][1] >= thisindent:
1028 del acstack[-1] 1036 del acstack[-1]
1029 acstack.append(["public", thisindent]) 1037 acstack.append(["public", thisindent])
1030 # default access control is 'public' 1038 # default access control is 'public'
1031 1039
1032 elif m.start("Module") >= 0: 1040 elif m.hasCaptured("Module"):
1033 # we found a module definition 1041 # we found a module definition
1034 thisindent = indent 1042 thisindent = indent
1035 indent += 1 1043 indent += 1
1036 lineno += src.count("\n", last_lineno_pos, start) 1044 lineno += src.count("\n", last_lineno_pos, start)
1037 last_lineno_pos = start 1045 last_lineno_pos = start
1041 classstack[-1][0], (Class, Function, RbModule) 1049 classstack[-1][0], (Class, Function, RbModule)
1042 ): 1050 ):
1043 # record the end line of this class, function or module 1051 # record the end line of this class, function or module
1044 classstack[-1][0].setEndLine(lineno - 1) 1052 classstack[-1][0].setEndLine(lineno - 1)
1045 del classstack[-1] 1053 del classstack[-1]
1046 module_name = m.group("ModuleName") 1054 module_name = m.captured("ModuleName")
1047 # remember this class 1055 # remember this class
1048 cur_class = RbModule(self.name, module_name, self.file, lineno) 1056 cur_class = RbModule(self.name, module_name, self.file, lineno)
1049 # add nested Ruby modules to the file 1057 # add nested Ruby modules to the file
1050 if module_name in self.modules: 1058 if module_name in self.modules:
1051 cur_class = self.modules[module_name] 1059 cur_class = self.modules[module_name]
1060 while acstack and acstack[-1][1] >= thisindent: 1068 while acstack and acstack[-1][1] >= thisindent:
1061 del acstack[-1] 1069 del acstack[-1]
1062 acstack.append(["public", thisindent]) 1070 acstack.append(["public", thisindent])
1063 # default access control is 'public' 1071 # default access control is 'public'
1064 1072
1065 elif m.start("AccessControl") >= 0: 1073 elif m.hasCaptured("AccessControl"):
1066 aclist = m.group("AccessControlList") 1074 aclist = m.captured("AccessControlList")
1067 if aclist is None: 1075 if not aclist:
1068 index = -1 1076 index = -1
1069 while index >= -len(acstack): 1077 while index >= -len(acstack):
1070 if acstack[index][1] < indent: 1078 if acstack[index][1] < indent:
1071 actype = ( 1079 actype = (
1072 m.group("AccessControlType") 1080 m.captured("AccessControlType")
1073 or m.group("AccessControlType2").split("_")[0] 1081 or m.captured("AccessControlType2").split("_")[0]
1074 ) 1082 )
1075 acstack[index][0] = actype.lower() 1083 acstack[index][0] = actype.lower()
1076 break 1084 break
1077 else: 1085 else:
1078 index -= 1 1086 index -= 1
1084 and not isinstance(classstack[index][0], Function) 1092 and not isinstance(classstack[index][0], Function)
1085 and classstack[index][1] < indent 1093 and classstack[index][1] < indent
1086 ): 1094 ):
1087 parent = classstack[index][0] 1095 parent = classstack[index][0]
1088 actype = ( 1096 actype = (
1089 m.group("AccessControlType") 1097 m.captured("AccessControlType")
1090 or m.group("AccessControlType2").split("_")[0] 1098 or m.captured("AccessControlType2").split("_")[0]
1091 ) 1099 )
1092 actype = actype.lower() 1100 actype = actype.lower()
1093 for name in aclist.split(","): 1101 for name in aclist.split(","):
1094 # get rid of leading ':' 1102 # get rid of leading ':'
1095 name = name.strip()[1:] 1103 name = name.strip()[1:]
1104 acmeth.setPublic() 1112 acmeth.setPublic()
1105 break 1113 break
1106 else: 1114 else:
1107 index -= 1 1115 index -= 1
1108 1116
1109 elif m.start("Attribute") >= 0: 1117 elif m.hasCaptured("Attribute"):
1110 lineno += src.count("\n", last_lineno_pos, start) 1118 lineno += src.count("\n", last_lineno_pos, start)
1111 last_lineno_pos = start 1119 last_lineno_pos = start
1112 index = -1 1120 index = -1
1113 while index >= -len(classstack): 1121 while index >= -len(classstack):
1114 if ( 1122 if (
1115 classstack[index][0] is not None 1123 classstack[index][0] is not None
1116 and not isinstance(classstack[index][0], Function) 1124 and not isinstance(classstack[index][0], Function)
1117 and classstack[index][1] < indent 1125 and classstack[index][1] < indent
1118 ): 1126 ):
1119 attrName = m.group("AttributeName") 1127 attrName = m.captured("AttributeName")
1120 attr = Attribute(self.name, attrName, self.file, lineno) 1128 attr = Attribute(self.name, attrName, self.file, lineno)
1121 if attrName.startswith("@@") or attrName[0].isupper(): 1129 if attrName.startswith("@@") or attrName[0].isupper():
1122 classstack[index][0].addGlobal(attrName, attr) 1130 classstack[index][0].addGlobal(attrName, attr)
1123 else: 1131 else:
1124 classstack[index][0].addAttribute(attrName, attr) 1132 classstack[index][0].addAttribute(attrName, attr)
1125 break 1133 break
1126 else: 1134 else:
1127 index -= 1 1135 index -= 1
1128 else: 1136 else:
1129 attrName = m.group("AttributeName") 1137 attrName = m.captured("AttributeName")
1130 if attrName[0] != "@": 1138 if attrName[0] != "@":
1131 attr = Attribute(self.name, attrName, self.file, lineno) 1139 attr = Attribute(self.name, attrName, self.file, lineno)
1132 self.addGlobal(attrName, attr) 1140 self.addGlobal(attrName, attr)
1133 if lastGlobalEntry: 1141 if lastGlobalEntry:
1134 lastGlobalEntry.setEndLine(lineno - 1) 1142 lastGlobalEntry.setEndLine(lineno - 1)
1135 lastGlobalEntry = None 1143 lastGlobalEntry = None
1136 1144
1137 elif m.start("Attr") >= 0: 1145 elif m.hasCaptured("Attr"):
1138 lineno += src.count("\n", last_lineno_pos, start) 1146 lineno += src.count("\n", last_lineno_pos, start)
1139 last_lineno_pos = start 1147 last_lineno_pos = start
1140 index = -1 1148 index = -1
1141 while index >= -len(classstack): 1149 while index >= -len(classstack):
1142 if ( 1150 if (
1143 classstack[index][0] is not None 1151 classstack[index][0] is not None
1144 and not isinstance(classstack[index][0], Function) 1152 and not isinstance(classstack[index][0], Function)
1145 and classstack[index][1] < indent 1153 and classstack[index][1] < indent
1146 ): 1154 ):
1147 parent = classstack[index][0] 1155 parent = classstack[index][0]
1148 if m.group("AttrType") is None: 1156 if not m.captured("AttrType"):
1149 nv = m.group("AttrList").split(",") 1157 nv = m.captured("AttrList").split(",")
1150 if not nv: 1158 if not nv:
1151 break 1159 break
1152 # get rid of leading ':' 1160 # get rid of leading ':'
1153 name = nv[0].strip()[1:] 1161 name = nv[0].strip()[1:]
1154 attr = ( 1162 attr = (
1160 attr.setProtected() 1168 attr.setProtected()
1161 elif nv[1].strip() == "true": 1169 elif nv[1].strip() == "true":
1162 attr.setPublic() 1170 attr.setPublic()
1163 parent.addAttribute(attr.name, attr) 1171 parent.addAttribute(attr.name, attr)
1164 else: 1172 else:
1165 access = m.group("AttrType") 1173 access = m.captured("AttrType")
1166 for name in m.group("AttrList").split(","): 1174 for name in m.captured("AttrList").split(","):
1167 # get rid of leading ':' 1175 # get rid of leading ':'
1168 name = name.strip()[1:] 1176 name = name.strip()[1:]
1169 attr = ( 1177 attr = (
1170 parent.getAttribute("@" + name) 1178 parent.getAttribute("@" + name)
1171 or parent.getAttribute("@@" + name) 1179 or parent.getAttribute("@@" + name)
1183 parent.addAttribute(attr.name, attr) 1191 parent.addAttribute(attr.name, attr)
1184 break 1192 break
1185 else: 1193 else:
1186 index -= 1 1194 index -= 1
1187 1195
1188 elif m.start("Begin") >= 0: 1196 elif m.hasCaptured("Begin"):
1189 # a begin of a block we are not interested in 1197 # a begin of a block we are not interested in
1190 indent += 1 1198 indent += 1
1191 1199
1192 elif m.start("End") >= 0: 1200 elif m.hasCaptured("End"):
1193 # an end of a block 1201 # an end of a block
1194 indent -= 1 1202 indent -= 1
1195 if indent < 0: 1203 if indent < 0:
1196 # no negative indent allowed 1204 # no negative indent allowed
1197 if classstack: 1205 if classstack:
1199 indent = classstack[-1][1] 1207 indent = classstack[-1][1]
1200 else: 1208 else:
1201 indent = 0 1209 indent = 0
1202 1210
1203 elif ( 1211 elif (
1204 m.start("String") >= 0 1212 m.hasCaptured("String")
1205 or m.start("Comment") >= 0 1213 or m.hasCaptured("Comment")
1206 or m.start("ClassIgnored") >= 0 1214 or m.hasCaptured("ClassIgnored")
1207 or m.start("BeginEnd") >= 0 1215 or m.hasCaptured("BeginEnd")
1208 ): 1216 ):
1209 pass 1217 pass
1210 1218
1211 def createHierarchy(self): 1219 def createHierarchy(self):
1212 """ 1220 """

eric ide

mercurial