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]
        rules += [(r'%s' % b, 0, STYLES['builtinFunction'])
                  for b in dir(builtins)]

        # All other rules
        rules += [
            # 'self'
            (r'\bself\b', 0, STYLES['self']),
            (r'\bsetData\b', 0, STYLES['dataAccess']),
            (r'\bgetData\b', 0, STYLES['dataAccess']),
            (r'\bsetClean\b', 0, STYLES['dataAccess']),
            (r'\bsetDirty\b', 0, STYLES['dataAccess']),
            (r'\bcurrentData\b', 0, STYLES['dataAccess']),

            # 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]
Ejemplo n.º 2
0
    def __init__(self, document):
        QSyntaxHighlighter.__init__(self, document)
        self.comments = (QRegExp(r"/\*"), QRegExp(r"\*/"), 1,
                         STYLES['string2'])
        rules = []

        # Keyword, operator, and brace rules
        rules += [(r'\b%s\b' % w, 0, STYLES['keyword'])
                  for w in MelHighlighter.keywords]
        rules += [(r'\b%s\b' % w, 0, STYLES['string2'])
                  for w in MelHighlighter.keywords2]
        rules += [(r'%s' % o, 0, STYLES['operator'])
                  for o in MelHighlighter.operators]
        rules += [(r'%s' % b, 0, STYLES['brace'])
                  for b in MelHighlighter.braces]

        # All other rules

        # Build a QRegExp for each pattern
        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']),

            # Double-quoted string, possibly containing escape sequences
            (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']),

            # 'def' followed by an identifier
            (r'\bproc\b\s*(\w+)', 1, STYLES['defclass']),
            # 'class' followed by an identifier
            (r'\bglobal\b\s*(\w+)', 1, STYLES['defclass']),

            # From '//' until a newline
            (r'//[^\n]*', 0, STYLES['comment']),
        ]
        self.rules = [(QRegExp(pat), index, fmt)
                      for (pat, index, fmt) in rules]
Ejemplo n.º 3
0
 def __init__(self, parent=None):
     QSyntaxHighlighter.__init__(self, parent)