Utilities/ClassBrowsers/pyclbr.py

changeset 6552
ea16b851fdab
parent 6048
82ad8ec9548c
child 6645
ad476851d7e0
--- a/Utilities/ClassBrowsers/pyclbr.py	Sat Oct 20 14:46:01 2018 +0200
+++ b/Utilities/ClassBrowsers/pyclbr.py	Sun Oct 21 14:22:14 2018 +0200
@@ -99,6 +99,11 @@
         [ \t]* =
     )
 
+|   (?P<Main>
+        ^
+        if \s+ __name__ \s* == \s* [^:]+ : $
+    )
+
 |   (?P<ConditionalDefine>
         ^
         (?P<ConditionalDefineIndent> [ \t]* )
@@ -562,13 +567,21 @@
                 else:
                     index -= 1
 
+        elif m.start("Main") >= 0:
+            # 'main' part of the script, reset class stack
+            lineno = lineno + src.count('\n', last_lineno_pos, start)
+            last_lineno_pos = start
+            classstack = []
+
         elif m.start("Variable") >= 0:
             thisindent = _indent(m.group("VariableIndent"))
             variable_name = m.group("VariableName")
             lineno = lineno + src.count('\n', last_lineno_pos, start)
             last_lineno_pos = start
-            if thisindent == 0:
-                # global variable
+            if thisindent == 0 or not classstack:
+                # global variable, reset class stack first
+                classstack = []
+                
                 if "@@Globals@@" not in dictionary:
                     dictionary["@@Globals@@"] = ClbrBaseClasses.ClbrBase(
                         module, "Globals", file, lineno)

eric ide

mercurial