Utilities/ClassBrowsers/rbclbr.py

branch
Py2 comp.
changeset 3060
5883ce99ee12
parent 3058
0a02c433f52d
parent 3039
8dd0165d805d
child 3145
a9de05d4a22f
equal deleted inserted replaced
3058:0a02c433f52d 3060:5883ce99ee12
156 end [ \t]* $ 156 end [ \t]* $
157 | 157 |
158 end \b [^_] 158 end \b [^_]
159 ) 159 )
160 ) 160 )
161 """, re.VERBOSE | re.DOTALL | re.MULTILINE).search 161 """, re.VERBOSE | re.DOTALL | re.MULTILINE).search # __IGNORE_WARNING__
162 162
163 _commentsub = re.compile(r"""#[^\n]*\n|#[^\n]*$""").sub 163 _commentsub = re.compile(r"""#[^\n]*\n|#[^\n]*$""").sub
164 164
165 _modules = {} # cache of modules we've seen 165 _modules = {} # cache of modules we've seen
166 166
302 if m.start("Method") >= 0: 302 if m.start("Method") >= 0:
303 # found a method definition or function 303 # found a method definition or function
304 thisindent = indent 304 thisindent = indent
305 indent += 1 305 indent += 1
306 meth_name = m.group("MethodName") or \ 306 meth_name = m.group("MethodName") or \
307 m.group("MethodName2") or \ 307 m.group("MethodName2") or \
308 m.group("MethodName3") 308 m.group("MethodName3")
309 meth_sig = m.group("MethodSignature") 309 meth_sig = m.group("MethodSignature")
310 meth_sig = meth_sig and meth_sig.replace('\\\n', '') or '' 310 meth_sig = meth_sig and meth_sig.replace('\\\n', '') or ''
311 meth_sig = _commentsub('', meth_sig) 311 meth_sig = _commentsub('', meth_sig)
312 lineno = lineno + src.count('\n', last_lineno_pos, start) 312 lineno = lineno + src.count('\n', last_lineno_pos, start)
313 last_lineno_pos = start 313 last_lineno_pos = start
315 meth_name = meth_name[5:] 315 meth_name = meth_name[5:]
316 elif meth_name.startswith('self::'): 316 elif meth_name.startswith('self::'):
317 meth_name = meth_name[6:] 317 meth_name = meth_name[6:]
318 # close all classes/modules indented at least as much 318 # close all classes/modules indented at least as much
319 while classstack and \ 319 while classstack and \
320 classstack[-1][1] >= thisindent: 320 classstack[-1][1] >= thisindent:
321 if classstack[-1][0] is not None: 321 if classstack[-1][0] is not None:
322 # record the end line 322 # record the end line
323 classstack[-1][0].setEndLine(lineno - 1) 323 classstack[-1][0].setEndLine(lineno - 1)
324 del classstack[-1] 324 del classstack[-1]
325 while acstack and \ 325 while acstack and \
326 acstack[-1][1] >= thisindent: 326 acstack[-1][1] >= thisindent:
327 del acstack[-1] 327 del acstack[-1]
328 if classstack: 328 if classstack:
329 # it's a class/module method 329 # it's a class/module method
330 cur_class = classstack[-1][0] 330 cur_class = classstack[-1][0]
331 if isinstance(cur_class, Class) or \ 331 if isinstance(cur_class, Class) or \
381 indent += 1 381 indent += 1
382 lineno = lineno + src.count('\n', last_lineno_pos, start) 382 lineno = lineno + src.count('\n', last_lineno_pos, start)
383 last_lineno_pos = start 383 last_lineno_pos = start
384 # close all classes/modules indented at least as much 384 # close all classes/modules indented at least as much
385 while classstack and \ 385 while classstack and \
386 classstack[-1][1] >= thisindent: 386 classstack[-1][1] >= thisindent:
387 if classstack[-1][0] is not None: 387 if classstack[-1][0] is not None:
388 # record the end line 388 # record the end line
389 classstack[-1][0].setEndLine(lineno - 1) 389 classstack[-1][0].setEndLine(lineno - 1)
390 del classstack[-1] 390 del classstack[-1]
391 class_name = m.group("ClassName") or m.group("ClassName2") 391 class_name = m.group("ClassName") or m.group("ClassName2")
415 lastGlobalEntry.setEndLine(lineno - 1) 415 lastGlobalEntry.setEndLine(lineno - 1)
416 lastGlobalEntry = cur_class 416 lastGlobalEntry = cur_class
417 cur_obj = cur_class 417 cur_obj = cur_class
418 classstack.append((cur_class, thisindent)) 418 classstack.append((cur_class, thisindent))
419 while acstack and \ 419 while acstack and \
420 acstack[-1][1] >= thisindent: 420 acstack[-1][1] >= thisindent:
421 del acstack[-1] 421 del acstack[-1]
422 acstack.append(["public", thisindent]) # default access control 422 acstack.append(["public", thisindent]) # default access control
423 # is 'public' 423 # is 'public'
424 424
425 elif m.start("Module") >= 0: 425 elif m.start("Module") >= 0:
428 indent += 1 428 indent += 1
429 lineno = lineno + src.count('\n', last_lineno_pos, start) 429 lineno = lineno + src.count('\n', last_lineno_pos, start)
430 last_lineno_pos = start 430 last_lineno_pos = start
431 # close all classes/modules indented at least as much 431 # close all classes/modules indented at least as much
432 while classstack and \ 432 while classstack and \
433 classstack[-1][1] >= thisindent: 433 classstack[-1][1] >= thisindent:
434 if classstack[-1][0] is not None: 434 if classstack[-1][0] is not None:
435 # record the end line 435 # record the end line
436 classstack[-1][0].setEndLine(lineno - 1) 436 classstack[-1][0].setEndLine(lineno - 1)
437 del classstack[-1] 437 del classstack[-1]
438 module_name = m.group("ModuleName") 438 module_name = m.group("ModuleName")
456 lastGlobalEntry.setEndLine(lineno - 1) 456 lastGlobalEntry.setEndLine(lineno - 1)
457 lastGlobalEntry = cur_class 457 lastGlobalEntry = cur_class
458 cur_obj = cur_class 458 cur_obj = cur_class
459 classstack.append((cur_class, thisindent)) 459 classstack.append((cur_class, thisindent))
460 while acstack and \ 460 while acstack and \
461 acstack[-1][1] >= thisindent: 461 acstack[-1][1] >= thisindent:
462 del acstack[-1] 462 del acstack[-1]
463 acstack.append(["public", thisindent]) # default access control 463 acstack.append(["public", thisindent]) # default access control
464 # is 'public' 464 # is 'public'
465 465
466 elif m.start("AccessControl") >= 0: 466 elif m.start("AccessControl") >= 0:
468 if aclist is None: 468 if aclist is None:
469 index = -1 469 index = -1
470 while index >= -len(acstack): 470 while index >= -len(acstack):
471 if acstack[index][1] < indent: 471 if acstack[index][1] < indent:
472 actype = m.group("AccessControlType") or \ 472 actype = m.group("AccessControlType") or \
473 m.group("AccessControlType2").split('_')[0] 473 m.group("AccessControlType2").split('_')[0]
474 acstack[index][0] = actype.lower() 474 acstack[index][0] = actype.lower()
475 break 475 break
476 else: 476 else:
477 index -= 1 477 index -= 1
478 else: 478 else:
481 if classstack[index][0] is not None and \ 481 if classstack[index][0] is not None and \
482 not isinstance(classstack[index][0], Function) and \ 482 not isinstance(classstack[index][0], Function) and \
483 not classstack[index][1] >= indent: 483 not classstack[index][1] >= indent:
484 parent = classstack[index][0] 484 parent = classstack[index][0]
485 actype = m.group("AccessControlType") or \ 485 actype = m.group("AccessControlType") or \
486 m.group("AccessControlType2").split('_')[0] 486 m.group("AccessControlType2").split('_')[0]
487 actype = actype.lower() 487 actype = actype.lower()
488 for name in aclist.split(","): 488 for name in aclist.split(","):
489 name = name.strip()[1:] # get rid of leading ':' 489 name = name.strip()[1:] # get rid of leading ':'
490 acmeth = parent._getmethod(name) 490 acmeth = parent._getmethod(name)
491 if acmeth is None: 491 if acmeth is None:
531 nv = m.group("AttrList").split(",") 531 nv = m.group("AttrList").split(",")
532 if not nv: 532 if not nv:
533 break 533 break
534 name = nv[0].strip()[1:] # get rid of leading ':' 534 name = nv[0].strip()[1:] # get rid of leading ':'
535 attr = parent._getattribute("@" + name) or \ 535 attr = parent._getattribute("@" + name) or \
536 parent._getattribute("@@" + name) or \ 536 parent._getattribute("@@" + name) or \
537 Attribute(module, "@" + name, file, lineno) 537 Attribute(module, "@" + name, file, lineno)
538 if len(nv) == 1 or nv[1].strip() == "false": 538 if len(nv) == 1 or nv[1].strip() == "false":
539 attr.setProtected() 539 attr.setProtected()
540 elif nv[1].strip() == "true": 540 elif nv[1].strip() == "true":
541 attr.setPublic() 541 attr.setPublic()
542 parent._addattribute(attr) 542 parent._addattribute(attr)
543 else: 543 else:
544 access = m.group("AttrType") 544 access = m.group("AttrType")
545 for name in m.group("AttrList").split(","): 545 for name in m.group("AttrList").split(","):
546 name = name.strip()[1:] # get rid of leading ':' 546 name = name.strip()[1:] # get rid of leading ':'
547 attr = parent._getattribute("@" + name) or \ 547 attr = parent._getattribute("@" + name) or \
548 parent._getattribute("@@" + name) or \ 548 parent._getattribute("@@" + name) or \
549 Attribute(module, "@" + name, file, lineno) 549 Attribute(module, "@" + name, file, lineno)
550 if access == "_accessor": 550 if access == "_accessor":
551 attr.setPublic() 551 attr.setPublic()
552 elif access == "_reader" or access == "_writer": 552 elif access == "_reader" or access == "_writer":
553 if attr.isPrivate(): 553 if attr.isPrivate():
554 attr.setProtected() 554 attr.setProtected()

eric ide

mercurial