diff -r a0be29ab700a -r a7e9fd398e5a src/eric7/Utilities/ClassBrowsers/rbclbr.py --- a/src/eric7/Utilities/ClassBrowsers/rbclbr.py Thu Jan 12 11:01:36 2023 +0100 +++ b/src/eric7/Utilities/ClassBrowsers/rbclbr.py Thu Jan 12 11:41:48 2023 +0100 @@ -14,6 +14,8 @@ import re +from PyQt6.QtCore import QRegularExpression + from eric7 import Utilities from eric7.Utilities import ClassBrowsers @@ -21,7 +23,7 @@ SUPPORTED_TYPES = [ClassBrowsers.RB_SOURCE] -_getnext = re.compile( +_getnext = QRegularExpression( r""" (?P<String> =begin .*? =end @@ -157,8 +159,11 @@ end \b [^_] ) )""", - 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 @@ -314,20 +319,20 @@ i = 0 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("Method") >= 0: + if m.hasCaptured("Method"): # found a method definition or function thisindent = indent indent += 1 meth_name = ( - m.group("MethodName") - or m.group("MethodName2") - or m.group("MethodName3") + m.captured("MethodName") + or m.captured("MethodName2") + or m.captured("MethodName3") ) - meth_sig = m.group("MethodSignature") + meth_sig = m.captured("MethodSignature") meth_sig = meth_sig and meth_sig.replace("\\\n", "") or "" meth_sig = _commentsub("", meth_sig) lineno += src.count("\n", last_lineno_pos, start) @@ -382,14 +387,14 @@ classstack.append((f, thisindent)) # Marker for nested fns elif ( - m.start("String") >= 0 - or m.start("Comment") >= 0 - or m.start("ClassIgnored") >= 0 - or m.start("BeginEnd") >= 0 + m.hasCaptured("String") + or m.hasCaptured("Comment") + or m.hasCaptured("ClassIgnored") + or m.hasCaptured("BeginEnd") ): pass - elif m.start("Class") >= 0: + elif m.hasCaptured("Class"): # we found a class definition thisindent = indent indent += 1 @@ -401,8 +406,8 @@ # record the end line classstack[-1][0].setEndLine(lineno - 1) del classstack[-1] - class_name = m.group("ClassName") or m.group("ClassName2") - inherit = m.group("ClassSupers") + class_name = m.captured("ClassName") or m.captured("ClassName2") + inherit = m.captured("ClassSupers") if inherit: # the class inherits from other classes inherit = inherit[1:].strip() @@ -433,7 +438,7 @@ acstack.append(["public", thisindent]) # default access control is 'public' - elif m.start("Module") >= 0: + elif m.hasCaptured("Module"): # we found a module definition thisindent = indent indent += 1 @@ -445,7 +450,7 @@ # record the end line classstack[-1][0].setEndLine(lineno - 1) del classstack[-1] - module_name = m.group("ModuleName") + module_name = m.captured("ModuleName") # remember this class cur_class = Module(module, module_name, file, lineno) if not classstack: @@ -472,15 +477,15 @@ acstack.append(["public", thisindent]) # default access control is 'public' - elif m.start("AccessControl") >= 0: - aclist = m.group("AccessControlList") - if aclist is None: + elif m.hasCaptured("AccessControl"): + aclist = m.captured("AccessControlList") + if not aclist: index = -1 while index >= -len(acstack): if acstack[index][1] < indent: actype = ( - m.group("AccessControlType") - or m.group("AccessControlType2").split("_")[0] + m.captured("AccessControlType") + or m.captured("AccessControlType2").split("_")[0] ) acstack[index][0] = actype.lower() break @@ -496,8 +501,8 @@ ): parent = classstack[index][0] actype = ( - m.group("AccessControlType") - or m.group("AccessControlType2").split("_")[0] + m.captured("AccessControlType") + or m.captured("AccessControlType2").split("_")[0] ) actype = actype.lower() for name in aclist.split(","): @@ -515,7 +520,7 @@ else: index -= 1 - elif m.start("Attribute") >= 0: + elif m.hasCaptured("Attribute"): lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start index = -1 @@ -525,7 +530,7 @@ and not isinstance(classstack[index][0], Function) and classstack[index][1] < indent ): - attr = Attribute(module, m.group("AttributeName"), file, lineno) + attr = Attribute(module, m.captured("AttributeName"), file, lineno) classstack[index][0]._addattribute(attr) break else: @@ -534,7 +539,7 @@ lastGlobalEntry.setEndLine(lineno - 1) lastGlobalEntry = None - elif m.start("Attr") >= 0: + elif m.hasCaptured("Attr"): lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start index = -1 @@ -545,8 +550,8 @@ and classstack[index][1] < indent ): parent = classstack[index][0] - if m.group("AttrType") is None: - nv = m.group("AttrList").split(",") + if not m.captured("AttrType"): + nv = m.captured("AttrList").split(",") if not nv: break name = nv[0].strip()[1:] # get rid of leading ':' @@ -561,8 +566,8 @@ attr.setPublic() parent._addattribute(attr) else: - access = m.group("AttrType") - for name in m.group("AttrList").split(","): + access = m.captured("AttrType") + for name in m.captured("AttrList").split(","): name = name.strip()[1:] # get rid of leading ':' attr = ( parent._getattribute("@" + name) @@ -581,11 +586,11 @@ else: index -= 1 - elif m.start("Begin") >= 0: + elif m.hasCaptured("Begin"): # a begin of a block we are not interested in indent += 1 - elif m.start("End") >= 0: + elif m.hasCaptured("End"): # an end of a block indent -= 1 if indent < 0: @@ -596,9 +601,9 @@ else: indent = 0 - 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: