Utilities/ModuleParser.py

changeset 1227
c5db073a124f
parent 945
8cd4d08fa9f6
child 1229
a8207dc73672
equal deleted inserted replaced
1225:254ec677c775 1227:c5db073a124f
90 (?: \\. | \#(?!\#\#) ) 90 (?: \\. | \#(?!\#\#) )
91 [^#\\]* 91 [^#\\]*
92 )* 92 )*
93 ) 93 )
94 \#\#\# 94 \#\#\#
95 )
96
97 | (?P<MethodModifier>
98 ^
99 (?P<MethodModifierIndent> [ \t]* )
100 (?P<MethodModifierType> @classmethod | @staticmethod )
95 ) 101 )
96 102
97 | (?P<Method> 103 | (?P<Method>
98 (^ [ \t]* @ (?: PyQt4 \. )? (?: QtCore \. )? (?: pyqtSignature | pyqtSlot ) 104 (^ [ \t]* @ (?: PyQt4 \. )? (?: QtCore \. )? (?: pyqtSignature | pyqtSlot )
99 [ \t]* \( 105 [ \t]* \(
477 deltaindent = 0 483 deltaindent = 0
478 deltaindentcalculated = 0 484 deltaindentcalculated = 0
479 i = 0 485 i = 0
480 modulelevel = 1 486 modulelevel = 1
481 cur_obj = self 487 cur_obj = self
488 modifierType = Function.General
489 modifierIndent = -1
482 while True: 490 while True:
483 m = self._getnext(src, i) 491 m = self._getnext(src, i)
484 if not m: 492 if not m:
485 break 493 break
486 start, i = m.span() 494 start, i = m.span()
487 495
488 if m.start("Method") >= 0: 496 if m.start("MethodModifier") >= 0:
497 modifierIndent = _indent(m.group("MethodModifierIndent"))
498 modifierType = m.group("MethodModifierType")
499 elif m.start("Method") >= 0:
489 # found a method definition or function 500 # found a method definition or function
490 thisindent = _indent(m.group("MethodIndent")) 501 thisindent = _indent(m.group("MethodIndent"))
491 meth_name = m.group("MethodName") 502 meth_name = m.group("MethodName")
492 meth_sig = m.group("MethodSignature") 503 meth_sig = m.group("MethodSignature")
493 meth_sig = meth_sig.replace('\\\n', '') 504 meth_sig = meth_sig.replace('\\\n', '')
499 .strip("\"', \t") 510 .strip("\"', \t")
500 else: 511 else:
501 meth_pyqtSig = None 512 meth_pyqtSig = None
502 lineno = lineno + src.count('\n', last_lineno_pos, start) 513 lineno = lineno + src.count('\n', last_lineno_pos, start)
503 last_lineno_pos = start 514 last_lineno_pos = start
515 if modifierType and modifierIndent == thisindent:
516 if modifierType == "@staticmethod":
517 modifier = Function.Static
518 elif modifierType == "@classmethod":
519 modifier = Function.Class
520 else:
521 modifier = Function.General
522 else:
523 modifier = Function.General
504 # modify indentation level for conditional defines 524 # modify indentation level for conditional defines
505 if conditionalsstack: 525 if conditionalsstack:
506 if thisindent > conditionalsstack[-1]: 526 if thisindent > conditionalsstack[-1]:
507 if not deltaindentcalculated: 527 if not deltaindentcalculated:
508 deltastack.append(thisindent - conditionalsstack[-1]) 528 deltastack.append(thisindent - conditionalsstack[-1])
536 continue 556 continue
537 557
538 if isinstance(cur_class, Class): 558 if isinstance(cur_class, Class):
539 # it's a class method 559 # it's a class method
540 f = Function(None, meth_name, None, lineno, 560 f = Function(None, meth_name, None, lineno,
541 meth_sig, meth_pyqtSig) 561 meth_sig, meth_pyqtSig, modifierType=modifier)
542 self.__py_setVisibility(f) 562 self.__py_setVisibility(f)
543 cur_class.addMethod(meth_name, f) 563 cur_class.addMethod(meth_name, f)
544 break 564 break
545 else: 565 else:
546 # it's a nested function of a module function 566 # it's a nested function of a module function
547 f = Function(self.name, meth_name, self.file, lineno, 567 f = Function(self.name, meth_name, self.file, lineno,
548 meth_sig, meth_pyqtSig) 568 meth_sig, meth_pyqtSig, modifierType=modifier)
549 self.__py_setVisibility(f) 569 self.__py_setVisibility(f)
550 self.addFunction(meth_name, f) 570 self.addFunction(meth_name, f)
551 else: 571 else:
552 # it's a module function 572 # it's a module function
553 f = Function(self.name, meth_name, self.file, lineno, 573 f = Function(self.name, meth_name, self.file, lineno,
554 meth_sig, meth_pyqtSig) 574 meth_sig, meth_pyqtSig, modifierType=modifier)
555 self.__py_setVisibility(f) 575 self.__py_setVisibility(f)
556 self.addFunction(meth_name, f) 576 self.addFunction(meth_name, f)
557 cur_obj = f 577 cur_obj = f
558 classstack.append((None, thisindent)) # Marker for nested fns 578 classstack.append((None, thisindent)) # Marker for nested fns
579
580 # reset the modifier settings
581 modifierType = Function.General
582 modifierIndent = -1
559 583
560 elif m.start("Docstring") >= 0: 584 elif m.start("Docstring") >= 0:
561 contents = m.group("DocstringContents3") 585 contents = m.group("DocstringContents3")
562 if contents is not None: 586 if contents is not None:
563 contents = _hashsub(r"\1", contents) 587 contents = _hashsub(r"\1", contents)
1214 1238
1215 class Function(VisibilityBase): 1239 class Function(VisibilityBase):
1216 ''' 1240 '''
1217 Class to represent a Python function or method. 1241 Class to represent a Python function or method.
1218 ''' 1242 '''
1219 def __init__(self, module, name, file, lineno, signature='', pyqtSignature=None): 1243 General = 0
1244 Static = 1
1245 Class = 2
1246
1247 def __init__(self, module, name, file, lineno, signature='', pyqtSignature=None,
1248 modifierType=General):
1220 """ 1249 """
1221 Constructor 1250 Constructor
1222 1251
1223 @param module name of module containing this function (string) 1252 @param module name of module containing this function (string)
1224 @param name name of the function (string) 1253 @param name name of the function (string)
1225 @param file name of file containing this function (string) 1254 @param file name of file containing this function (string)
1226 @param lineno linenumber of the function definition (integer) 1255 @param lineno linenumber of the function definition (integer)
1227 @param signature the functions call signature (string) 1256 @param signature the functions call signature (string)
1228 @param pyqtSignature the functions PyQt signature (string) 1257 @param pyqtSignature the functions PyQt signature (string)
1258 @param modifierType type of the function
1229 """ 1259 """
1230 self.module = module 1260 self.module = module
1231 self.name = name 1261 self.name = name
1232 self.file = file 1262 self.file = file
1233 self.lineno = lineno 1263 self.lineno = lineno
1234 signature = _commentsub('', signature) 1264 signature = _commentsub('', signature)
1235 self.parameters = [e.strip() for e in signature.split(',')] 1265 self.parameters = [e.strip() for e in signature.split(',')]
1236 self.description = "" 1266 self.description = ""
1237 self.pyqtSignature = pyqtSignature 1267 self.pyqtSignature = pyqtSignature
1268 self.modifier = modifierType
1238 self.setPublic() 1269 self.setPublic()
1239 1270
1240 def addDescription(self, description): 1271 def addDescription(self, description):
1241 """ 1272 """
1242 Public method to store the functions docstring. 1273 Public method to store the functions docstring.

eric ide

mercurial