def __init__(self, document): """""" QSyntaxHighlighter.__init__(self, document) rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, self.styles['keyword']) for w in CSSHighlighter.keywords] rules += [(r'( )', 0, format('#4f5b62'))] # All other rules rules += [(r'"[^"\\]*(\\.[^"\\]*)*"', 0, self.styles['value']), (r"'[^'\\]*(\\.[^'\\]*)*'", 0, self.styles['value']), (r'^([\w]+)[#\.\w\[\]=]*\s*\{', 1, self.styles['selector']), (r'^\s*([\w-]+)\s*:\s*([\w\'"#]+)', 1, self.styles['key']), (r'^\s*([\w-]+)\s*:\s*([\w\'"#]+)', 2, self.styles['value']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, self.styles['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, self.styles['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, self.styles['numbers']), ] # Build a QRegularExpression for each pattern self.rules = [(QRegularExpression(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, parent): QSyntaxHighlighter.__init__(self, parent) self.tags = list() self.colos = [ Qt.darkGreen, Qt.darkMagenta, Qt.darkRed, Qt.darkBlue, Qt.darkCyan, Qt.darkYellow ] self.tagColorMap = dict()
def __init__(self, document, styles): """ :param document: :type document: the textEdit document :param styles: The style dict :type styles: dict """ QSyntaxHighlighter.__init__(self, document) colors = styles["colors"] syntax = styles["syntax"] self.tri_single = (QRegExp("'''"), 1, colors['string']) self.tri_double = (QRegExp('"""'), 2, colors['string']) rules = [ # 'self' (r'\bself\b', 0, colors['self']), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, colors['string']), # Single-quoted string, possibly containing escape sequences (r"'[^'\\]*(\\.[^'\\]*)*'", 0, colors['string']), # 'def' followed by an identifier (r'\bdef\b\s*(\w+)', 1, colors['methods']), # 'class' followed by an identifier (r'\bclass\b\s*(\w+)', 1, colors['defclass']), # From '#' until a newline (r'#[^\n]*', 0, colors['comment']), (r"\\b[A-Za-z0-9_]+(?=\\()", 0, colors['methods']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, colors['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, colors['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, colors['numbers']), ] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, colors['keyword']) for w in syntax["keywords"]] rules += [(r'\b%s\b' % w, 0, colors['preprocessor']) for w in syntax["preprocessors"]] rules += [(r'\b%s\b' % w, 0, colors['special']) for w in syntax["specials"]] rules += [(r'%s' % o, 0, colors['operator']) for o in syntax["operators"]] rules += [(r'%s' % b, 0, colors['brace']) for b in syntax["braces"]] # 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 = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in SyntaxHighlighter.keywords] rules += [(r'%s' % o, 0, STYLES['operator']) for o in SyntaxHighlighter.operators] rules += [(r'%s' % b, 0, STYLES['brace']) for b in SyntaxHighlighter.braces] # All other rules rules += [ # 'self' (r'\bself\b', 0, STYLES['self']), # Click # Click\s *\((.* ?)\) (r'Click\s *\((.* ?)\)', 1, STYLES['defclass']), # Wait # Wait\s*\(\d\) (r'Wait\s*\(\d\)', 1, STYLES['defclass']), # Type # Type\s *\((.* ?)\) (r'Type\s *\((.* ?)\)', 1, STYLES['defclass']), # Press # Press\s *\((.* ?)\) (r'Press\s *\((.* ?)\)', 1, STYLES['defclass']), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), # Single-quoted string, possibly containing escape sequences (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']), # 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): 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 = (QRegularExpression("'''"), 1, self.styles['string2']) self.tri_double = (QRegularExpression('"""'), 2, self.styles['string2']) rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, self.styles['keyword']) for w in PythonHighlighter.keywords_bold] rules += [(r'\b%s\b' % w, 0, self.styles['keyword2']) for w in PythonHighlighter.keywords] rules += [(r'\b%s\b' % o, 0, self.styles['operator']) for o in PythonHighlighter.operators] rules += [(r'\b%s\b' % b, 0, self.styles['brace']) for b in PythonHighlighter.braces] # All other rules rules += [ # 'def' followed by an identifier (r'\bdef\b\s*(\w+)', 1, self.styles['def']), # 'class' followed by an identifier (r'\bclass\b\s*(\w+)', 1, self.styles['class']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, self.styles['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, self.styles['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, self.styles['numbers']), # From '#' until a newline (r"""#[^\n'{2}"{2}]*""", 0, self.styles['comment']), # Double and Single-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, self.styles['string']), (r"'[^'\\]*(\\.[^'\\]*)*'", 0, self.styles['string']), # Complete line commented (r'^[\s]*(#[^\n]*)', 1, self.styles['comment']), # Decorators (r'^[\s]*(@[^(]*)', 1, self.styles['decorator']), ] # Build a QRegularExpression for each pattern self.rules = [(QRegularExpression(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, document, config): """ Handles the highlighting of the identified elements :param document: QPlaintTextEdit's document to format """ QSyntaxHighlighter.__init__(self, document) self.styles = { 'label': self.get_format(config.get('colors', 'asm_labels'), 'italic'), } self.rules = [] self.init_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 = [ (r'.', 0, STYLES["text"]), ] # 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']), # 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, database=None, *args): QSyntaxHighlighter.__init__(self, *args) self._on = True # Access to (esoteric) dictionary databases self._database = database # Rules for specifically handling the esoteric words and definitions. if self._database is not None: self.updateRules() # Initialize private members self._sp_dict = None self._chunkers = []
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']), # 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, config): """ Handles the syntax highlighting for assemble language :param document: QPlaintTextEdit's document to format """ QSyntaxHighlighter.__init__(self, document) self.styles = { 'keyword': self.get_format(config.get('colors', 'asm_keywords')), 'comment': self.get_format(config.get('colors', 'asm_comments')), 'label': self.get_format(config.get('colors', 'asm_labels'), 'italic'), 'directive': self.get_format(config.get('colors', 'asm_directives')), 'numbers': self.get_format(config.get('colors', 'asm_numbers'), 'bold') } self.rules = [] self.keywords = [] self.init_rules([]) # Initialization with no keywords
def __init__(self, parent=None): QSyntaxHighlighter.__init__(self, parent) self._mappings = {}
def __init__(self, document): QSyntaxHighlighter.__init__(self, document)