ModuleParser, pyclbr: fixed an issue parsing Python source files.

Sun, 21 Oct 2018 14:22:14 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 21 Oct 2018 14:22:14 +0200
changeset 6552
ea16b851fdab
parent 6551
f4adb9431204
child 6553
5006766492a5

ModuleParser, pyclbr: fixed an issue parsing Python source files.

Utilities/ClassBrowsers/pyclbr.py file | annotate | diff | comparison | revisions
Utilities/ModuleParser.py file | annotate | diff | comparison | revisions
--- 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)
--- a/Utilities/ModuleParser.py	Sat Oct 20 14:46:01 2018 +0200
+++ b/Utilities/ModuleParser.py	Sun Oct 21 14:22:14 2018 +0200
@@ -168,6 +168,11 @@
         [ \t]* = [ \t]* (?P<VariableSignal> (?:pyqtSignal)? )
     )
 
+|   (?P<Main>
+        ^
+        if \s+ __name__ \s* == \s* [^:]+ : $
+    )
+
 |   (?P<Import>
         ^ [ \t]* (?: import | from [ \t]+ \. [ \t]+ import ) [ \t]+
         (?P<ImportList> (?: [^#;\\\n]* (?: \\\n )* )* )
@@ -732,6 +737,12 @@
                     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")

eric ide

mercurial