src/eric7/Utilities/ClassBrowsers/pyclbr.py

branch
eric7
changeset 9733
c5c2a74e9382
parent 9693
a7e9fd398e5a
child 10050
3750abc45d5e
equal deleted inserted replaced
9732:3985549d7d36 9733:c5c2a74e9382
452 m = _getnext(src, i) 452 m = _getnext(src, i)
453 if not m.hasMatch(): 453 if not m.hasMatch():
454 break 454 break
455 start, i = m.capturedStart(), m.capturedEnd() 455 start, i = m.capturedStart(), m.capturedEnd()
456 456
457 if m.hasCaptured("MethodModifier"): 457 if m.captured("MethodModifier"):
458 modifierIndent = _indent(m.captured("MethodModifierIndent")) 458 modifierIndent = _indent(m.captured("MethodModifierIndent"))
459 modifierType = m.captured("MethodModifierType") 459 modifierType = m.captured("MethodModifierType")
460 460
461 elif m.hasCaptured("Method"): 461 elif m.captured("Method"):
462 # found a method definition or function 462 # found a method definition or function
463 thisindent = _indent(m.captured("MethodIndent")) 463 thisindent = _indent(m.captured("MethodIndent"))
464 meth_name = m.captured("MethodName") 464 meth_name = m.captured("MethodName")
465 meth_sig = m.captured("MethodSignature") 465 meth_sig = m.captured("MethodSignature")
466 meth_sig = meth_sig.replace("\\\n", "") 466 meth_sig = meth_sig.replace("\\\n", "")
537 537
538 # reset the modifier settings 538 # reset the modifier settings
539 modifierType = ClbrBaseClasses.Function.General 539 modifierType = ClbrBaseClasses.Function.General
540 modifierIndent = -1 540 modifierIndent = -1
541 541
542 elif m.hasCaptured("String"): 542 elif m.captured("String"):
543 pass 543 pass
544 544
545 elif m.hasCaptured("Class"): 545 elif m.captured("Class"):
546 # we found a class definition 546 # we found a class definition
547 thisindent = _indent(m.captured("ClassIndent")) 547 thisindent = _indent(m.captured("ClassIndent"))
548 # close all classes indented at least as much 548 # close all classes indented at least as much
549 while classstack and classstack[-1][1] >= thisindent: 549 while classstack and classstack[-1][1] >= thisindent:
550 del classstack[-1] 550 del classstack[-1]
604 dictionary[class_name] = cur_class 604 dictionary[class_name] = cur_class
605 else: 605 else:
606 classstack[-1][0]._addclass(class_name, cur_class) 606 classstack[-1][0]._addclass(class_name, cur_class)
607 classstack.append((cur_class, thisindent)) 607 classstack.append((cur_class, thisindent))
608 608
609 elif m.hasCaptured("Attribute"): 609 elif m.captured("Attribute"):
610 lineno += src.count("\n", last_lineno_pos, start) 610 lineno += src.count("\n", last_lineno_pos, start)
611 last_lineno_pos = start 611 last_lineno_pos = start
612 index = -1 612 index = -1
613 while index >= -len(classstack): 613 while index >= -len(classstack):
614 if classstack[index][0] is not None and not isinstance( 614 if classstack[index][0] is not None and not isinstance(
618 classstack[index][0]._addattribute(attr) 618 classstack[index][0]._addattribute(attr)
619 break 619 break
620 else: 620 else:
621 index -= 1 621 index -= 1
622 622
623 elif m.hasCaptured("Main"): 623 elif m.captured("Main"):
624 # 'main' part of the script, reset class stack 624 # 'main' part of the script, reset class stack
625 lineno += src.count("\n", last_lineno_pos, start) 625 lineno += src.count("\n", last_lineno_pos, start)
626 last_lineno_pos = start 626 last_lineno_pos = start
627 classstack = [] 627 classstack = []
628 628
629 elif m.hasCaptured("Variable"): 629 elif m.captured("Variable"):
630 thisindent = _indent(m.captured("VariableIndent")) 630 thisindent = _indent(m.captured("VariableIndent"))
631 variable_name = m.captured("VariableName") 631 variable_name = m.captured("VariableName")
632 lineno += src.count("\n", last_lineno_pos, start) 632 lineno += src.count("\n", last_lineno_pos, start)
633 last_lineno_pos = start 633 last_lineno_pos = start
634 if thisindent == 0 or not classstack: 634 if thisindent == 0 or not classstack:
652 classstack[index][0]._addglobal( 652 classstack[index][0]._addglobal(
653 Attribute(module, variable_name, file, lineno) 653 Attribute(module, variable_name, file, lineno)
654 ) 654 )
655 break 655 break
656 656
657 elif m.hasCaptured("Publics"): 657 elif m.captured("Publics"):
658 idents = m.captured("Identifiers") 658 idents = m.captured("Identifiers")
659 lineno += src.count("\n", last_lineno_pos, start) 659 lineno += src.count("\n", last_lineno_pos, start)
660 last_lineno_pos = start 660 last_lineno_pos = start
661 pubs = Publics( 661 pubs = Publics(
662 module=module, 662 module=module,
667 for e in idents.split(",") 667 for e in idents.split(",")
668 ], 668 ],
669 ) 669 )
670 dictionary["__all__"] = pubs 670 dictionary["__all__"] = pubs
671 671
672 elif m.hasCaptured("Import"): 672 elif m.captured("Import"):
673 # - import module 673 # - import module
674 names = [ 674 names = [
675 n.strip() 675 n.strip()
676 for n in "".join(m.captured("ImportList").splitlines()) 676 for n in "".join(m.captured("ImportList").splitlines())
677 .replace("\\", "") 677 .replace("\\", "")
682 if "@@Import@@" not in dictionary: 682 if "@@Import@@" not in dictionary:
683 dictionary["@@Import@@"] = Imports(module, file) 683 dictionary["@@Import@@"] = Imports(module, file)
684 for name in names: 684 for name in names:
685 dictionary["@@Import@@"].addImport(name, [], lineno) 685 dictionary["@@Import@@"].addImport(name, [], lineno)
686 686
687 elif m.hasCaptured("ImportFrom"): 687 elif m.captured("ImportFrom"):
688 # - from module import stuff 688 # - from module import stuff
689 mod = m.captured("ImportFromPath") 689 mod = m.captured("ImportFromPath")
690 namesLines = ( 690 namesLines = (
691 m.captured("ImportFromList") 691 m.captured("ImportFromList")
692 .replace("(", "") 692 .replace("(", "")
701 last_lineno_pos = start 701 last_lineno_pos = start
702 if "@@Import@@" not in dictionary: 702 if "@@Import@@" not in dictionary:
703 dictionary["@@Import@@"] = Imports(module, file) 703 dictionary["@@Import@@"] = Imports(module, file)
704 dictionary["@@Import@@"].addImport(mod, names, lineno) 704 dictionary["@@Import@@"].addImport(mod, names, lineno)
705 705
706 elif m.hasCaptured("ConditionalDefine"): 706 elif m.captured("ConditionalDefine"):
707 # a conditional function/method definition 707 # a conditional function/method definition
708 thisindent = _indent(m.captured("ConditionalDefineIndent")) 708 thisindent = _indent(m.captured("ConditionalDefineIndent"))
709 while conditionalsstack and conditionalsstack[-1] >= thisindent: 709 while conditionalsstack and conditionalsstack[-1] >= thisindent:
710 del conditionalsstack[-1] 710 del conditionalsstack[-1]
711 if deltastack: 711 if deltastack:
712 del deltastack[-1] 712 del deltastack[-1]
713 conditionalsstack.append(thisindent) 713 conditionalsstack.append(thisindent)
714 deltaindentcalculated = False 714 deltaindentcalculated = False
715 715
716 elif m.hasCaptured("CodingLine"): 716 elif m.captured("CodingLine"):
717 # a coding statement 717 # a coding statement
718 coding = m.captured("Coding") 718 coding = m.captured("Coding")
719 lineno += src.count("\n", last_lineno_pos, start) 719 lineno += src.count("\n", last_lineno_pos, start)
720 last_lineno_pos = start 720 last_lineno_pos = start
721 if "@@Coding@@" not in dictionary: 721 if "@@Coding@@" not in dictionary:

eric ide

mercurial