@@ -39,15 +39,15 @@ class PythonHighlighter(QSyntaxHighlighter):
3939 # Comparison
4040 '==' , '!=' , '<' , '<=' , '>' , '>=' ,
4141 # Arithmetic
42- '\+' , '-' , '\*' , '/' , '//' , '\%' , '\*\*' ,
42+ r '\+' , '-' , r '\*' , '/' , '//' , r '\%' , r '\*\*' ,
4343 # In-place
44- '\+=' , '-=' , '\*=' , '/=' , '\%=' ,
44+ r '\+=' , '-=' , r '\*=' , '/=' , r '\%=' ,
4545 # Bitwise
46- '\^' , '\|' , '\&' , '\~' , '>>' , '<<'
46+ r '\^' , r '\|' , r '\&' , r '\~' , '>>' , '<<'
4747 ]
4848
4949 # Python braces
50- braces = ['\{' , '\}' , '\(' , '\)' , '\[' , '\]' ]
50+ braces = [r '\{' , r '\}' , r '\(' , r '\)' , r '\[' , r '\]' ]
5151
5252 def __init__ (self , document = None ):
5353 super (PythonHighlighter , self ).__init__ (document )
@@ -117,7 +117,8 @@ def highlightBlock(self, text):
117117 # Do other syntax formatting
118118 for rule in self .rules :
119119 expression , nth , formatting = rule
120- index = expression .indexIn (text , 0 )
120+ match = expression .match (text )
121+ index = match .capturedStart ()
121122 # This is here because you can't do nested logic in regex
122123 nested = 0
123124 if rule in self .special_rules :
@@ -126,10 +127,10 @@ def highlightBlock(self, text):
126127
127128 while index >= 0 :
128129 # We actually want the index of the nth match
129- index = expression . pos (nth )
130- length = len (expression . cap (nth ))
130+ index = match . capturedStart (nth )
131+ length = len (match . captured (nth ))
131132 self .setFormat (index , length + nested , formatting )
132- index = expression . indexIn (text , index + length )
133+ index = match . capturedStart (text )
133134
134135 self .setCurrentBlockState (0 )
135136
@@ -151,17 +152,19 @@ def match_multiline(self, text, delimiter, in_state, style):
151152 add = 0
152153 # Otherwise, look for the delimiter on this line
153154 else :
154- start = delimiter .indexIn (text )
155+ match = delimiter .match (text )
156+ start = match .capturedStart ()
155157 # Move past this match
156- add = delimiter . matchedLength ()
158+ add = match . capturedLength ()
157159
158160 # As long as there's a delimiter match on this line...
159161 while start >= 0 :
162+ match = delimiter .match (text )
160163 # Look for the ending delimiter
161- end = delimiter . indexIn ( text , start + add )
164+ end = match . capturedStart () + ( start + add )
162165 # Ending delimiter on this line?
163166 if end >= add :
164- length = end - start + add + delimiter . matchedLength ()
167+ length = end - start + add + match . capturedLength ()
165168 self .setCurrentBlockState (0 )
166169 # No; multi-line string
167170 else :
@@ -170,7 +173,7 @@ def match_multiline(self, text, delimiter, in_state, style):
170173 # Apply formatting
171174 self .setFormat (start , length , style )
172175 # Look for the next match
173- start = delimiter . indexIn ( text , start + length )
176+ start = match . capturedStart () + ( start + length )
174177
175178 # Return True if still inside a multi-line string, False otherwise
176179 if self .currentBlockState () == in_state :
0 commit comments