ProjectKivy/KivyLexer.py

Thu, 27 May 2021 18:21:00 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 27 May 2021 18:21:00 +0200
branch
eric7
changeset 46
2ff6b838b040
parent 43
e0ec8dc346a0
child 47
072c7c4791d4
permissions
-rw-r--r--

Ported the plug-in to PyQt6 for eric7.

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

# Copyright (c) 2013 - 2021 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))),
            (r'[^:]+?$', 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