--- a/src/eric7/Utilities/ModuleParser.py Thu Feb 02 18:01:00 2023 +0100 +++ b/src/eric7/Utilities/ModuleParser.py Mon Feb 06 10:02:35 2023 +0100 @@ -22,8 +22,6 @@ from functools import reduce -from PyQt6.QtCore import QRegularExpression - from eric7 import Utilities __all__ = [ @@ -66,7 +64,7 @@ return -1 -_py_getnext = QRegularExpression( +_py_getnext = re.compile( r""" (?P<Comment> \# .*? $ # ignore everything in comments @@ -214,13 +212,10 @@ (?: (?: if | elif ) [ \t]+ [^:]* | else [ \t]* ) : (?= \s* (?: async [ \t]+ )? def) )""", - QRegularExpression.PatternOption.MultilineOption - | QRegularExpression.PatternOption.DotMatchesEverythingOption - | QRegularExpression.PatternOption.ExtendedPatternSyntaxOption - | QRegularExpression.PatternOption.UseUnicodePropertiesOption, -).match + re.VERBOSE | re.DOTALL | re.MULTILINE, +).search -_rb_getnext = QRegularExpression( +_rb_getnext = re.compile( r""" (?P<Docstring> =begin [ \t]+ edoc (?P<DocstringContents> .*? ) =end @@ -355,11 +350,8 @@ end \b [^_] ) )""", - QRegularExpression.PatternOption.MultilineOption - | QRegularExpression.PatternOption.DotMatchesEverythingOption - | QRegularExpression.PatternOption.ExtendedPatternSyntaxOption - | QRegularExpression.PatternOption.UseUnicodePropertiesOption, -).match + re.VERBOSE | re.DOTALL | re.MULTILINE, +).search _hashsub = re.compile(r"""^([ \t]*)#[ \t]?""", re.MULTILINE).sub @@ -589,25 +581,25 @@ modifierIndent = -1 while True: m = self._getnext(src, i) - if not m.hasMatch(): + if not m: break - start, i = m.capturedStart(), m.capturedEnd() + start, i = m.span() - if m.captured("MethodModifier"): - modifierIndent = _indent(m.captured("MethodModifierIndent")) - modifierType = m.captured("MethodModifierType") + if m.start("MethodModifier") >= 0: + modifierIndent = _indent(m.group("MethodModifierIndent")) + modifierType = m.group("MethodModifierType") - elif m.captured("Method"): + elif m.start("Method") >= 0: # found a method definition or function - thisindent = _indent(m.captured("MethodIndent")) - meth_name = m.captured("MethodName") - meth_sig = m.captured("MethodSignature") + thisindent = _indent(m.group("MethodIndent")) + meth_name = m.group("MethodName") + meth_sig = m.group("MethodSignature") meth_sig = meth_sig.replace("\\\n", "") - meth_ret = m.captured("MethodReturnAnnotation") + meth_ret = m.group("MethodReturnAnnotation") meth_ret = meth_ret.replace("\\\n", "") - if m.captured("MethodPyQtSignature"): + if m.group("MethodPyQtSignature") is not None: meth_pyqtSig = ( - m.captured("MethodPyQtSignature") + m.group("MethodPyQtSignature") .replace("\\\n", "") .split("result")[0] .split("name")[0] @@ -704,49 +696,49 @@ modifierType = Function.General modifierIndent = -1 - elif m.captured("Docstring"): - contents = m.captured("DocstringContents3") - if contents: + elif m.start("Docstring") >= 0: + contents = m.group("DocstringContents3") + if contents is not None: contents = _hashsub(r"\1", contents) else: if self.file.lower().endswith(".ptl"): contents = "" else: - contents = m.captured("DocstringContents1") or m.captured( + contents = m.group("DocstringContents1") or m.group( "DocstringContents2" ) if cur_obj: cur_obj.addDescription(contents) - elif m.captured("String"): + elif m.start("String") >= 0: if modulelevel and ( src[start - len("\r\n") : start] == "\r\n" or src[start - len("\n") : start] == "\n" or src[start - len("\r") : start] == "\r" ): - contents = m.captured("StringContents3") - if contents: + contents = m.group("StringContents3") + if contents is not None: contents = _hashsub(r"\1", contents) else: if self.file.lower().endswith(".ptl"): contents = "" else: - contents = m.captured("StringContents1") or m.captured( + contents = m.group("StringContents1") or m.group( "StringContents2" ) if cur_obj: cur_obj.addDescription(contents) - elif m.captured("Class"): + elif m.start("Class") >= 0: # we found a class definition - thisindent = _indent(m.captured("ClassIndent")) + thisindent = _indent(m.group("ClassIndent")) lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start # close all classes indented at least as much while classstack and classstack[-1][1] >= thisindent: del classstack[-1] - class_name = m.captured("ClassName") - inherit = m.captured("ClassSupers") + class_name = m.group("ClassName") + inherit = m.group("ClassSupers") if inherit: # the class inherits from other classes inherit = inherit[1:-1].strip() @@ -795,13 +787,13 @@ # add nested classes to the module classstack.append((cur_class, thisindent)) - elif m.captured("Attribute"): + elif m.start("Attribute") >= 0: lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start index = -1 while index >= -len(classstack): if classstack[index][0] is not None: - attrName = m.captured("AttributeName") + attrName = m.group("AttributeName") attr = Attribute(self.name, attrName, self.file, lineno) self.__py_setVisibility(attr) classstack[index][0].addAttribute(attrName, attr) @@ -809,16 +801,16 @@ else: index -= 1 - elif m.captured("Main"): + elif m.start("Main") >= 0: # 'main' part of the script, reset class stack lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start classstack = [] - elif m.captured("Variable"): - thisindent = _indent(m.captured("VariableIndent")) - variable_name = m.captured("VariableName") - isSignal = m.captured("VariableSignal") != "" + elif m.start("Variable") >= 0: + thisindent = _indent(m.group("VariableIndent")) + variable_name = m.group("VariableName") + isSignal = m.group("VariableSignal") != "" lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start if thisindent == 0: @@ -848,11 +840,11 @@ classstack[index][0].addGlobal(variable_name, attr) break - elif m.captured("Import"): + elif m.start("Import") >= 0: # - import module names = [ n.strip() - for n in "".join(m.captured("ImportList").splitlines()) + for n in "".join(m.group("ImportList").splitlines()) .replace("\\", "") .split(",") ] @@ -860,11 +852,11 @@ [name for name in names if name not in self.imports] ) - elif m.captured("ImportFrom"): + elif m.start("ImportFrom") >= 0: # - from module import stuff - mod = m.captured("ImportFromPath") + mod = m.group("ImportFromPath") namesLines = ( - m.captured("ImportFromList") + m.group("ImportFromList") .replace("(", "") .replace(")", "") .replace("\\", "") @@ -879,9 +871,9 @@ [name for name in names if name not in self.from_imports[mod]] ) - elif m.captured("ConditionalDefine"): + elif m.start("ConditionalDefine") >= 0: # a conditional function/method definition - thisindent = _indent(m.captured("ConditionalDefineIndent")) + thisindent = _indent(m.group("ConditionalDefineIndent")) while conditionalsstack and conditionalsstack[-1] >= thisindent: del conditionalsstack[-1] if deltastack: @@ -889,7 +881,7 @@ conditionalsstack.append(thisindent) deltaindentcalculated = 0 - elif m.captured("Comment") and modulelevel: + elif m.start("Comment") >= 0 and modulelevel: continue modulelevel = False @@ -911,20 +903,20 @@ lastGlobalEntry = None while True: m = self._getnext(src, i) - if not m.hasMatch(): + if not m: break - start, i = m.capturedStart(), m.capturedEnd() + start, i = m.span() - if m.captured("Method"): + if m.start("Method") >= 0: # found a method definition or function thisindent = indent indent += 1 meth_name = ( - m.captured("MethodName") - or m.captured("MethodName2") - or m.captured("MethodName3") + m.group("MethodName") + or m.group("MethodName2") + or m.group("MethodName3") ) - meth_sig = m.captured("MethodSignature") + meth_sig = m.group("MethodSignature") meth_sig = meth_sig and meth_sig.replace("\\\n", "") or "" lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start @@ -982,14 +974,14 @@ cur_obj = f classstack.append((None, thisindent)) # Marker for nested fns - elif m.captured("Docstring"): - contents = m.captured("DocstringContents") - if contents: + elif m.start("Docstring") >= 0: + contents = m.group("DocstringContents") + if contents is not None: contents = _hashsub(r"\1", contents) if cur_obj: cur_obj.addDescription(contents) - elif m.captured("Class"): + elif m.start("Class") >= 0: # we found a class definition thisindent = indent indent += 1 @@ -1003,8 +995,8 @@ # record the end line of this class, function or module classstack[-1][0].setEndLine(lineno - 1) del classstack[-1] - class_name = m.captured("ClassName") or m.captured("ClassName2") - inherit = m.captured("ClassSupers") + class_name = m.group("ClassName") or m.group("ClassName2") + inherit = m.group("ClassSupers") if inherit: # the class inherits from other classes inherit = inherit[1:].strip() @@ -1037,7 +1029,7 @@ acstack.append(["public", thisindent]) # default access control is 'public' - elif m.captured("Module"): + elif m.start("Module") >= 0: # we found a module definition thisindent = indent indent += 1 @@ -1051,7 +1043,7 @@ # record the end line of this class, function or module classstack[-1][0].setEndLine(lineno - 1) del classstack[-1] - module_name = m.captured("ModuleName") + module_name = m.group("ModuleName") # remember this class cur_class = RbModule(self.name, module_name, self.file, lineno) # add nested Ruby modules to the file @@ -1070,15 +1062,15 @@ acstack.append(["public", thisindent]) # default access control is 'public' - elif m.captured("AccessControl"): - aclist = m.captured("AccessControlList") - if not aclist: + elif m.start("AccessControl") >= 0: + aclist = m.group("AccessControlList") + if aclist is None: index = -1 while index >= -len(acstack): if acstack[index][1] < indent: actype = ( - m.captured("AccessControlType") - or m.captured("AccessControlType2").split("_")[0] + m.group("AccessControlType") + or m.group("AccessControlType2").split("_")[0] ) acstack[index][0] = actype.lower() break @@ -1094,8 +1086,8 @@ ): parent = classstack[index][0] actype = ( - m.captured("AccessControlType") - or m.captured("AccessControlType2").split("_")[0] + m.group("AccessControlType") + or m.group("AccessControlType2").split("_")[0] ) actype = actype.lower() for name in aclist.split(","): @@ -1114,7 +1106,7 @@ else: index -= 1 - elif m.captured("Attribute"): + elif m.start("Attribute") >= 0: lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start index = -1 @@ -1124,7 +1116,7 @@ and not isinstance(classstack[index][0], Function) and classstack[index][1] < indent ): - attrName = m.captured("AttributeName") + attrName = m.group("AttributeName") attr = Attribute(self.name, attrName, self.file, lineno) if attrName.startswith("@@") or attrName[0].isupper(): classstack[index][0].addGlobal(attrName, attr) @@ -1134,7 +1126,7 @@ else: index -= 1 else: - attrName = m.captured("AttributeName") + attrName = m.group("AttributeName") if attrName[0] != "@": attr = Attribute(self.name, attrName, self.file, lineno) self.addGlobal(attrName, attr) @@ -1142,7 +1134,7 @@ lastGlobalEntry.setEndLine(lineno - 1) lastGlobalEntry = None - elif m.captured("Attr"): + elif m.start("Attr") >= 0: lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start index = -1 @@ -1153,8 +1145,8 @@ and classstack[index][1] < indent ): parent = classstack[index][0] - if not m.captured("AttrType"): - nv = m.captured("AttrList").split(",") + if m.group("AttrType") is None: + nv = m.group("AttrList").split(",") if not nv: break # get rid of leading ':' @@ -1170,8 +1162,8 @@ attr.setPublic() parent.addAttribute(attr.name, attr) else: - access = m.captured("AttrType") - for name in m.captured("AttrList").split(","): + access = m.group("AttrType") + for name in m.group("AttrList").split(","): # get rid of leading ':' name = name.strip()[1:] attr = ( @@ -1193,11 +1185,11 @@ else: index -= 1 - elif m.captured("Begin"): + elif m.start("Begin") >= 0: # a begin of a block we are not interested in indent += 1 - elif m.captured("End"): + elif m.start("End") >= 0: # an end of a block indent -= 1 if indent < 0: @@ -1209,10 +1201,10 @@ indent = 0 elif ( - m.captured("String") - or m.captured("Comment") - or m.captured("ClassIgnored") - or m.captured("BeginEnd") + m.start("String") >= 0 + or m.start("Comment") >= 0 + or m.start("ClassIgnored") >= 0 + or m.start("BeginEnd") >= 0 ): pass