49 QSyntaxHighlighter.__init__(self, document)
57 self.
tri_single = (QRegularExpression(
r"""'''(?!")"""), 1,
'string2')
58 self.
tri_double = (QRegularExpression(
r'''"""(?!')'''), 2,
'string2')
63 rules += [(
r'\b%s\b' % w, 0,
'keyword')
64 for w
in PythonHighlighter.keywords]
65 rules += [(
r'%s' % o, 0,
'operator')
66 for o
in PythonHighlighter.operators]
67 rules += [(
r'%s' % b, 0,
'brace')
68 for b
in PythonHighlighter.braces]
73 (
r'\bself\b', 0,
'self'),
76 (
r'"[^"\\]*(\\.[^"\\]*)*"', 0,
'string'),
78 (
r"'[^'\\]*(\\.[^'\\]*)*'", 0,
'string'),
81 (
r'\bdef\b\s*(\w+)', 1,
'defclass'),
83 (
r'\bclass\b\s*(\w+)', 1,
'defclass'),
86 (
r'#[^\n]*', 0,
'comment'),
89 (
r'\b[+-]?[0-9]+[lL]?\b', 0,
'numbers'),
90 (
r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0,
'numbers'),
91 (
r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0,
'numbers'),
95 self.
rules = [(QRegularExpression(pat), index, identifier)
96 for (pat, index, identifier)
in rules]
99 """Apply syntax highlighting to the given block of text."""
101 for expression, nth, identifier
in self.
rules:
102 matchIter = expression.globalMatch(text)
103 while matchIter.hasNext():
104 match = matchIter.next()
105 index = match.capturedStart(nth)
106 length = match.capturedLength(nth)
107 self.setFormat(index, length, self.
syntaxStyle[identifier])
109 self.setCurrentBlockState(0)
117 """Do highlighting of multi-line strings. ``delimiter`` should be a
118 ``QRegularExpression`` for triple-single-quotes or triple-double-quotes, and
119 ``in_state`` should be a unique integer to represent the corresponding
120 state changes when inside those strings. Returns True if we're still
121 inside a multi-line string when this function is finished.
124 if self.previousBlockState() == in_state:
129 start = delimiter.match(text).capturedStart()
131 add = delimiter.match(text).capturedLength(delimiter.match(text).lastCapturedIndex())
136 match = delimiter.match(text, start + add)
137 end = match.capturedStart()
140 length = end - start + add + match.capturedLength(match.lastCapturedIndex())
141 self.setCurrentBlockState(0)
144 self.setCurrentBlockState(in_state)
145 length = len(text) - start + add
147 self.setFormat(start, length, self.
syntaxStyle[style])
149 start = delimiter.match(text, start + length).capturedStart()
152 if self.currentBlockState() == in_state: