eric6/Utilities/ModuleParser.py

changeset 8205
4a0f1f896341
parent 8131
f2129bb79269
child 8207
d359172d11be
equal deleted inserted replaced
8204:fd477cded1c1 8205:4a0f1f896341
872 def __rb_scan(self, src): 872 def __rb_scan(self, src):
873 """ 873 """
874 Private method to scan the source text of a Python module and retrieve 874 Private method to scan the source text of a Python module and retrieve
875 the relevant information. 875 the relevant information.
876 876
877 @param src the source text to be scanned (string) 877 @param src the source text to be scanned
878 @type str
878 """ 879 """
879 lineno, last_lineno_pos = 1, 0 880 lineno, last_lineno_pos = 1, 0
880 classstack = [] # stack of (class, indent) pairs 881 classstack = [] # stack of (class, indent) pairs
881 acstack = [] # stack of (access control, indent) pairs 882 acstack = [] # stack of (access control, indent) pairs
882 indent = 0 883 indent = 0
925 cur_class = classstack[csi][0] 926 cur_class = classstack[csi][0]
926 csi -= 1 927 csi -= 1
927 if cur_class is None: 928 if cur_class is None:
928 continue 929 continue
929 930
930 if ( 931 if isinstance(cur_class, (Class, RbModule)):
931 isinstance(cur_class, Class) or
932 isinstance(cur_class, RbModule)
933 ):
934 # it's a class/module method 932 # it's a class/module method
935 f = Function(None, meth_name, 933 f = Function(None, meth_name,
936 None, lineno, meth_sig) 934 None, lineno, meth_sig)
937 cur_class.addMethod(meth_name, f) 935 cur_class.addMethod(meth_name, f)
938 break 936 break
1085 index = -1 1083 index = -1
1086 while index >= -len(classstack): 1084 while index >= -len(classstack):
1087 if ( 1085 if (
1088 classstack[index][0] is not None and 1086 classstack[index][0] is not None and
1089 not isinstance(classstack[index][0], Function) and 1087 not isinstance(classstack[index][0], Function) and
1090 not classstack[index][1] >= indent 1088 classstack[index][1] < indent
1091 ): 1089 ):
1092 parent = classstack[index][0] 1090 parent = classstack[index][0]
1093 actype = ( 1091 actype = (
1094 m.group("AccessControlType") or 1092 m.group("AccessControlType") or
1095 m.group("AccessControlType2").split('_')[0] 1093 m.group("AccessControlType2").split('_')[0]
1117 index = -1 1115 index = -1
1118 while index >= -len(classstack): 1116 while index >= -len(classstack):
1119 if ( 1117 if (
1120 classstack[index][0] is not None and 1118 classstack[index][0] is not None and
1121 not isinstance(classstack[index][0], Function) and 1119 not isinstance(classstack[index][0], Function) and
1122 not classstack[index][1] >= indent 1120 classstack[index][1] < indent
1123 ): 1121 ):
1124 attrName = m.group("AttributeName") 1122 attrName = m.group("AttributeName")
1125 attr = Attribute( 1123 attr = Attribute(
1126 self.name, attrName, self.file, lineno) 1124 self.name, attrName, self.file, lineno)
1127 if attrName.startswith("@@") or attrName[0].isupper(): 1125 if attrName.startswith("@@") or attrName[0].isupper():
1147 index = -1 1145 index = -1
1148 while index >= -len(classstack): 1146 while index >= -len(classstack):
1149 if ( 1147 if (
1150 classstack[index][0] is not None and 1148 classstack[index][0] is not None and
1151 not isinstance(classstack[index][0], Function) and 1149 not isinstance(classstack[index][0], Function) and
1152 not classstack[index][1] >= indent 1150 classstack[index][1] < indent
1153 ): 1151 ):
1154 parent = classstack[index][0] 1152 parent = classstack[index][0]
1155 if m.group("AttrType") is None: 1153 if m.group("AttrType") is None:
1156 nv = m.group("AttrList").split(",") 1154 nv = m.group("AttrList").split(",")
1157 if not nv: 1155 if not nv:
1181 self.name, "@" + name, self.file, 1179 self.name, "@" + name, self.file,
1182 lineno) 1180 lineno)
1183 ) 1181 )
1184 if access == "_accessor": 1182 if access == "_accessor":
1185 attr.setPublic() 1183 attr.setPublic()
1186 elif ( 1184 elif access in ("_reader", "_writer"):
1187 access == "_reader" or
1188 access == "_writer"
1189 ):
1190 if attr.isPrivate(): 1185 if attr.isPrivate():
1191 attr.setProtected() 1186 attr.setProtected()
1192 elif attr.isProtected(): 1187 elif attr.isProtected():
1193 attr.setPublic() 1188 attr.setPublic()
1194 parent.addAttribute(attr.name, attr) 1189 parent.addAttribute(attr.name, attr)
1660 if os.path.exists(os.path.join(p, name)): 1655 if os.path.exists(os.path.join(p, name)):
1661 pathname = os.path.join(p, name) 1656 pathname = os.path.join(p, name)
1662 if ext == '.ptl': 1657 if ext == '.ptl':
1663 # Quixote page template 1658 # Quixote page template
1664 return (open(pathname), pathname, 1659 return (open(pathname), pathname,
1660 # __IGNORE_WARNING_Y115__
1665 ('.ptl', 'r', PTL_SOURCE)) 1661 ('.ptl', 'r', PTL_SOURCE))
1666 elif ext == '.rb': 1662 elif ext == '.rb':
1667 # Ruby source file 1663 # Ruby source file
1668 return (open(pathname), pathname, 1664 return (open(pathname), pathname,
1665 # __IGNORE_WARNING_Y115__
1669 ('.rb', 'r', RB_SOURCE)) 1666 ('.rb', 'r', RB_SOURCE))
1670 else: 1667 else:
1671 return (open(pathname), pathname, 1668 return (open(pathname), pathname,
1669 # __IGNORE_WARNING_Y115__
1672 (ext, 'r', PY_SOURCE)) 1670 (ext, 'r', PY_SOURCE))
1673 raise ImportError 1671 raise ImportError
1674 1672
1675 # standard Python module file 1673 # standard Python module file
1676 if name.lower().endswith('.py'): 1674 if name.lower().endswith('.py'):
1680 if spec is None: 1678 if spec is None:
1681 raise ImportError 1679 raise ImportError
1682 if isinstance(spec.loader, importlib.machinery.SourceFileLoader): 1680 if isinstance(spec.loader, importlib.machinery.SourceFileLoader):
1683 ext = os.path.splitext(spec.origin)[-1] 1681 ext = os.path.splitext(spec.origin)[-1]
1684 return (open(spec.origin), spec.origin, (ext, 'r', PY_SOURCE)) 1682 return (open(spec.origin), spec.origin, (ext, 'r', PY_SOURCE))
1683 # __IGNORE_WARNING_Y115__
1685 1684
1686 raise ImportError 1685 raise ImportError
1687 1686
1688 1687
1689 def resetParsedModules(): 1688 def resetParsedModules():

eric ide

mercurial