ProjectKivy/KivyLexer.py

Wed, 21 Sep 2022 16:27:00 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 21 Sep 2022 16:27:00 +0200
branch
eric7
changeset 50
265ebe67da39
parent 47
072c7c4791d4
child 57
ebf3e41eff26
permissions
-rw-r--r--

Reformatted source code with 'Black'.

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

# Copyright (c) 2013 - 2022 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