Beispiel #1
0
    def get_environment_target(cls, name):
        """Return environment target for environment ``name``.

        Can be overridden to support special environments.

        """
        return ifmember(name, MATH_ENVIRONMENTS, cls.environment_math, cls.environment)
Beispiel #2
0
 def identifier(cls):
     """An ident-token that could be a color or a function()."""
     from .css_words import CSS3_NAMED_COLORS
     action = ifeq(
         TEXT, "transparent", Literal.Color,
         ifmember(TEXT, CSS3_NAMED_COLORS, Literal.Color, Name.Symbol))
     yield r"\(", Delimiter, cls.function
     yield from cls.identifier_common(action)
Beispiel #3
0
 def ifpitch(cls, itemlist=None, else_itemlist=None):
     """Return a rule item that by default yields Name.Pitch for a pitch, else Name.Symbol."""
     if itemlist is None:
         itemlist = Name.Pitch
     if else_itemlist is None:
         else_itemlist = Name.Symbol
     return ifmember(TEXT, lilypond_words.all_pitch_names, itemlist,
                     else_itemlist)
Beispiel #4
0
 def root(cls):
     yield fr'^{_S_}+($|(?=#))?', ifgroup(1, Whitespace, Whitespace.Indent)
     yield r'@', Name.Decorator, cls.decorator
     yield fr'(class\b){_S_}*({_I_})', bygroup(
         Keyword,
         ifmember(MATCH[2], python_words.keywords, Invalid,
                  Name.Class.Definition)), cls.classdef
     yield fr'(def\b){_S_}*({_I_})', bygroup(
         Keyword,
         ifmember(MATCH[2], python_words.keywords, Invalid,
                  Name.Function.Definition)), cls.funcdef
     yield fr':(?={_S_}*(?:$|#))', Delimiter.Indent
     yield fr'({_I_})\s*(=)', bygroup(
         select(call(str.isupper, TEXT),
                select(call(isclassname, TEXT), Name.Variable, Name.Class),
                Name.Constant), Operator.Assignment)
     yield from cls.common()
Beispiel #5
0
 def root(cls):
     tag = ifmember(MATCH[2], DOCBOOK_ELEMENTS, Keyword, Name.Tag)
     # copied and modified from Xml to use Keyword for known DB tags
     yield fr'(<\s*?/)\s*({RE_XML_NAME})\s*(>)', bygroup(Delimiter, tag, Delimiter), -1
     yield fr'(<)\s*({RE_XML_NAME})(?:\s*((?:/\s*)?>))?', \
         bygroup(Delimiter, tag, Delimiter), dselect(MATCH[3], {
             None: cls.attrs,        # no ">" or "/>": go to attrs
             ">": cls.tag,           # a ">": go to tag
         })                          # by default ("/>"): stay in context
     yield from super().root
Beispiel #6
0
    def common(cls):
        yield r'#', Comment, cls.comment
        yield fr'({_N_})(\s*)', bygroup(Escape, Whitespace)
        yield r'\[', Delimiter, cls.list
        yield r'\(', Delimiter, cls.tuple
        yield r'\{', Delimiter, cls.dict

        ## string literals
        yield from cls.find_string_literals()
        yield from cls.find_bytes_literals()

        ## numerical values
        yield '0[oO](?:_?[0-7])+', Number.Octal
        yield '0[bB](?:_?[01])+', Number.Binary
        yield '0[xX](?:_?[0-9a-fA-F])+', Number.Hexadecimal
        yield r'(?:\.\d(?:_?\d)*|\d(?:_?\d)*(?:\.(?:\d(?:_?\d)*)?)?)(?:[eE][-+]\d(?:_?\d)*)?[jJ]?', Number

        ## keywords, variables, functions
        yield words(python_words.keywords, prefix=r'\b', suffix=r'\b'), Keyword
        yield words(python_words.constants, prefix=r'\b',
                    suffix=r'\b'), Name.Constant
        yield fr'\b(self|cls)\b(?:{_SN_}*([\[\(]))?', Name.Variable.Special, \
            dselect(MATCH[2], {'(': cls.call, '[': cls.item})
        # method, class or attribute (keywords after a . are also caught)
        yield fr'(\.){_SN_}*\b({_I_})\b(?:{_SN_}*([\[\(]))?', \
            bygroup(
                Delimiter,
                ifmember(MATCH[2], python_words.keywords,
                    Keyword,
                    dselect(MATCH[3], {'(': select(call(isclassname, TEXT), Name.Method, Name.Class)},
                         select(call(str.isupper, TEXT),
                             select(call(isclassname, TEXT), Name.Attribute, Name.Class),
                             Name.Constant))),
                Delimiter), \
            dselect(MATCH[3], {'(': cls.call, '[': cls.item})
        # function, class or variable
        yield fr'\b({_I_})\b(?:{_SN_}*([\[\(]))?', \
            bygroup(
                findmember(MATCH[1],
                    ((python_words.builtins, Name.Builtin),
                     (python_words.exceptions, Name.Exception)),
                    select(call(str.isupper, TEXT),
                        select(call(isclassname, TEXT),
                            dselect(MATCH[2], {'(': Name.Function}, Name.Variable),
                            Name.Class),
                        Name.Constant)),
                Delimiter), \
            dselect(MATCH[2], {'(': cls.call, '[': cls.item})

        ## delimiters, operators
        yield r'\.\.\.', Delimiter.Special.Ellipsis
        yield r'(?:\*\*|//|<<|>>|[-+*/%@&|^:])?=', Operator.Assignment
        yield r'\*\*|//|<<|>>|[<>=!]=|[-+*/%@&|^~<>]', Operator
        yield r'[.;,:]', Delimiter
Beispiel #7
0
 def get_markup_action(cls):
     r"""Get the action for a command in \markup { }."""
     return ifmember(MATCH[1], lilypond_words.markup_commands,
                     Name.Function.Markup, Name.Function)
Beispiel #8
0
 def property(cls):
     """A CSS property."""
     from .css_words import CSS3_ALL_PROPERTIES
     action = ifmember(TEXT, CSS3_ALL_PROPERTIES, Name.Property.Definition,
                       Name.Property)
     yield from cls.identifier_common(action)
Beispiel #9
0
 def get_word_action(cls):
     """Return a dynamic action that is chosen based on the text."""
     from . import scheme_words
     return ifmember(TEXT, scheme_words.keywords, Keyword, Name)