mirror of
https://github.com/fergalmoran/picard.git
synced 2025-12-22 09:18:18 +00:00
Properly match existing functions, and differentiate them from unknown ones
Before this patch, `$numXXX()` was highlighted the same way as `$num()`, even though it was raising a syntax error. After this patch they have different formats.
This commit is contained in:
@@ -101,7 +101,12 @@ class TaggerScriptSyntaxHighlighter(QtGui.QSyntaxHighlighter):
|
|||||||
def __init__(self, document):
|
def __init__(self, document):
|
||||||
super().__init__(document)
|
super().__init__(document)
|
||||||
syntax_theme = theme.syntax_theme
|
syntax_theme = theme.syntax_theme
|
||||||
self.func_re = re.compile(r"\$(?!noop)[_a-zA-Z0-9]*\(")
|
|
||||||
|
self.unknown_func_re = re.compile(r"\$(?!noop)[_a-zA-Z0-9]*\(")
|
||||||
|
self.unknown_func_fmt = QtGui.QTextCharFormat()
|
||||||
|
self.unknown_func_fmt.setFontItalic(True)
|
||||||
|
self.unknown_func_fmt.setForeground(syntax_theme.special)
|
||||||
|
|
||||||
self.func_fmt = QtGui.QTextCharFormat()
|
self.func_fmt = QtGui.QTextCharFormat()
|
||||||
self.func_fmt.setFontWeight(QtGui.QFont.Weight.Bold)
|
self.func_fmt.setFontWeight(QtGui.QFont.Weight.Bold)
|
||||||
self.func_fmt.setForeground(syntax_theme.func)
|
self.func_fmt.setForeground(syntax_theme.func)
|
||||||
@@ -130,13 +135,20 @@ class TaggerScriptSyntaxHighlighter(QtGui.QSyntaxHighlighter):
|
|||||||
self.noop_fmt.setFontItalic(True)
|
self.noop_fmt.setFontItalic(True)
|
||||||
self.noop_fmt.setForeground(syntax_theme.noop)
|
self.noop_fmt.setForeground(syntax_theme.noop)
|
||||||
|
|
||||||
self.rules = [
|
self.rules = list(self.func_rules())
|
||||||
(self.func_re, self.func_fmt, 0, -1),
|
self.rules.extend([
|
||||||
|
(self.unknown_func_re, self.unknown_func_fmt, 0, -1),
|
||||||
(self.var_re, self.var_fmt, 0, 0),
|
(self.var_re, self.var_fmt, 0, 0),
|
||||||
(self.unicode_re, self.unicode_fmt, 0, 0),
|
(self.unicode_re, self.unicode_fmt, 0, 0),
|
||||||
(self.escape_re, self.escape_fmt, 0, 0),
|
(self.escape_re, self.escape_fmt, 0, 0),
|
||||||
(self.special_re, self.special_fmt, 0, 0),
|
(self.special_re, self.special_fmt, 0, 0),
|
||||||
]
|
])
|
||||||
|
|
||||||
|
def func_rules(self):
|
||||||
|
for func_name in script_function_names():
|
||||||
|
if func_name != 'noop':
|
||||||
|
pattern = re.escape("$" + func_name + "(")
|
||||||
|
yield (re.compile(pattern), self.func_fmt, 0, -1)
|
||||||
|
|
||||||
def highlightBlock(self, text):
|
def highlightBlock(self, text):
|
||||||
self.setCurrentBlockState(0)
|
self.setCurrentBlockState(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user