186 | (?P<ConditionalDefine> |
186 | (?P<ConditionalDefine> |
187 ^ |
187 ^ |
188 (?P<ConditionalDefineIndent> [ \t]* ) |
188 (?P<ConditionalDefineIndent> [ \t]* ) |
189 (?: (?: if | elif ) [ \t]+ [^:]* | else [ \t]* ) : (?= \s* def) |
189 (?: (?: if | elif ) [ \t]+ [^:]* | else [ \t]* ) : (?= \s* def) |
190 ) |
190 ) |
191 """, re.VERBOSE | re.DOTALL | re.MULTILINE).search |
191 """, re.VERBOSE | re.DOTALL | re.MULTILINE).search # __IGNORE_WARNING__ |
192 |
192 |
193 _rb_getnext = re.compile( |
193 _rb_getnext = re.compile( |
194 r""" |
194 r""" |
195 (?P<Docstring> |
195 (?P<Docstring> |
196 =begin [ \t]+ edoc (?P<DocstringContents> .*? ) =end |
196 =begin [ \t]+ edoc (?P<DocstringContents> .*? ) =end |
565 lambda x, y: x + y, deltastack) |
565 lambda x, y: x + y, deltastack) |
566 deltaindentcalculated = 1 |
566 deltaindentcalculated = 1 |
567 thisindent -= deltaindent |
567 thisindent -= deltaindent |
568 else: |
568 else: |
569 while conditionalsstack and \ |
569 while conditionalsstack and \ |
570 conditionalsstack[-1] >= thisindent: |
570 conditionalsstack[-1] >= thisindent: |
571 del conditionalsstack[-1] |
571 del conditionalsstack[-1] |
572 if deltastack: |
572 if deltastack: |
573 del deltastack[-1] |
573 del deltastack[-1] |
574 deltaindentcalculated = 0 |
574 deltaindentcalculated = 0 |
575 # close all classes indented at least as much |
575 # close all classes indented at least as much |
576 while classstack and \ |
576 while classstack and \ |
577 classstack[-1][1] >= thisindent: |
577 classstack[-1][1] >= thisindent: |
578 if classstack[-1][0] is not None and \ |
578 if classstack[-1][0] is not None and \ |
579 isinstance(classstack[-1][0], (Class, Function)): |
579 isinstance(classstack[-1][0], (Class, Function)): |
580 # record the end line of this class or function |
580 # record the end line of this class or function |
581 classstack[-1][0].setEndLine(lineno - 1) |
581 classstack[-1][0].setEndLine(lineno - 1) |
582 del classstack[-1] |
582 del classstack[-1] |
630 else: |
630 else: |
631 if self.file.lower().endswith('.ptl'): |
631 if self.file.lower().endswith('.ptl'): |
632 contents = "" |
632 contents = "" |
633 else: |
633 else: |
634 contents = 1 and m.group("DocstringContents1") \ |
634 contents = 1 and m.group("DocstringContents1") \ |
635 or m.group("DocstringContents2") |
635 or m.group("DocstringContents2") |
636 if cur_obj: |
636 if cur_obj: |
637 cur_obj.addDescription(contents) |
637 cur_obj.addDescription(contents) |
638 |
638 |
639 elif m.start("String") >= 0: |
639 elif m.start("String") >= 0: |
640 if modulelevel and \ |
640 if modulelevel and \ |
641 (src[start - len('\r\n'):start] == '\r\n' or |
641 (src[start - len('\r\n'):start] == '\r\n' or |
642 src[start - len('\n'):start] == '\n' or |
642 src[start - len('\n'):start] == '\n' or |
643 src[start - len('\r'):start] == '\r'): |
643 src[start - len('\r'):start] == '\r'): |
644 contents = m.group("StringContents3") |
644 contents = m.group("StringContents3") |
645 if contents is not None: |
645 if contents is not None: |
646 contents = _hashsub(r"\1", contents) |
646 contents = _hashsub(r"\1", contents) |
647 else: |
647 else: |
648 if self.file.lower().endswith('.ptl'): |
648 if self.file.lower().endswith('.ptl'): |
649 contents = "" |
649 contents = "" |
650 else: |
650 else: |
651 contents = 1 and m.group("StringContents1") \ |
651 contents = 1 and m.group("StringContents1") \ |
652 or m.group("StringContents2") |
652 or m.group("StringContents2") |
653 if cur_obj: |
653 if cur_obj: |
654 cur_obj.addDescription(contents) |
654 cur_obj.addDescription(contents) |
655 |
655 |
656 elif m.start("Class") >= 0: |
656 elif m.start("Class") >= 0: |
657 # we found a class definition |
657 # we found a class definition |
658 thisindent = _indent(m.group("ClassIndent")) |
658 thisindent = _indent(m.group("ClassIndent")) |
659 lineno = lineno + src.count('\n', last_lineno_pos, start) |
659 lineno = lineno + src.count('\n', last_lineno_pos, start) |
660 last_lineno_pos = start |
660 last_lineno_pos = start |
661 # close all classes indented at least as much |
661 # close all classes indented at least as much |
662 while classstack and \ |
662 while classstack and \ |
663 classstack[-1][1] >= thisindent: |
663 classstack[-1][1] >= thisindent: |
664 if classstack[-1][0] is not None and \ |
664 if classstack[-1][0] is not None and \ |
665 isinstance(classstack[-1][0], (Class, Function)): |
665 isinstance(classstack[-1][0], (Class, Function)): |
666 # record the end line of this class or function |
666 # record the end line of this class or function |
667 classstack[-1][0].setEndLine(lineno - 1) |
667 classstack[-1][0].setEndLine(lineno - 1) |
668 del classstack[-1] |
668 del classstack[-1] |
773 |
773 |
774 elif m.start("ConditionalDefine") >= 0: |
774 elif m.start("ConditionalDefine") >= 0: |
775 # a conditional function/method definition |
775 # a conditional function/method definition |
776 thisindent = _indent(m.group("ConditionalDefineIndent")) |
776 thisindent = _indent(m.group("ConditionalDefineIndent")) |
777 while conditionalsstack and \ |
777 while conditionalsstack and \ |
778 conditionalsstack[-1] >= thisindent: |
778 conditionalsstack[-1] >= thisindent: |
779 del conditionalsstack[-1] |
779 del conditionalsstack[-1] |
780 if deltastack: |
780 if deltastack: |
781 del deltastack[-1] |
781 del deltastack[-1] |
782 conditionalsstack.append(thisindent) |
782 conditionalsstack.append(thisindent) |
783 deltaindentcalculated = 0 |
783 deltaindentcalculated = 0 |
810 if m.start("Method") >= 0: |
810 if m.start("Method") >= 0: |
811 # found a method definition or function |
811 # found a method definition or function |
812 thisindent = indent |
812 thisindent = indent |
813 indent += 1 |
813 indent += 1 |
814 meth_name = m.group("MethodName") or \ |
814 meth_name = m.group("MethodName") or \ |
815 m.group("MethodName2") or \ |
815 m.group("MethodName2") or \ |
816 m.group("MethodName3") |
816 m.group("MethodName3") |
817 meth_sig = m.group("MethodSignature") |
817 meth_sig = m.group("MethodSignature") |
818 meth_sig = meth_sig and meth_sig.replace('\\\n', '') or '' |
818 meth_sig = meth_sig and meth_sig.replace('\\\n', '') or '' |
819 lineno = lineno + src.count('\n', last_lineno_pos, start) |
819 lineno = lineno + src.count('\n', last_lineno_pos, start) |
820 last_lineno_pos = start |
820 last_lineno_pos = start |
821 if meth_name.startswith('self.'): |
821 if meth_name.startswith('self.'): |
822 meth_name = meth_name[5:] |
822 meth_name = meth_name[5:] |
823 elif meth_name.startswith('self::'): |
823 elif meth_name.startswith('self::'): |
824 meth_name = meth_name[6:] |
824 meth_name = meth_name[6:] |
825 # close all classes/modules indented at least as much |
825 # close all classes/modules indented at least as much |
826 while classstack and \ |
826 while classstack and \ |
827 classstack[-1][1] >= thisindent: |
827 classstack[-1][1] >= thisindent: |
828 if classstack[-1][0] is not None and \ |
828 if classstack[-1][0] is not None and \ |
829 isinstance(classstack[-1][0], |
829 isinstance(classstack[-1][0], |
830 (Class, Function, RbModule)): |
830 (Class, Function, RbModule)): |
831 # record the end line of this class, function or module |
831 # record the end line of this class, function or module |
832 classstack[-1][0].setEndLine(lineno - 1) |
832 classstack[-1][0].setEndLine(lineno - 1) |
833 del classstack[-1] |
833 del classstack[-1] |
834 while acstack and \ |
834 while acstack and \ |
835 acstack[-1][1] >= thisindent: |
835 acstack[-1][1] >= thisindent: |
836 del acstack[-1] |
836 del acstack[-1] |
837 if classstack: |
837 if classstack: |
838 csi = -1 |
838 csi = -1 |
839 while csi >= -len(classstack): |
839 while csi >= -len(classstack): |
840 # nested defs are added to the class |
840 # nested defs are added to the class |
900 indent += 1 |
900 indent += 1 |
901 lineno = lineno + src.count('\n', last_lineno_pos, start) |
901 lineno = lineno + src.count('\n', last_lineno_pos, start) |
902 last_lineno_pos = start |
902 last_lineno_pos = start |
903 # close all classes/modules indented at least as much |
903 # close all classes/modules indented at least as much |
904 while classstack and \ |
904 while classstack and \ |
905 classstack[-1][1] >= thisindent: |
905 classstack[-1][1] >= thisindent: |
906 if classstack[-1][0] is not None and \ |
906 if classstack[-1][0] is not None and \ |
907 isinstance(classstack[-1][0], |
907 isinstance(classstack[-1][0], |
908 (Class, Function, RbModule)): |
908 (Class, Function, RbModule)): |
909 # record the end line of this class, function or module |
909 # record the end line of this class, function or module |
910 classstack[-1][0].setEndLine(lineno - 1) |
910 classstack[-1][0].setEndLine(lineno - 1) |
924 else: |
924 else: |
925 parent_obj = self |
925 parent_obj = self |
926 if class_name in parent_obj.classes: |
926 if class_name in parent_obj.classes: |
927 cur_class = parent_obj.classes[class_name] |
927 cur_class = parent_obj.classes[class_name] |
928 elif classstack and \ |
928 elif classstack and \ |
929 isinstance(classstack[-1][0], Class) and \ |
929 isinstance(classstack[-1][0], Class) and \ |
930 class_name == "self": |
930 class_name == "self": |
931 cur_class = classstack[-1][0] |
931 cur_class = classstack[-1][0] |
932 else: |
932 else: |
933 parent_obj.addClass(class_name, cur_class) |
933 parent_obj.addClass(class_name, cur_class) |
934 if not classstack: |
934 if not classstack: |
935 if lastGlobalEntry: |
935 if lastGlobalEntry: |
936 lastGlobalEntry.setEndLine(lineno - 1) |
936 lastGlobalEntry.setEndLine(lineno - 1) |
937 lastGlobalEntry = cur_class |
937 lastGlobalEntry = cur_class |
938 cur_obj = cur_class |
938 cur_obj = cur_class |
939 classstack.append((cur_class, thisindent)) |
939 classstack.append((cur_class, thisindent)) |
940 while acstack and \ |
940 while acstack and \ |
941 acstack[-1][1] >= thisindent: |
941 acstack[-1][1] >= thisindent: |
942 del acstack[-1] |
942 del acstack[-1] |
943 acstack.append(["public", thisindent]) |
943 acstack.append(["public", thisindent]) |
944 # default access control is 'public' |
944 # default access control is 'public' |
945 |
945 |
946 elif m.start("Module") >= 0: |
946 elif m.start("Module") >= 0: |
949 indent += 1 |
949 indent += 1 |
950 lineno = lineno + src.count('\n', last_lineno_pos, start) |
950 lineno = lineno + src.count('\n', last_lineno_pos, start) |
951 last_lineno_pos = start |
951 last_lineno_pos = start |
952 # close all classes/modules indented at least as much |
952 # close all classes/modules indented at least as much |
953 while classstack and \ |
953 while classstack and \ |
954 classstack[-1][1] >= thisindent: |
954 classstack[-1][1] >= thisindent: |
955 if classstack[-1][0] is not None and \ |
955 if classstack[-1][0] is not None and \ |
956 isinstance(classstack[-1][0], |
956 isinstance(classstack[-1][0], |
957 (Class, Function, RbModule)): |
957 (Class, Function, RbModule)): |
958 # record the end line of this class, function or module |
958 # record the end line of this class, function or module |
959 classstack[-1][0].setEndLine(lineno - 1) |
959 classstack[-1][0].setEndLine(lineno - 1) |
972 lastGlobalEntry.setEndLine(lineno - 1) |
972 lastGlobalEntry.setEndLine(lineno - 1) |
973 lastGlobalEntry = cur_class |
973 lastGlobalEntry = cur_class |
974 cur_obj = cur_class |
974 cur_obj = cur_class |
975 classstack.append((cur_class, thisindent)) |
975 classstack.append((cur_class, thisindent)) |
976 while acstack and \ |
976 while acstack and \ |
977 acstack[-1][1] >= thisindent: |
977 acstack[-1][1] >= thisindent: |
978 del acstack[-1] |
978 del acstack[-1] |
979 acstack.append(["public", thisindent]) |
979 acstack.append(["public", thisindent]) |
980 # default access control is 'public' |
980 # default access control is 'public' |
981 |
981 |
982 elif m.start("AccessControl") >= 0: |
982 elif m.start("AccessControl") >= 0: |
1061 if not nv: |
1061 if not nv: |
1062 break |
1062 break |
1063 # get rid of leading ':' |
1063 # get rid of leading ':' |
1064 name = nv[0].strip()[1:] |
1064 name = nv[0].strip()[1:] |
1065 attr = parent.getAttribute("@" + name) or \ |
1065 attr = parent.getAttribute("@" + name) or \ |
1066 parent.getAttribute("@@" + name) or \ |
1066 parent.getAttribute("@@" + name) or \ |
1067 Attribute( |
1067 Attribute( |
1068 self.name, "@" + name, self.file, lineno) |
1068 self.name, "@" + name, self.file, lineno) |
1069 if len(nv) == 1 or nv[1].strip() == "false": |
1069 if len(nv) == 1 or nv[1].strip() == "false": |
1070 attr.setProtected() |
1070 attr.setProtected() |
1071 elif nv[1].strip() == "true": |
1071 elif nv[1].strip() == "true": |
1072 attr.setPublic() |
1072 attr.setPublic() |
1075 access = m.group("AttrType") |
1075 access = m.group("AttrType") |
1076 for name in m.group("AttrList").split(","): |
1076 for name in m.group("AttrList").split(","): |
1077 # get rid of leading ':' |
1077 # get rid of leading ':' |
1078 name = name.strip()[1:] |
1078 name = name.strip()[1:] |
1079 attr = parent.getAttribute("@" + name) or \ |
1079 attr = parent.getAttribute("@" + name) or \ |
1080 parent.getAttribute("@@" + name) or \ |
1080 parent.getAttribute("@@" + name) or \ |
1081 Attribute( |
1081 Attribute( |
1082 self.name, "@" + name, self.file, |
1082 self.name, "@" + name, self.file, |
1083 lineno) |
1083 lineno) |
1084 if access == "_accessor": |
1084 if access == "_accessor": |
1085 attr.setPublic() |
1085 attr.setPublic() |
1086 elif access == "_reader" or \ |
1086 elif access == "_reader" or \ |