ProjectKivy/KivyLexer.py

Sun, 24 Jan 2016 13:40:08 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 24 Jan 2016 13:40:08 +0100
changeset 32
1264664c5ba9
parent 31
0c20b8d83f0b
child 34
dee6b8a3245a
permissions
-rw-r--r--

Fixed a bug in the Kivy lexer causing all strings to be unicodes on Python2, which makes Pygments raise an exception.

# -*- coding: utf-8 -*-

# Copyright (c) 2013 - 2016 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a Pygments lexer for the Kivy language.
"""

#
# Lexer class is derived from the highlighter contained in the Kivy package.
# Copyright of the original by the Kivy Team.
#

from pygments.lexer import RegexLexer, bygroups, using
from pygments.lexers.agile import PythonLexer
from pygments.token import Comment, Text, Name, Punctuation, Operator

__all__ = ['KivyLexer']


class KivyLexer(RegexLexer):
    """
    Class implementing a Pygments lexer for the Kivy language.
    """
    name = 'Kivy'
    aliases = ['kivy', 'kv']
    filenames = ['*.kv', '*.kivy']
    mimetypes = ['application/x-kivy']
    tokens = {
        'root': [
            (r'#:.*?$', Comment.Preproc),
            (r'#.*?$', using(PythonLexer)),
            (r'\s+', Text),
            (r'<.+>', Name.Namespace),
            (r'(\[)(\s*)(.*?)(\s*)(@)',
                bygroups(Punctuation, Text, Name.Class, Text, Operator),
                'classList'),
            (r'[A-Za-z][A-Za-z0-9]*$', Name.Attribute),
            (r'(.*?)(\s*)(:)(\s*)$',
                bygroups(Name.Class, Text, Punctuation, Text)),
            (r'(.*?)(\s*)(:)(\s*)(.*?)$',
                bygroups(Name.Attribute, Text, Punctuation, Text,
                         using(PythonLexer)))],
        'classList': [
            (r'(,)(\s*)([A-Z][A-Za-z0-9]*)',
                bygroups(Punctuation, Text, Name.Class)),
            (r'(\+)(\s*)([A-Z][A-Za-z0-9]*)',
                bygroups(Operator, Text, Name.Class)),
            (r'\s+', Text),
            (r'[A-Z][A-Za-z0-9]*', Name.Class),
            (r'\]', Punctuation, '#pop')]}

#
# eflag: noqa = M702

eric ide

mercurial