src/eric7/Utilities/ClassBrowsers/pyclbr.py

branch
eric7
changeset 9693
a7e9fd398e5a
parent 9653
e67609152c5e
child 9733
c5c2a74e9382
--- a/src/eric7/Utilities/ClassBrowsers/pyclbr.py	Thu Jan 12 11:01:36 2023 +0100
+++ b/src/eric7/Utilities/ClassBrowsers/pyclbr.py	Thu Jan 12 11:41:48 2023 +0100
@@ -16,6 +16,8 @@
 from dataclasses import dataclass
 from functools import reduce
 
+from PyQt6.QtCore import QRegularExpression
+
 from eric7 import Utilities
 from eric7.Utilities import ClassBrowsers
 
@@ -25,7 +27,7 @@
 
 SUPPORTED_TYPES = [ClassBrowsers.PY_SOURCE, ClassBrowsers.PTL_SOURCE]
 
-_getnext = re.compile(
+_getnext = QRegularExpression(
     r"""
    (?P<CodingLine>
         ^ \# \s* [*_-]* \s* coding[:=] \s* (?P<Coding> [-\w_.]+ ) \s* [*_-]* $
@@ -135,8 +137,11 @@
             |
             (?: [^#;\\\n]* (?: \\\n )* )* )
     )""",
-    re.VERBOSE | re.DOTALL | re.MULTILINE,
-).search
+    QRegularExpression.PatternOption.MultilineOption
+    | QRegularExpression.PatternOption.DotMatchesEverythingOption
+    | QRegularExpression.PatternOption.ExtendedPatternSyntaxOption
+    | QRegularExpression.PatternOption.UseUnicodePropertiesOption,
+).match
 
 _commentsub = re.compile(r"""#[^\n]*\n|#[^\n]*$""").sub
 
@@ -445,22 +450,22 @@
     modifierIndent = -1
     while True:
         m = _getnext(src, i)
-        if not m:
+        if not m.hasMatch():
             break
-        start, i = m.span()
+        start, i = m.capturedStart(), m.capturedEnd()
 
-        if m.start("MethodModifier") >= 0:
-            modifierIndent = _indent(m.group("MethodModifierIndent"))
-            modifierType = m.group("MethodModifierType")
+        if m.hasCaptured("MethodModifier"):
+            modifierIndent = _indent(m.captured("MethodModifierIndent"))
+            modifierType = m.captured("MethodModifierType")
 
-        elif m.start("Method") >= 0:
+        elif m.hasCaptured("Method"):
             # found a method definition or function
-            thisindent = _indent(m.group("MethodIndent"))
-            meth_name = m.group("MethodName")
-            meth_sig = m.group("MethodSignature")
+            thisindent = _indent(m.captured("MethodIndent"))
+            meth_name = m.captured("MethodName")
+            meth_sig = m.captured("MethodSignature")
             meth_sig = meth_sig.replace("\\\n", "")
             meth_sig = _commentsub("", meth_sig)
-            meth_ret = m.group("MethodReturnAnnotation")
+            meth_ret = m.captured("MethodReturnAnnotation")
             meth_ret = meth_ret.replace("\\\n", "")
             meth_ret = _commentsub("", meth_ret)
             lineno += src.count("\n", last_lineno_pos, start)
@@ -534,19 +539,19 @@
             modifierType = ClbrBaseClasses.Function.General
             modifierIndent = -1
 
-        elif m.start("String") >= 0:
+        elif m.hasCaptured("String"):
             pass
 
-        elif m.start("Class") >= 0:
+        elif m.hasCaptured("Class"):
             # we found a class definition
-            thisindent = _indent(m.group("ClassIndent"))
+            thisindent = _indent(m.captured("ClassIndent"))
             # close all classes indented at least as much
             while classstack and classstack[-1][1] >= thisindent:
                 del classstack[-1]
             lineno += src.count("\n", last_lineno_pos, start)
             last_lineno_pos = start
-            class_name = m.group("ClassName")
-            inherit = m.group("ClassSupers")
+            class_name = m.captured("ClassName")
+            inherit = m.captured("ClassSupers")
             if inherit:
                 # the class inherits from other classes
                 inherit = inherit[1:-1].strip()
@@ -601,7 +606,7 @@
                 classstack[-1][0]._addclass(class_name, cur_class)
             classstack.append((cur_class, thisindent))
 
-        elif m.start("Attribute") >= 0:
+        elif m.hasCaptured("Attribute"):
             lineno += src.count("\n", last_lineno_pos, start)
             last_lineno_pos = start
             index = -1
@@ -609,21 +614,21 @@
                 if classstack[index][0] is not None and not isinstance(
                     classstack[index][0], Function
                 ):
-                    attr = Attribute(module, m.group("AttributeName"), file, lineno)
+                    attr = Attribute(module, m.captured("AttributeName"), file, lineno)
                     classstack[index][0]._addattribute(attr)
                     break
                 else:
                     index -= 1
 
-        elif m.start("Main") >= 0:
+        elif m.hasCaptured("Main"):
             # 'main' part of the script, reset class stack
             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")
+        elif m.hasCaptured("Variable"):
+            thisindent = _indent(m.captured("VariableIndent"))
+            variable_name = m.captured("VariableName")
             lineno += src.count("\n", last_lineno_pos, start)
             last_lineno_pos = start
             if thisindent == 0 or not classstack:
@@ -649,8 +654,8 @@
                             )
                         break
 
-        elif m.start("Publics") >= 0:
-            idents = m.group("Identifiers")
+        elif m.hasCaptured("Publics"):
+            idents = m.captured("Identifiers")
             lineno += src.count("\n", last_lineno_pos, start)
             last_lineno_pos = start
             pubs = Publics(
@@ -664,11 +669,11 @@
             )
             dictionary["__all__"] = pubs
 
-        elif m.start("Import") >= 0:
+        elif m.hasCaptured("Import"):
             # - import module
             names = [
                 n.strip()
-                for n in "".join(m.group("ImportList").splitlines())
+                for n in "".join(m.captured("ImportList").splitlines())
                 .replace("\\", "")
                 .split(",")
             ]
@@ -679,11 +684,11 @@
             for name in names:
                 dictionary["@@Import@@"].addImport(name, [], lineno)
 
-        elif m.start("ImportFrom") >= 0:
+        elif m.hasCaptured("ImportFrom"):
             # - from module import stuff
-            mod = m.group("ImportFromPath")
+            mod = m.captured("ImportFromPath")
             namesLines = (
-                m.group("ImportFromList")
+                m.captured("ImportFromList")
                 .replace("(", "")
                 .replace(")", "")
                 .replace("\\", "")
@@ -698,9 +703,9 @@
                 dictionary["@@Import@@"] = Imports(module, file)
             dictionary["@@Import@@"].addImport(mod, names, lineno)
 
-        elif m.start("ConditionalDefine") >= 0:
+        elif m.hasCaptured("ConditionalDefine"):
             # a conditional function/method definition
-            thisindent = _indent(m.group("ConditionalDefineIndent"))
+            thisindent = _indent(m.captured("ConditionalDefineIndent"))
             while conditionalsstack and conditionalsstack[-1] >= thisindent:
                 del conditionalsstack[-1]
                 if deltastack:
@@ -708,9 +713,9 @@
             conditionalsstack.append(thisindent)
             deltaindentcalculated = False
 
-        elif m.start("CodingLine") >= 0:
+        elif m.hasCaptured("CodingLine"):
             # a coding statement
-            coding = m.group("Coding")
+            coding = m.captured("Coding")
             lineno += src.count("\n", last_lineno_pos, start)
             last_lineno_pos = start
             if "@@Coding@@" not in dictionary:

eric ide

mercurial