Utilities/ModuleParser.py

changeset 3966
969a3d41c402
parent 3656
441956d8fce5
child 4021
195a471c327b
equal deleted inserted replaced
3962:b75057280077 3966:969a3d41c402
137 def [ \t]+ 137 def [ \t]+
138 (?P<MethodName> \w+ ) 138 (?P<MethodName> \w+ )
139 (?: [ \t]* \[ (?: plain | html ) \] )? 139 (?: [ \t]* \[ (?: plain | html ) \] )?
140 [ \t]* \( 140 [ \t]* \(
141 (?P<MethodSignature> (?: [^)] | \)[ \t]*,? )*? ) 141 (?P<MethodSignature> (?: [^)] | \)[ \t]*,? )*? )
142 \) [ \t]* : 142 \) [ \t]*
143 (?P<MethodReturnAnnotation> (?: -> [ \t]* [^:]+ )? )
144 [ \t]* :
143 ) 145 )
144 146
145 | (?P<Class> 147 | (?P<Class>
146 ^ 148 ^
147 (?P<ClassIndent> [ \t]* ) 149 (?P<ClassIndent> [ \t]* )
536 # found a method definition or function 538 # found a method definition or function
537 thisindent = _indent(m.group("MethodIndent")) 539 thisindent = _indent(m.group("MethodIndent"))
538 meth_name = m.group("MethodName") 540 meth_name = m.group("MethodName")
539 meth_sig = m.group("MethodSignature") 541 meth_sig = m.group("MethodSignature")
540 meth_sig = meth_sig.replace('\\\n', '') 542 meth_sig = meth_sig.replace('\\\n', '')
543 meth_ret = m.group("MethodReturnAnnotation")
544 meth_ret = meth_ret.replace('\\\n', '')
541 if m.group("MethodPyQtSignature") is not None: 545 if m.group("MethodPyQtSignature") is not None:
542 meth_pyqtSig = m.group("MethodPyQtSignature")\ 546 meth_pyqtSig = m.group("MethodPyQtSignature")\
543 .replace('\\\n', '')\ 547 .replace('\\\n', '')\
544 .split('result')[0]\ 548 .split('result')[0]\
545 .split('name')[0]\ 549 .split('name')[0]\
593 597
594 if isinstance(cur_class, Class): 598 if isinstance(cur_class, Class):
595 # it's a class method 599 # it's a class method
596 f = Function( 600 f = Function(
597 None, meth_name, None, lineno, 601 None, meth_name, None, lineno,
598 meth_sig, meth_pyqtSig, modifierType=modifier) 602 meth_sig, meth_pyqtSig, modifierType=modifier,
603 annotation=meth_ret)
599 self.__py_setVisibility(f) 604 self.__py_setVisibility(f)
600 cur_class.addMethod(meth_name, f) 605 cur_class.addMethod(meth_name, f)
601 break 606 break
602 else: 607 else:
603 # it's a nested function of a module function 608 # it's a nested function of a module function
604 f = Function( 609 f = Function(
605 self.name, meth_name, self.file, lineno, 610 self.name, meth_name, self.file, lineno,
606 meth_sig, meth_pyqtSig, modifierType=modifier) 611 meth_sig, meth_pyqtSig, modifierType=modifier,
612 annotation=meth_ret)
607 self.__py_setVisibility(f) 613 self.__py_setVisibility(f)
608 self.addFunction(meth_name, f) 614 self.addFunction(meth_name, f)
609 else: 615 else:
610 # it's a module function 616 # it's a module function
611 f = Function(self.name, meth_name, self.file, lineno, 617 f = Function(self.name, meth_name, self.file, lineno,
612 meth_sig, meth_pyqtSig, modifierType=modifier) 618 meth_sig, meth_pyqtSig, modifierType=modifier,
619 annotation=meth_ret)
613 self.__py_setVisibility(f) 620 self.__py_setVisibility(f)
614 self.addFunction(meth_name, f) 621 self.addFunction(meth_name, f)
615 if not classstack: 622 if not classstack:
616 if lastGlobalEntry: 623 if lastGlobalEntry:
617 lastGlobalEntry.setEndLine(lineno - 1) 624 lastGlobalEntry.setEndLine(lineno - 1)
1352 General = 0 1359 General = 0
1353 Static = 1 1360 Static = 1
1354 Class = 2 1361 Class = 2
1355 1362
1356 def __init__(self, module, name, file, lineno, signature='', 1363 def __init__(self, module, name, file, lineno, signature='',
1357 pyqtSignature=None, modifierType=General): 1364 pyqtSignature=None, modifierType=General, annotation=""):
1358 """ 1365 """
1359 Constructor 1366 Constructor
1360 1367
1361 @param module name of module containing this function (string) 1368 @param module name of module containing this function (string)
1362 @param name name of the function (string) 1369 @param name name of the function (string)
1363 @param file name of file containing this function (string) 1370 @param file name of file containing this function (string)
1364 @param lineno linenumber of the function definition (integer) 1371 @param lineno linenumber of the function definition (integer)
1365 @param signature the functions call signature (string) 1372 @param signature the functions call signature (string)
1366 @param pyqtSignature the functions PyQt signature (string) 1373 @param pyqtSignature the functions PyQt signature (string)
1367 @param modifierType type of the function 1374 @param modifierType type of the function
1375 @param annotation return annotation
1368 """ 1376 """
1369 self.module = module 1377 self.module = module
1370 self.name = name 1378 self.name = name
1371 self.file = file 1379 self.file = file
1372 self.lineno = lineno 1380 self.lineno = lineno
1374 signature = _commentsub('', signature) 1382 signature = _commentsub('', signature)
1375 self.parameters = [e.strip() for e in signature.split(',')] 1383 self.parameters = [e.strip() for e in signature.split(',')]
1376 self.description = "" 1384 self.description = ""
1377 self.pyqtSignature = pyqtSignature 1385 self.pyqtSignature = pyqtSignature
1378 self.modifier = modifierType 1386 self.modifier = modifierType
1387 self.annotation = annotation
1379 self.setPublic() 1388 self.setPublic()
1380 1389
1381 def addDescription(self, description): 1390 def addDescription(self, description):
1382 """ 1391 """
1383 Public method to store the functions docstring. 1392 Public method to store the functions docstring.

eric ide

mercurial