def __init__(self, document, lang): QSyntaxHighlighter.__init__(self, document) langSyntax = loader.syntax[lang] Highlighter.keywords = langSyntax.get('keywords', []) Highlighter.braces = langSyntax.get('brace', []) Highlighter.operators = langSyntax.get('operators', []) rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in Highlighter.keywords] rules += [(r'%s' % o, 0, STYLES['operator']) for o in Highlighter.operators] rules += [(r'%s' % b, 0, STYLES['brace']) for b in Highlighter.braces] # All other rules proper = langSyntax.get('properObject', None) if proper is not None: proper = '\\b' + str(proper[0]) + '\\b' rules += [ # 'self' (proper, 0, STYLES['properObject'])] rules.append((r'__\w+__', 0, STYLES['properObject'])) definition = langSyntax.get('definition', []) for de in definition: expr = '\\b' + de + '\\b\\s*(\\w+)' rules.append((expr, 1, STYLES['definition'])) rules += [ # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']), ] stringChar = langSyntax.get('string', []) for sc in stringChar: expr = r'"[^"\\]*(\\.[^"\\]*)*"' if sc == '"' else r"'[^'\\]*(\\.[^'\\]*)*'" rules.append((expr, 0, STYLES['string'])) # Multi-line strings (expression, flag, style) # FIXME: The triple-quotes in these two lines will mess up the # syntax highlighting from this point onward self.tri_single = (QRegExp("'''"), 1, STYLES['string2']) #''' self.tri_double = (QRegExp('"""'), 2, STYLES['string2']) #""" comments = langSyntax.get('comment', []) for co in comments: expr = co + '[^\\n]*' rules.append((expr, 0, STYLES['comment'])) rules.append(('\s+', 0, STYLES['spaces'])) # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, parent=None): QSyntaxHighlighter.__init__(self, parent) self.parent = parent sqlKeyword = QTextCharFormat() sqlOperator = QTextCharFormat() self.highlightingRules = [] #Keywords sqlKeyword.setFontWeight(QFont.Bold) sqlKeyword.setForeground(Qt.blue) sqlKeywords = ["AND", "OR", "LIKE"] for word in sqlKeywords: regExp = QRegExp("\\b" + word + "\\b", Qt.CaseInsensitive) rule = HighlightingRule(regExp, sqlKeyword) self.highlightingRules.append(rule) #Comparison Operators sqlOperator.setForeground(Qt.magenta) sqlOperators = ["<", ">", "="] for operator in sqlOperators: regExp = QRegExp("\\W" + operator + "\\W", Qt.CaseInsensitive) rule = HighlightingRule(regExp, sqlOperator) self.highlightingRules.append(rule)
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) # Multi-line strings (expression, flag, style) # FIXME: The triple-quotes in these two lines will mess up the # syntax highlighting from this point onward self.tri_single = (QRegExp("'''"), 1, STYLES['string2']) self.tri_double = (QRegExp('"""'), 2, STYLES['string2']) rules = [] rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in Python.keywords] rules += [(r'%s' % o, 0, STYLES['operator']) for o in Python.operators] rules += [(r'%s' % b, 0, STYLES['brace']) for b in Python.braces] rules += [ # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), # Single-quoted string, possibly containing escape sequences (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']), # 'def' followed by an identifier (r'\bdef\b\s*(\w+)', 1, STYLES['defclass']), # 'class' followed by an identifier (r'\bclass\b\s*(\w+)', 1, STYLES['defclass']), # From '#' until a newline (r'#[^\n]*', 0, STYLES['comment']), ] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) rules = [ (r'=', 0, STYLES['operator']), (r'\b[YN]\b', 0, STYLES['numbers']), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), # Single-quoted string, possibly containing escape sequences (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']), # Numeric literals (r'\b[+-]?[0-9]+\b', 0, STYLES['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+\b', 0, STYLES['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']), # From '#' until a newline (r'#[^\n]*', 0, STYLES['comment']), (r'^\[.+\]', 0, STYLES['section']), (r'^[a-zA-Z0-9_-]+\s?=', 0, STYLES['key']), ] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) self.tri_single = (QRegExp("'''"), 1, STYLES['string2']) self.tri_double = (QRegExp('"""'), 2, STYLES['string2']) rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in PythonHighlighter.keywords] rules += [(r'%s' % o, 0, STYLES['operator']) for o in PythonHighlighter.operators] rules += [(r'%s' % b, 0, STYLES['brace']) for b in PythonHighlighter.braces] rules += [ (r'\bself\b', 0, STYLES['self']), (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']), (r'\bdef\b\s*(\w+)', 1, STYLES['defclass']), (r'\bclass\b\s*(\w+)', 1, STYLES['defclass']), (r'#[^\n]*', 0, STYLES['comment']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']), ] self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, doc, *args, **kwargs): QSyntaxHighlighter.__init__(self, doc) for attr, val in default_colors.items(): setattr(self, attr, val) self._rules = [] self.enabled = True self.generate_rules()
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) rules = [] # LaTeX in-line math brace rules += [(r'%s' % b, 0, STYLES['brace']) for b in LaTeXHighlighter.braces] # LaTeX in-line math brace rules += [(r'%s' % mb, 0, STYLES['mathbrace']) for mb in LaTeXHighlighter.mathbrace] # All other rules rules += [ # \ "something" ends with { or [ or white space - for environments and others # e.g. \begin{}, \something[]{} \texbf etc (r'[\\](?:(?![ \{ | \[ | \s ]).)*', 0, STYLES['environment']), (r'\\end', 0, STYLES['environment']), # LaTeX in-line math braces (r'\\\[', 0, STYLES['mathbrace']), (r'\\\]', 0, STYLES['mathbrace']), (r'\\\(', 0, STYLES['mathbrace']), (r'\\\)', 0, STYLES['mathbrace']), # From '%' until a newline - Commment (r'\%[^\n]*', 0, STYLES['comment']), ] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, parent=None): QSyntaxHighlighter.__init__(self, parent) self.parent = parent sqlKeyword = QTextCharFormat() sqlOperator = QTextCharFormat() self.highlightingRules = [] # Keywords sqlKeyword.setFontWeight(QFont.Bold) sqlKeyword.setForeground(Qt.blue) sqlKeywords = ["AND", "OR", "LIKE"] for word in sqlKeywords: regExp = QRegExp("\\b" + word + "\\b", Qt.CaseInsensitive) rule = HighlightingRule(regExp, sqlKeyword) self.highlightingRules.append(rule) # Comparison Operators sqlOperator.setForeground(Qt.magenta) sqlOperators = ["<", ">", "="] for operator in sqlOperators: regExp = QRegExp("\\W" + operator + "\\W", Qt.CaseInsensitive) rule = HighlightingRule(regExp, sqlOperator) self.highlightingRules.append(rule)
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) rules = [] rules += [(r'%s' % p, 0, 'phpBlock') for p in self.phpBlock] rules += [(r'%s' % k, 0, 'keywords') for k in self.keywords] rules += [(r'%s' % f, 0, 'functions') for f in self.functions] # $variables rules += [(r'\$[\w]*', 0, 'variables')] # comments rules += [(r'#[^\n]*', 0, 'comments')] rules += [(r'//[^\n]*', 0, 'comments')] rules += [(r'/\*+.*\*+/', 0, 'comments')] # strings rules += [(r'".*"', 0, 'strings')] rules += [(r"'.*'", 0, 'strings')] self.rules = [(QRegExp(pat), index, format) for(pat, index, format) in rules]
def __init__(self, parent=None): self.keywordFormat = text_format(Qt.blue, QFont.Bold) self.stringFormat = text_format(Qt.darkGreen) self.defFormat = text_format(Qt.black, QFont.Bold) self.commentFormat = text_format(Qt.lightGray) self.decoratorFormat = text_format(Qt.darkGray) self.keywords = list(keyword.kwlist) self.rules = [(QRegExp(r"\b%s\b" % kwd), self.keywordFormat) for kwd in self.keywords] + \ [(QRegExp(r"\bdef\s+([A-Za-z_]+[A-Za-z0-9_]+)\s*\("), self.defFormat), (QRegExp(r"\bclass\s+([A-Za-z_]+[A-Za-z0-9_]+)\s*\("), self.defFormat), (QRegExp(r"'.*'"), self.stringFormat), (QRegExp(r'".*"'), self.stringFormat), (QRegExp(r"#.*"), self.commentFormat), (QRegExp(r"@[A-Za-z_]+[A-Za-z0-9_]+"), self.decoratorFormat)] self.multilineStart = QRegExp(r"(''')|" + r'(""")') self.multilineEnd = QRegExp(r"(''')|" + r'(""")') QSyntaxHighlighter.__init__(self, parent)
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) # Multi-line strings (expression, flag, style) # FIXME: The triple-quotes in these two lines will mess up the # syntax highlighting from this point onward self.tri_single = (QRegExp("'''"), 1, STYLES['string2']) self.tri_double = (QRegExp('"""'), 2, STYLES['string2']) rules = [] # Keyword, operator, and brace rules rules += [(r'%s' % o, 0, STYLES['operator']) for o in self.operators] rules += [(r'%s' % b, 0, STYLES['brace']) for b in self.braces] rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in self.keywords] # All other rules rules += [ # From '#' until a newline (r':[^(\n|;|\})]*', 0, STYLES['value']), (r'\/\*(.*)\*\/*', 0, STYLES['comment']), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), # Single-quoted string, possibly containing escape sequences (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']), ] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, parent = None, theme = None, prefix = ''): QSyntaxHighlighter.__init__(self, parent) self.rules = [] self.prefix = prefix kwFormat = QTextCharFormat() kwFormat.setForeground( Qt.blue ) #kwFormat.setFontWeight( QFont.Bold ) quoteFormat = QTextCharFormat() quoteFormat.setForeground( Qt.red ) commentFormat = QTextCharFormat() commentFormat.setForeground( Qt.darkGray ) keywords = ["and", "del", "for", "is", "raise", "assert", "elif", "from", "lambda", "break", "else", "global", "not", "try", "class", "except", "if", "or", "while", "continue", "exec", "import", "pass", "yield", "def", "finally", "in", "print", "self" ] for kw in keywords: self.rules.append( (QRegExp("\\b" + kw + "\\b"), kwFormat) ) self.rules.append( (QRegExp(r'"(?:[^"\\]|\\.)*"'), quoteFormat) ) self.rules.append( (QRegExp(r"'(?:[^\']+|\.)*'"), quoteFormat) ) self.rules.append( (QRegExp(r"#.*$"), commentFormat) )
def __init__(self, document, lang=None, scheme=None, errors=None, pep8=None): QSyntaxHighlighter.__init__(self, document) self.errors = errors self.pep8 = pep8 if lang is not None: self.apply_highlight(lang, scheme)
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) self.clb = ConfigurationLineBuilder(ErtKeywords()) self.comment_format = QTextCharFormat() self.comment_format.setForeground(QColor(0, 128, 0)) self.comment_format.setFontItalic(True) self.keyword_format = QTextCharFormat() self.keyword_format.setForeground(QColor(200, 100, 0)) # self.keyword_format.setFontWeight(QFont.Bold) self.error_format = QTextCharFormat() # self.error_format.setForeground(QColor(255, 0, 0)) self.error_format.setUnderlineStyle(QTextCharFormat.WaveUnderline) self.error_format.setUnderlineColor(QColor(255, 0, 0)) self.search_format = QTextCharFormat() self.search_format.setBackground(QColor(220, 220, 220)) self.builtin_format = QTextCharFormat() self.builtin_format.setForeground(QColor(0, 170, 227)) self.search_string = ""
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) self._fridge = ly.lex.Fridge() app.settingsChanged.connect(self.rehighlight) self._highlighting = metainfo.info(document).highlighting document.loaded.connect(self._resetHighlighting) self._mode = documentinfo.mode(document, False) variables.manager(document).changed.connect(self._variablesChange)
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) self._fridge = ly.lex.Fridge() app.settingsChanged.connect(self.rehighlight) self._initialState = None self._highlighting = True self._mode = None self.initializeDocument()
def __init__(self, document, lang=None, scheme=None, errors=None, pep8=None): QSyntaxHighlighter.__init__(self, document) self.highlight_function = self.realtime_highlight self.errors = errors self.pep8 = pep8 self.selected_word_lines = [] self.visible_limits = (0, 50) if lang is not None: self.apply_highlight(lang, scheme)
def __init__(self, widget): QSyntaxHighlighter.__init__(self, widget) self.regex = None # create format type self.odd_format = QTextCharFormat() self.odd_format.setFontWeight(QFont.Bold) self.odd_format.setForeground(Qt.darkBlue) self.even_format = QTextCharFormat() self.even_format.setFontWeight(QFont.Bold) self.even_format.setForeground(Qt.darkMagenta)
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) # Multi-line strings (expression, flag, style) # FIXME: The triple-quotes in these two lines will mess up the # syntax highlighting from this point onward self.tri_single = (QRegExp("'''"), 1, STYLES['string2']) self.tri_double = (QRegExp('"""'), 2, STYLES['string2']) rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in PythonHighlighter.keywords] rules += [(r'%s' % o, 0, STYLES['operator']) for o in PythonHighlighter.operators] rules += [(r'%s' % b, 0, STYLES['brace']) for b in PythonHighlighter.braces] # All other rules rules += [ # 'self' (r'\bself\b', 0, STYLES['self']), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), # Single-quoted string, possibly containing escape sequences (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']), # 'def' followed by an identifier (r'\bdef\b\s*(\w+)', 1, STYLES['defclass']), # 'class' followed by an identifier (r'\bclass\b\s*(\w+)', 1, STYLES['defclass']), # From '#' until a newline (r'//[^\n]*', 0, STYLES['comment']), # From replace (r'^#define', 0, STYLES['perso']), # From perso (r'\*\*\w+\*\*', 0, STYLES['replace']), # From qsub (r'qsub[^\n]*', 0, STYLES['replace']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']), ] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) # Multi-line strings (expression, flag, style) # FIXME: The triple-quotes in these two lines will mess up the # syntax highlighting from this point onward self.tri_single = (QRegExp("'''"), 1, STYLES['string2']) self.tri_double = (QRegExp('"""'), 2, STYLES['string2']) rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in PythonHighlighter.keywords] rules += [(r'\b%s\b' % w, 0, STYLES['keyword2']) for w in PythonHighlighter.keywords2] rules += [(r'\b%s\b' % w, 0, STYLES['datatype']) for w in PythonHighlighter.datatypes] rules += [(r'%s' % b, 0, STYLES['brace']) for b in PythonHighlighter.braces] # All other rules rules += [ # 'self' (r'\bself\b', 0, STYLES['self']), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), # Single-quoted string, possibly containing escape sequences (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']), # 'def' followed by an identifier (r'\bdef\b\s*(\w+)', 1, STYLES['defclass']), # 'class' followed by an identifier (r'\bclass\b\s*(\w+)', 1, STYLES['defclass']), # From '//' until a newline (r'//[^\n]*', 0, STYLES['comment']), # Multi-line comments - This needs to be a single rule (r'/\*', 0, STYLES['comment']), (r'\*[^\n]*', 0, STYLES['comment']), (r'\*/', 0, STYLES['comment']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']), ] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, edit): self.textedit = edit document = edit.document() QSyntaxHighlighter.__init__(self, document) base_format = QTextCharFormat() base_format.setFont(edit.font()) self.base_format = base_format self.document = document self.updateHighlighter(base_format.font())
def __init__(self,name,document): self.init= False self.name = name self.entities=[] self.initialized=False self.styles=[] self.blocks=[] self.braces = QRegExp('(\{|\}|\(|\)|\[|\])') self.font=QFont() self.Default=0 QSyntaxHighlighter.__init__(self,document)
def __init__(self, document, pattern): QSyntaxHighlighter.__init__(self, document) self.keywords.append(pattern) rules = [] rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in PythonHighlighter.keywords] self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) # Multi-line strings (expression, flag, style) # FIXME: The triple-quotes in these two lines will mess up the # syntax highlighting from this point onward self.tri_single = (QRegExp("'''"), 1, STYLES_R['string2']) self.tri_double = (QRegExp('"""'), 2, STYLES_R['string2']) rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, STYLES_R['keyword']) for w in RHighlighter.keywords] rules += [(r'%s' % o, 0, STYLES_R['operator']) for o in RHighlighter.operators] rules += [(r'%s' % b, 0, STYLES_R['brace']) for b in RHighlighter.braces] # All other rules rules += [ # True or False (r'\bTrue', 0, STYLES_R['truefalse']), (r'\bFalse', 0, STYLES_R['truefalse']), # Assign (r'(\<)(\-)', 0, STYLES_R['assign']), # Function call (r'\b*(\w+)\(', 1, STYLES_R['function']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES_R['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES_R['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES_R['numbers']), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES_R['string']), # Single-quoted string, possibly containing escape sequences (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES_R['string']), # Quicktrace Variables (r'(\@)(\{)[^\}]*(\})', 0, STYLES_R['quicktraceVariable']), # From '#' until a newline (r'#[^\n]*', 0, STYLES_R['comment']), ] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) rules = [] rules += [(r'\b%s\b' % w, 0, STYLES['p_commands']) for w in ImagiHighlighter.p_commands] rules += [(r'\b%s\b' % w, 0, STYLES['l_commands']) for w in ImagiHighlighter.l_commands] rules += [(r'\b%s\b' % w, 0, STYLES['m_attributes']) for w in ImagiHighlighter.m_attributes] rules += [(r'\b%s\b' % w, 0, STYLES['types']) for w in ImagiHighlighter.types] rules += [(r'%s' % o, 0, STYLES['operators']) for o in ImagiHighlighter.operators] self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) rules = [] rules += [(r'%s' % c, 0, STYLES['comment']) for c in self.comment] rules += [(r'%s' % g, 0, STYLES['group']) for g in self.group] rules += [(r'%s' % o, 0, STYLES['operator']) for o in self.operators] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) # Multi-line strings (expression, flag, style) # FIXME: The triple-quotes in these two lines will mess up the # syntax highlighting from this point onward #self.tri_single = (QRegExp("'''"), 1, STYLES['string2']) self.multi_cmnt = (QRegExp("\/\*"), QRegExp("\*\/"), 1, STYLES['comment']) #self.tri_double = (QRegExp('"""'), 2, STYLES['string2']) rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in VerilogHighlighter.keywords] rules += [(r'%s' % o, 0, STYLES['operator']) for o in VerilogHighlighter.operators] rules += [(r'%s' % b, 0, STYLES['brace']) for b in VerilogHighlighter.braces] # All other rules rules += [ #Comments for #(r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), #(r'\/\*[^\\]*(\\.[^\\]*)\*\/', 0, STYLES["comment"]), (r'\/\*[^\\]*(\\.[^\\]*)\*\/', 0, STYLES["string"]), #(r"\/\**(\\.[^\*\/]*)*", 0, STYLES['string']), ##Double-quoted string, possibly containing escape sequences #(r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), ## Single-quoted string, possibly containing escape sequences #(r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']), #(r"\/\**(\\.[^'\\]*)\*\/", 0, STYLES['comment']), # 'def' followed by an identifier #(r'\balways\b\s*(\w+)', 1, STYLES['defclass']), # 'class' followed by an identifier #(r'\binitial\b\s*(\w+)', 1, STYLES['defclass']), # From '#' until a newline (r'\/\/[^\n]*', 0, STYLES['comment']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']), ] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, document, keywords=[], functions=[]): QSyntaxHighlighter.__init__(self, document) EHighlighter.keywords.extend(keywords) EHighlighter.functions.extend(functions) rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in EHighlighter.keywords] rules += [(r'\b%s\b' % w, 0, STYLES['functions']) for w in EHighlighter.functions] rules += [(r'%s' % o, 0, STYLES['operator']) for o in EHighlighter.operators] rules += [(r'%s' % b, 0, STYLES['brace']) for b in EHighlighter.braces] # All other rules rules += [ # 'self' (r'\bself\b', 0, STYLES['self']), #(r'Traceback[^\n]*', 0, STYLES['Traceback']), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), # Single-quoted string, possibly containing escape sequences (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']), # 'def' followed by an identifier (r'\bdef\b\s*(\w+)', 1, STYLES['defclass']), # 'class' followed by an identifier (r'\bclass\b\s*(\w+)', 1, STYLES['defclass']), # From '#' until a newline (r'#[^\n]*', 0, STYLES['comment']), (r'(__[a-zA-Z_]*(__)?)', 0, STYLES['default']), (r'(\'[a-zA-Z_]*(\')?)', 0, STYLES['string']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers'])] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, parent=None): QSyntaxHighlighter.__init__(self, parent) for rule in Highlighter.Rules: if not rule[3]: rule[3] = QTextCharFormat() rule[3].setForeground(rule[0]) if rule[1] & Highlighter.Normal: rule[3].setFontWeight(QFont.Normal) if rule[1] & Highlighter.Bold: rule[3].setFontWeight(QFont.Bold) if rule[1] & Highlighter.Italic: rule[3].setFontItalic(True) return
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) # syntax highlighting from this point onward self.multiline_comment = (QRegExp("/\*"),QRegExp("\*/"), 1, STYLES['comment']) rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in CPPHighlighter.keywords] rules += [(r'%s' % o, 0, STYLES['operator']) for o in CPPHighlighter.operators] rules += [(r'%s' % b, 0, STYLES['brace']) for b in CPPHighlighter.braces] rules += [(r'\b%s\b' % b, 0, STYLES['modifiers']) for b in CPPHighlighter.modifiers] rules += [(r'\b%s\b' % b, 0, STYLES['datatypes']) for b in CPPHighlighter.datatypes] # All other rules rules += [ # 'class' followed by an identifier (r'\bclass\b\s*(\w+)', 1, STYLES['defclass']), # From '#' until a newline (r'#[^\n]*', 0, STYLES['directive']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), #For includes with doubly quoted strings (r'#+(.)+"+(.)+"',0,STYLES['directive']), # From '//' until a newline (r'//[^\n]*', 0, STYLES['comment']), #(r'/\*(.)+\*/',0,STYLES['comment']), ] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules] self.comment_started = False
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) # syntax highlighting from this point onward self.multiline_comment = (QRegExp("/\*"), QRegExp("\*/"), 1, STYLES['comment']) rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in CPPHighlighter.keywords] rules += [(r'%s' % o, 0, STYLES['operator']) for o in CPPHighlighter.operators] rules += [(r'%s' % b, 0, STYLES['brace']) for b in CPPHighlighter.braces] rules += [(r'\b%s\b' % b, 0, STYLES['modifiers']) for b in CPPHighlighter.modifiers] rules += [(r'\b%s\b' % b, 0, STYLES['datatypes']) for b in CPPHighlighter.datatypes] # All other rules rules += [ # 'class' followed by an identifier (r'\bclass\b\s*(\w+)', 1, STYLES['defclass']), # From '#' until a newline (r'#[^\n]*', 0, STYLES['directive']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), #For includes with doubly quoted strings (r'#+(.)+"+(.)+"', 0, STYLES['directive']), # From '//' until a newline (r'//[^\n]*', 0, STYLES['comment']), #(r'/\*(.)+\*/',0,STYLES['comment']), ] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules] self.comment_started = False
def __init__(self, parent=None): """ Initializes the class. :param parent: Widget parent. :type parent: QObject """ LOGGER.debug("> Initializing '{0}()' class.".format(self.__class__.__name__)) QSyntaxHighlighter.__init__(self, parent) # --- Setting class attributes. --- self.__formats = None self.__rules = None
def __init__(self, doc): QSyntaxHighlighter.__init__(self, doc) commentFormat = QTextCharFormat() commentFormat.setFontItalic(True) commentFormat.setFontWeight(0) commentFormat.setForeground(QColor('grey')) self.commentFormat = commentFormat mysqlObjectFormat = QTextCharFormat() mysqlObjectFormat.setFontItalic(True) mysqlObjectFormat.setFontWeight(0) mysqlObjectFormat.setForeground(QColor().fromRgb(128, 128, 0)) self.mysqlObjectFormat = mysqlObjectFormat self.mysqlObjectRegex = re.compile('(`.+?`)')
def __init__(self,textboxdoc,valid_list_of_commands): QSyntaxHighlighter.__init__(self,textboxdoc) self.valid_syntax="|".join([command.regexp_str for command in valid_list_of_commands]) self.my_expression = QRegExp(self.valid_syntax) #define a blue font format for valid commands self.valid = QTextCharFormat() self.valid.setForeground(Qt.black) #define a bold red font format for invalid commands self.invalid = QTextCharFormat() self.invalid.setFontWeight(QFont.Bold) self.invalid.setForeground(Qt.red) #define a blue font format for valid parameters self.valid_value=QTextCharFormat() self.valid_value.setFontWeight(QFont.Bold) #self.valid_value.setForeground(QColor.fromRgb(255,85,0)) self.valid_value.setForeground(Qt.blue)
def __init__(self, textboxdoc, valid_list_of_commands): QSyntaxHighlighter.__init__(self, textboxdoc) self.valid_syntax = "|".join( [command.regexp_str for command in valid_list_of_commands]) self.my_expression = QRegExp(self.valid_syntax) #define a blue font format for valid commands self.valid = QTextCharFormat() self.valid.setForeground(Qt.black) #define a bold red font format for invalid commands self.invalid = QTextCharFormat() self.invalid.setFontWeight(QFont.Bold) self.invalid.setForeground(Qt.red) #define a blue font format for valid parameters self.valid_value = QTextCharFormat() self.valid_value.setFontWeight(QFont.Bold) #self.valid_value.setForeground(QColor.fromRgb(255,85,0)) self.valid_value.setForeground(Qt.blue)
def __init__(self, textEdit): QSyntaxHighlighter.__init__(self, textEdit) self._textEdit = textEdit textEdit.setFont(QFont("Monospace")) self._bracePattern = re.compile('[\(\)]') """Single line string formatting are applied at the end. Therefore even if some items in the string was highlighted with other style, it will be replaced """ self._patternsToApply = { 'keyword': self._makePatternFromList(self.KEYWORDS), 'standardFunction': self._makePatternFromList(self.STANDARD_FUNCTIONS), 'number': self._makePatternFromList(self.NUMBERS), } textEdit.cursorPositionChanged.connect(self._rehighlightMatchingBraces) textEdit.textChanged.connect(self._rehighlightMatchingBraces) # When user presses Del, cursor is not moved
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) self.start_of_chorus = (QRegExp("\{soc\}"), QRegExp("\{eoc\}"), 1, STYLES['chorus']) rules = [] # Rules # TODO: make a nice rule for chord definition # TODO: make rules for keywords that take special arguments (like numbers) rules += [(r'\{%s\:(.)*\}' % w, 0, STYLES['argument']) for w in ChordProHighlighter.argumentKeywords] rules += [(r'\{%s\:?' % w, 0, STYLES['keyword']) for w in ChordProHighlighter.keywords] rules += [(r'%s' % b, 0, STYLES['curlyBrace']) for b in ChordProHighlighter.curlyBraces] rules += [(r'\[[^\]]*\]', 0, STYLES['chord'])] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, textEdit): QSyntaxHighlighter.__init__(self, textEdit) self._textEdit = textEdit textEdit.setFont(QFont("Monospace")) self._bracePattern = re.compile('[\(\)]') """Single line string formatting are applied at the end. Therefore even if some items in the string was highlighted with other style, it will be replaced """ self._patternsToApply = { 'keyword': self._makePatternFromList(self.KEYWORDS), 'standardFunction': self._makePatternFromList(self.STANDARD_FUNCTIONS), 'number': self._makePatternFromList(self.NUMBERS), } textEdit.cursorPositionChanged.connect(self._rehighlightMatchingBraces) textEdit.textChanged.connect( self._rehighlightMatchingBraces ) # When user presses Del, cursor is not moved
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) self.tri_single = (QRegExp("'''"), 2, ESTILOS['cadena2']) self.tri_double = (QRegExp('"""'), 2, ESTILOS['cadena2']) reglas = [] # Keyword, operator, and brace rules reglas += [(r'\b%s\b' % w, 0, ESTILOS['palabra']) for w in const.PALABRAS] reglas += [(r'%s' % o, 0, ESTILOS['operador']) for o in const.OPERADORES] reglas += [(r'%s' % b, 0, ESTILOS['corchetes']) for b in const.CORCHETES] reglas += [(r'%s' % b, 0, ESTILOS['tipos']) for b in const.TIPOS] # All other rules reglas += [ (r'\bINICIO\b', 0, ESTILOS['INICIO']), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, ESTILOS['cadena']), # Single-quoted string, possibly containing escape sequences (r"'[^'\\]*(\\.[^'\\]*)*'", 0, ESTILOS['cadena']), # From '#' until a newline (r'#[^\n]*', 0, ESTILOS['libreria']), (r'//[^\n]*', 0, ESTILOS['commentario']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, ESTILOS['numberos']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, ESTILOS['numberos']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, ESTILOS['numberos']), ] # Build a QRegExp for each pattern self.reglas = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in reglas]
def __init__(self, document, main_win): global gtk_enabled, gtk_struct_str QSyntaxHighlighter.__init__(self, document) self.build_rules() self.comment_started = False self.index_comment_start = -1 self.index_comment_end = -1 self.document = document self.list_multi_line_comment_pos = [] print 'kkkkkk' gtk_enabled = False gtk_struct_str = '' self.main_win = main_win if self.main_win.gtk_support_structs != None: gtk_enabled = True gtk_struct_str = main_win.gtk_support_structs.all_structs_str print gtk_enabled
def __init__(self, document): QSyntaxHighlighter.__init__(self, document)
def __init__(self, parent, mode): QSyntaxHighlighter.__init__(self, parent) self.tstamp = time.time() self.formatter = QFormatter() self.lexer = get_lexer_by_name(mode) return
def rehighlight(self): QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QSyntaxHighlighter.rehighlight(self) QApplication.restoreOverrideCursor()
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) # Syntax styles specific for Gaffer self.styles = { 'keyword': self.text_format("#CC7832", 'bold'), 'operator': self.text_format("#FFC68D"), 'brace': self.text_format("#EEEEEE"), 'defclass': self.text_format("#EEEEEE", 'bold'), 'string': self.text_format("#8AA779"), 'string2': self.text_format("#8AA779", 'italic'), 'comment': self.text_format("#808080", 'italic'), 'self': self.text_format("#8A653B", 'italic'), 'numbers': self.text_format("#6897BB") } # Python keywords self.keywords = [ 'and', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'yield', 'None', 'True', 'False', ] # Python operators self.operators = [ '=', # Comparison '==', '!=', '<', '<=', '>', '>=', # Arithmetic '\+', '-', '\*', '/', '//', '\%', '\*\*', # In-place '\+=', '-=', '\*=', '/=', '\%=', # Bitwise '\^', '\|', '\&', '\~', '>>', '<<', ] # Python braces self.braces = [ '\{', '\}', '\(', '\)', '\[', '\]', ] self.block_state_id = {"'": 2, '"': 3, "'''": 4, '"""': 5, '#': 6} rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, 'keyword') for w in self.keywords] rules += [(r'%s' % o, 0, 'operator') for o in self.operators] rules += [(r'%s' % b, 0, 'brace') for b in self.braces] # All other rules rules += [ # 'self' (r'\bself\b', 0, 'self'), # 'def' followed by an identifier (r'\bdef\b\s*(\w+)', 1, 'defclass'), # 'class' followed by an identifier (r'\bclass\b\s*(\w+)', 1, 'defclass'), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, 'numbers'), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, 'numbers'), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, 'numbers'), ] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules] self.formats = {}
def __init__(self, document, lang, scheme=None): QSyntaxHighlighter.__init__(self, document) langSyntax = loader.syntax[lang] if scheme is not None and not {}: restyle(scheme) keywords = langSyntax.get('keywords', []) operators = langSyntax.get('operators', []) extras = langSyntax.get('extras', []) rules = [] # Keyword, operator, brace and extras rules rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in keywords] rules += [(r'%s' % o, 0, STYLES['operator']) for o in operators] rules += [(r'%s' % b, 0, STYLES['brace']) for b in Highlighter.braces] rules += [(r'\b%s\b' % e, 0, STYLES['extras']) for e in extras] # All other rules proper = langSyntax.get('properObject', None) if proper is not None: proper = '\\b' + str(proper[0]) + '\\b' rules += [(proper, 0, STYLES['properObject'])] rules.append((r'__\w+__', 0, STYLES['properObject'])) definition = langSyntax.get('definition', []) for de in definition: expr = '\\b' + de + '\\b\\s*(\\w+)' rules.append((expr, 1, STYLES['definition'])) # Numeric literals rules += [ (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']), ] regex = langSyntax.get('regex', []) for reg in regex: expr = reg[0] color = color_scheme['extras'] style = '' if len(reg) > 2: color = reg[1] style = reg[2] elif len(reg) > 1: color = reg[1] rules.append((expr, 0, format(color, style))) comments = langSyntax.get('comment', []) for co in comments: expr = co + '[^\\n]*' rules.append((expr, 0, STYLES['comment'])) stringChar = langSyntax.get('string', []) for sc in stringChar: expr = r'"[^"\\]*(\\.[^"\\]*)*"' if sc == '"' else r"'[^'\\]*(\\.[^'\\]*)*'" rules.append((expr, 0, STYLES['string'])) # Multi-line strings (expression, flag, style) # FIXME: The triple-quotes in these two lines will mess up the # syntax highlighting from this point onward self.tri_single = (QRegExp("'''"), 1, STYLES['string2']) #''' self.tri_double = (QRegExp('"""'), 2, STYLES['string2']) #""" multi = langSyntax.get('multiline_comment', []) if multi: self.multi_start = (QRegExp(multi['open']), STYLES['comment']) self.multi_end = (QRegExp(multi['close']), STYLES['comment']) else: self.multi_start = None # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, document, lang=None, scheme=None): QSyntaxHighlighter.__init__(self, document) if lang is not None: self.apply_highlight(lang, scheme)
def __init__(self, document, lang, scheme=None): QSyntaxHighlighter.__init__(self, document) self.apply_highlight(lang, scheme)
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) # Multi-line strings (expression, flag, style) # FIXME: The triple-quotes in these two lines will mess up the # syntax highlighting from this point onward # self.tri_single = (QRegExp("'''"), 1, STYLES['string2']) # self.tri_double = (QRegExp('"""'), 2, STYLES['string2']) rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in MelHighlighter.keywords] rules += [(r'%s' % o, 0, STYLES['operator']) for o in MelHighlighter.operators] rules += [(r'%s' % b, 0, STYLES['brace']) for b in MelHighlighter.braces] rules += [(r'%s' % b, 0, STYLES['keyword']) for b in MelHighlighter.pyKeywords] rules += [(r'%s' % "|".join(MelHighlighter.pyKeywords), 0, STYLES['keyword'])] # All other rules rules += [ # 'self' # (r'\bself\b', 0, STYLES['self']), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), # Single-quoted string, possibly containing escape sequences # (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']), # 'proc' followed by an identifier # (r'\bproc\b\s*(\w+)', 1, STYLES['defclass']), # 'global proc' followed by an identifier # (r'\bglobal proc\b\s*(\w+)', 1, STYLES['defclass']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']), # From '//' until a newline (r'//[^\n]*', 0, STYLES['comment']), ] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules] # Quotes self._singleQuotes = QtCore.QRegExp("'''") self._doubleQuotes = QtCore.QRegExp('"""') # mel multi-line comment: /* */ self._melMLComStart = re.compile('/\\*') self._melMLComEnd = re.compile('\\*/')
def __init__(self, document, filename, syntax_mode, syntax_theme): self.document = document QSyntaxHighlighter.__init__(self, self.document) try: filename_extension = filename.rsplit('.', 1) filename_extension = filename_extension[1] except: filename_extension = "" for extension in BoostSourceHighlighter.file_extensions: if extension == filename_extension: syntax_mode = filename_extension # Syntax styles that can be shared by all languages # Theme support: temporarily sys.argv input try: if syntax_theme == "Monochrome" or str( sys.argv[1]) == "monochrome": STYLES = { 'keyword': format('#38898C'), 'operator': format('#419141'), 'brace': format('#878787'), 'defclass': format('#759F6F'), 'string': format('#759F6F'), 'string2': format('#759F6F'), 'comment': format('#6b6b6b'), 'self': format('#38898C'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "Red" or str(sys.argv[1]) == "red": STYLES = { 'keyword': format('#770000'), 'operator': format('#7A7A7A'), 'brace': format('#878787'), 'defclass': format('#9C4343'), 'string': format('#9C4343'), 'string2': format('#9C4343'), 'comment': format('#494949'), 'self': format('#770000'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "Orange" or str(sys.argv[1]) == "orange": STYLES = { 'keyword': format('#8F471E'), 'operator': format('#7A7A7A'), 'brace': format('#878787'), 'defclass': format('#e87330'), 'string': format('#e87330'), 'string2': format('#e87330'), 'comment': format('#494949'), 'self': format('#8F471E'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "Yellow" or str(sys.argv[1]) == "yellow": STYLES = { 'keyword': format('#777700'), 'operator': format('#7A7A7A'), 'brace': format('#878787'), 'defclass': format('#A5A448'), 'string': format('#848337'), 'string2': format('#848337'), 'comment': format('#494949'), 'self': format('#777700'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "Blue" or str(sys.argv[1]) == "blue": STYLES = { 'keyword': format('#003377'), 'operator': format('#7A7A7A'), 'brace': format('#878787'), 'defclass': format('#375c84'), 'string': format('#375c84'), 'string2': format('#375c84'), 'comment': format('#494949'), 'self': format('#003377'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "Green" or str(sys.argv[1]) == "green": STYLES = { 'keyword': format('#007765'), 'operator': format('#7A7A7A'), 'brace': format('#878787'), 'defclass': format('#378437'), 'string': format('#378437'), 'string2': format('#378437'), 'comment': format('#494949'), 'self': format('#007765'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "Flo\'s V8 Cafe" or str( sys.argv[1]) == "flosv8cafe": STYLES = { 'keyword': format('#0D8580'), 'operator': format('#7A7A7A'), 'brace': format('#878787'), 'defclass': format('#EF7196'), 'string': format('#EF7196'), 'string2': format('#EF7196'), 'comment': format('#494949'), 'self': format('#0D8580'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "Stranger Things" or str( sys.argv[1]) == "strangerthings": STYLES = { 'keyword': format('#222F57'), 'operator': format('#7A7A7A'), 'brace': format('#878787'), 'defclass': format('#BF1515'), 'string': format('#BF1515'), 'string2': format('#BF1515'), 'comment': format('#494949'), 'self': format('#222F57'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "Royal" or str(sys.argv[1]) == "royal": STYLES = { 'keyword': format('#00626a'), 'operator': format('#4D1675'), 'brace': format('#878787'), 'defclass': format('#e8b290'), 'string': format('#e8b290'), 'string2': format('#e8b290'), 'comment': format('#494949'), 'self': format('#00626a'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "Scoops Ahoy" or str( sys.argv[1]) == "scoopsahoy": STYLES = { 'keyword': format('#473B5F'), 'operator': format('#943B41'), 'brace': format('#878787'), 'defclass': format('#943B41'), 'string': format('#D2A89C'), 'string2': format('#D2A89C'), 'comment': format('#494949'), 'self': format('#473B5F'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "Old Locomotive" or str( sys.argv[1]) == "oldlocomotive": STYLES = { 'keyword': format('#916438'), 'operator': format('#878787'), 'brace': format('#878787'), 'defclass': format('#389138'), 'string': format('#389138'), 'string2': format('#389138'), 'comment': format('#6b6b6b'), 'self': format('#916438'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "Green (Muted)" or str( sys.argv[1]) == "greenmuted": STYLES = { 'keyword': format('#38898C'), 'operator': format('#878787'), 'brace': format('#878787'), 'defclass': format('#759F6F'), 'string': format('#759F6F'), 'string2': format('#759F6F'), 'comment': format('#6b6b6b'), 'self': format('#38898C'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "Winter" or str(sys.argv[1]) == "winter": STYLES = { 'keyword': format('#875F5F'), 'operator': format('#878787'), 'brace': format('#878787'), 'defclass': format('#5F5F87'), 'string': format('#38898C'), 'string2': format('#38898C'), 'comment': format('#6b6b6b'), 'self': format('#38898C'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "SpaCy" or str(sys.argv[1]) == "spacy": STYLES = { 'keyword': format('#DB2C55'), 'operator': format('#878787'), 'brace': format('#878787'), 'defclass': format('#FFB86C'), 'string': format('#FFB86C'), 'string2': format('#FFB86C'), 'comment': format('#6b6b6b'), 'self': format('#DEDEDE'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "Alabaster" or str( sys.argv[1]) == "alabaster": STYLES = { 'keyword': format('#007765'), 'operator': format('#7A7A7A'), 'brace': format('#000000'), 'defclass': format('#378437'), 'string': format('#378437'), 'string2': format('#378437'), 'comment': format('#378437'), 'self': format('#000000'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "SpaceX" or str(sys.argv[1]) == "spacex": STYLES = { 'keyword': format('#186298'), 'operator': format('#878787'), 'brace': format('#878787'), 'defclass': format('#287FB1'), 'string': format('#FF9210'), 'string2': format('#FF9210'), 'comment': format('#FF9210'), 'self': format('#DEDEDE'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "Forest" or str(sys.argv[1]) == "forest": STYLES = { 'keyword': format('#379439'), 'operator': format('#BBC1A8'), 'brace': format('#8C8C8C'), 'defclass': format('#CC652D'), 'string': format('#CC652D'), 'string2': format('#CC652D'), 'comment': format('#8C8C8C'), 'self': format('#FFFFFF'), 'numbers': format('#8A8A8A'), } elif syntax_theme == "": STYLES = { 'keyword': format('#2273A5'), 'operator': format('#DBD9D5'), 'brace': format('#DBD9D5'), 'defclass': format('#ccac55'), 'string': format('#77D479'), 'string2': format('#77D479'), 'comment': format('#8b939b'), 'self': format('#C37A5A'), 'numbers': format('#DBD9D5'), } except: STYLES = { 'keyword': format('#2273A5'), 'operator': format('#DBD9D5'), 'brace': format('#DBD9D5'), 'defclass': format('#ccac55'), 'string': format('#77D479'), 'string2': format('#77D479'), 'comment': format('#8b939b'), 'self': format('#C37A5A'), 'numbers': format('#DBD9D5'), } if syntax_mode == "html": keywords = [ 'a', 'abbr', 'acronym', 'address', 'applet', 'area', 'article', 'aside', 'audio', 'b', 'base', 'basefont', 'bdi', 'bdo', 'bgsound', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'command', 'content', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'frame', 'frameset', 'h1', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'image', 'img', 'input', 'ins', 'isindex', 'kbd', 'keygen', 'label', 'legend', 'li', 'link', 'listing', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meta', 'meter', 'multicol', 'nav', 'nextid', 'nobr', 'noembed', 'noframes', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'picture', 'plaintext', 'pre', 'progress', 'q', 'rb', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'script', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr', 'xmp', ] operators = [ # Arithmetic '\+', '-', '\*', '/', '//', '\%', '\*\*', ] braces = [ '\{', '\}', '\(', '\)', '\[', '\]', ] elif syntax_mode == "js": keywords = [ 'abstract', 'arguments', 'await*', 'boolean', 'break', 'byte', 'case', 'catch', 'char', 'class*', 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'double', 'else', 'enum*', 'evalexport*', 'extends*', 'false', 'final', 'finally', 'float', 'for', 'function', 'goto', 'if', 'implements', 'import*', 'in', 'instanceof', 'int', 'interface', 'let*', 'long', 'native', 'new', 'null', 'package', 'private', 'protected', 'public', 'return', 'short', 'static', 'super*', 'switch', 'synchronized', 'this', 'throw', 'throws', 'transient', 'true', 'try', 'typeof', 'var', 'void', 'volatile', 'while', 'with', 'yield' ] operators = [ # Arithmetic '\+', '-', '\*', '/', '//', '\%', '\*\*', ] braces = [ '\{', '\}', '\(', '\)', '\[', '\]', ] elif syntax_mode == "cpp": keywords = [ '__abstract', '__alignof', 'Operator', '__asm', '__assume', '__based', '__box', '__cdecl', '__declspec', '__delegate', '__event', '__except', '__fastcall', '__finally', '__forceinline', '__gc', '__hook', '__identifier', '__if_exists', '__if_not_exists', '__inline', '__int16', '__int32', '__int64', '__int8', '__interface', '__leave', '__m128', '__m128d', '__m128i', '__m64', '__multiple_inheritance', '__nogc', '__noop', '__pin', '__property', '__ptr32', '__ptr644', '__raise', '__restrict', '__sealed', '__single_inheritance4', '__sptr4', '__stdcall', '__super', '__thiscall', '__try_cast', '__unaligned', '__unhook', '__uptr', '__uuidof', '__value', '__vectorcall', '__virtual_inheritance', '__w64', '__wchar_t', 'abstract', 'alignas', 'array', 'auto', 'bool', 'break', 'case', 'catch', 'char', 'char16_t', 'char32_t', 'class', 'const', 'const_cast', 'constexpr', 'continue', 'decltype', 'default', 'delegate', 'delete', 'deprecated', 'dllexport', 'dllimport', 'do', 'double', 'dynamic_cast', 'else', 'enum', 'enum', 'class', 'enum', 'include', 'struct', 'event', 'explicit', 'extern', 'false', 'finally', 'float', 'for', 'for', 'each', 'in', 'friend', 'friend_as', 'gcnew', 'generic', 'goto', 'if', 'initonly', 'inline', 'int', 'interface', 'class', 'interface', 'struct', 'interior_ptr', 'literal', 'long', 'mutable', 'naked', 'namespace', 'new', 'new', 'noexcept', 'noinline', 'noreturn', 'nothrow', 'novtable', 'nullptr', 'operator', 'private', 'property', 'property', 'protected', 'public', 'ref', 'class', 'ref', 'struct', 'register', 'reinterpret_cast', 'return', 'safecast', 'sealed', 'selectany', 'short', 'signed', 'sizeof', 'static', 'static_assert', 'static_cast', 'struct', 'string', 'switch', 'template', 'this', 'thread', 'throw', 'true', 'try', 'typedef', 'typeid', 'typeid', 'typename', 'union', 'unsigned', 'using', 'declaration', 'using', 'directive', 'uuid', 'value', 'class', 'value', 'struct', 'virtual', 'void', 'volatile', 'while' ] operators = [ # Arithmetic '\+', '-', '\*', '/', '//', '\%', '\*\*', ] braces = [ '\{', '\}', '\(', '\)', '\[', '\]', ] elif syntax_mode == "rs": keywords = [ '_', 'abstract', 'alignof', 'as', 'become', 'box', 'break', 'const', 'continue', 'crate', 'do', 'else', 'enum', 'extern', 'false', 'final', 'fn', 'for', 'if', 'impl', 'in', 'let', 'loop', 'macro', 'match', 'mod', 'move', 'mut', 'offsetof', 'override', 'priv', 'proc', 'pub', 'pure', 'ref', 'return', 'Self', 'self', 'sizeof', 'static', 'struct', 'super', 'trait', 'true', 'type', 'typeof', 'unsafe', 'unsized', 'use', 'virtual', 'where', 'while', 'yield' ] operators = [ # Arithmetic '\+', '-', '\*', '/', '//', '\%', '\*\*', ] braces = [ '\{', '\}', '\(', '\)', '\[', '\]', ] # Python operators elif syntax_mode in BoostSourceHighlighter.file_extensions: # Python keywords keywords = [ 'and', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'yield', 'None', 'True', 'False', ] operators = [ '=', # Comparison '==', '!=', '<', '<=', '>', '>=', # Arithmetic '\+', '-', '\*', '/', '//', '\%', '\*\*', # In-place '\+=', '-=', '\*=', '/=', '\%=', # Bitwise '\^', '\|', '\&', '\~', '>>', '<<', ] # Python braces braces = [ '\{', '\}', '\(', '\)', '\[', '\]', ] #Everything not a source file else: keywords = [] operators = [] braces = [] STYLES = { 'keyword': format('#DBD9D5'), 'operator': format('#DBD9D5'), 'brace': format('#DBD9D5'), 'defclass': format('#DBD9D5'), 'string': format('#DBD9D5'), 'string2': format('#DBD9D5'), 'comment': format('#DBD9D5'), 'self': format('#DBD9D5'), 'numbers': format('#DBD9D5'), } QSyntaxHighlighter.__init__(self, self.document) # Multi-line strings (expression, flag, style) # FIXME: The triple-quotes in these two lines will mess up the # syntax highlighting from this point onward self.tri_single = (QRegExp("'''"), 1, STYLES['comment']) self.tri_double = (QRegExp('"""'), 2, STYLES['comment']) highlight_rules = [] # Keyword, operator, and brace rules highlight_rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in keywords] highlight_rules += [(r'%s' % o, 0, STYLES['operator']) for o in operators] highlight_rules += [(r'%s' % b, 0, STYLES['brace']) for b in braces] # All other rules if str(syntax_mode) != "html" and str(syntax_mode) != "htm": highlight_rules += [ # 'self' (r'\bself\b', 0, STYLES['self']), # 'def' followed by an identifier (r'\bdef\b\s*(\w+)', 1, STYLES['defclass']), # 'class' followed by an identifier (r'\bclass\b\s*(\w+)', 1, STYLES['defclass']), # Function call after . and before ( # (r'\.(?:[^\.]*(?=([(])))', 0, STYLES['function']), # (r'\.[\w]+(?=\()', 0, STYLES['function']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']), # From '//' until a newline (r'//[^\n]*', 0, STYLES['comment']), #Comments between /* and */ (r'\/\*(?:(?!\*)(?:.|[\r\n]+))*\*\/', 1, STYLES['comment']), ] #Python comment if str(syntax_mode) == "py": highlight_rules += [ # From '#' until a newline (r'#[^\n]*', 0, STYLES['comment']), ] elif str(syntax_mode) == "html" or str(syntax_mode) == "htm": highlight_rules += [ (r'\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>', 1, STYLES['comment']), ] highlight_rules += [ # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), # Single-quoted string, possibly containing escape sequences (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']), ] self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in highlight_rules]