<p>我知道这个问题已经得到了回答,但和我一样,许多新用户来到这里,他们会知道,上面提到的选项是很少的高级水平。我把这个答案贴出来,供其他新来的人参考</p>
<p>使用python和Qt创建语法高亮是一个不错的选择。因为python是非常强大的语言,QT是GUI应用程序开发的优秀框架。<br/>
Syntax highlighter是带有QTextEdit对象的最简单的Regex表达式。您只需解析正则表达式,然后为这种正则表达式选择特定的QTextFormat,然后将该文本格式应用到该块上。
在这里,hightaxlynlier在hightaxlighter类中使用最简单的syntuqsynlighter语法在hightaxlighter类中实现</p>
<pre><code> def highlightBlock(self, text):
for pattern, format in self.highlightingRules:
expression = QtCore.QRegExp(pattern)
index = expression.indexIn(text)
while index >= 0:
length = expression.matchedLength()
self.setFormat(index, length, format)
index = expression.indexIn(text, index + length)
self.setCurrentBlockState(0)
startIndex = 0
if self.previousBlockState() != 1:
startIndex = self.commentStartExpression.indexIn(text)
while startIndex >= 0:
endIndex = self.commentEndExpression.indexIn(text, startIndex)
if endIndex == -1:
self.setCurrentBlockState(1)
commentLength = len(text) - startIndex
else:
commentLength = endIndex - startIndex + self.commentEndExpression.matchedLength()
self.setFormat(startIndex, commentLength,
self.multiLineCommentFormat)
startIndex = self.commentStartExpression.indexIn(text,
startIndex + commentLength);
</code></pre>
<p>以8051单片机为例,用8051微控制器的语法创建了一个高质量的程序集。为了进一步的参考和一个好的起点你<a href="https://pykasm51.codeplex.com/" rel="nofollow">can refer to that code.</a></p>