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
def root(cls): yield r"'", String.Start, cls.string("'") yield r'"', String.Start, cls.string('"') yield r'`', String.Start, cls.template_literal yield '//', Comment, cls.singleline_comment yield r'/\*', Comment.Start, cls.multiline_comment yield fr'(const|let|var)\s+({_I_})\b', bygroup(Keyword, Name.Variable.Definition) yield fr'(function)\s+({_I_})\b', bygroup(Keyword, Name.Function.Definition) yield fr'(new)\s+({_I_})\b', bygroup(Keyword, Name.Class.Definition) yield words(js.JAVASCRIPT_KEYWORDS, prefix=r'\b', suffix=r'\b'), Keyword yield words(js.JAVASCRIPT_DECLARATORS, prefix=r'\b', suffix=r'\b'), Keyword yield words(js.JAVASCRIPT_RESERVED_KEYWORDS, prefix=r'\b', suffix=r'\b'), Keyword.Reserved yield words(js.JAVASCRIPT_CONSTANTS, prefix=r'\b', suffix=r'\b'), Name.Constant yield words(js.JAVASCRIPT_BUILTINS, prefix=r'\b', suffix=r'\b'), Name.Builtin yield words(js.JAVASCRIPT_PROTOTYPES, prefix=r'\b', suffix=r'\b'), Name.Builtin yield fr'(\.)\s*({_I_})\b(?:\s*([\(\[]))?', bygroup(Delimiter, dselect(MATCH[3], {'(': Name.Method}, Name.Attribute), Delimiter), \ dselect(MATCH[3], {'(': cls.call, '[': cls.index}) yield fr'({_I_})(?:\s*([\(\[]))?', bygroup( dselect(MATCH[2], {'(': Name.Function}, Name.Variable), Delimiter), \ dselect(MATCH[2], {'(': cls.call, '[': cls.index}) yield fr'{_I_}\b', select(call(str.isupper, TEXT), Name.Variable, Name.Class) ## numerical values (recently, underscore support inside numbers was added) yield '0[oO](?:_?[0-7])+n?', Number yield '0[bB](?:_?[01])+n?', Number yield '0[xX](?:_?[0-9a-fA-F])+n?', Number yield RE_JS_DECIMAL_NUMBER, Number yield r'\{', Bracket.Start, cls.scope yield r'\[', Bracket.Start, cls.array yield r'\(', Delimiter, cls.paren yield RE_JS_REGEXP, Literal.Regexp yield r'(?:<<|>>>?|[&|^*/%+-])=', Operator.Assignment yield r'&&?|\|\|?|<<|>>>?|[!=]==?|<=?|>=?|\*\*|[-+~!/*%^?:,]', Operator yield r'=', Operator.Assignment yield r';', Delimiter
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()
def root(cls): yield from cls.find_comments() yield fr'(<!)(ENTITY)\b(?:\s*(%))?(?:\s*({_N_}))?', \ bygroup(Delimiter, Keyword, Keyword, Name.Entity.Definition), cls.entity yield fr'(<!)(ELEMENT|ATTLIST|NOTATION)\b(?:\s*({_N_}))?', \ bygroup(Delimiter, Keyword, Name.Element.Definition), \ dselect(MATCH[2], {"ELEMENT": cls.element, "ATTLIST": cls.attlist}, cls.notation) yield fr'%{_N_};', Name.Entity.Escape yield default_action, select(call(str.isspace, TEXT), Text, skip)
def _markup_rules(cls, *extra_target): r"""Markup rules. Specify ``-1`` if outside an environment.""" yield (r'\{', Bracket.Markup.Start, *extra_target, cls.markuplist) yield (r"(\\score(?:-lines)?)\s*(\{)", bygroup(Name.Function.Markup, Bracket.Start), *extra_target, cls.markupscore) if extra_target: # count the arguments of markup commands and stack markup contexts yield RE_LILYPOND_COMMAND, cls.get_markup_action(), \ select(call(cls.get_markup_argument_count, MATCH[1]), -1, 0, 1, 2, 3) else: # in an environment; no need to count the arguments. yield RE_LILYPOND_COMMAND, cls.get_markup_action() yield from cls.find_string(*extra_target) yield from cls.find_scheme(*extra_target) yield from cls.find_comment() yield (RE_LILYPOND_MARKUP_TEXT, Text, *extra_target)
def root(cls): yield from cls.find_comments() yield r'(<!\[)(CDATA)(\[)', bygroup(Delimiter, Data.Definition, Delimiter), cls.cdata yield fr'(<!)(DOCTYPE)\b(?:\s*({_N_}))?', \ bygroup(Delimiter, Keyword, Name.Tag.Definition), cls.doctype yield fr'(<\?)({_N_})?', bygroup(Bracket.Preprocessed.Start, Name.Tag.Preprocessed), \ cls.processing_instruction yield fr'(<\s*?/)\s*({_N_})\s*(>)', bygroup(Delimiter, Name.Tag, Delimiter), -1 yield fr'(<)\s*({_N_})(?:\s*((?:/\s*)?>))?', \ bygroup(Delimiter, Name.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 r'&\S*?;', Escape yield default_action, select(call(str.isspace, TEXT), Text, Whitespace)
def array_table(cls): yield r'(?:(\.)[ \t]*)?(\]\])([^\n#]*)', \ bygroup(Invalid, Bracket.End, select(call(str.isspace, TEXT), Invalid, skip)), -1 yield from cls.keys(Name.Namespace)
def array(cls): yield r'(\])([^,}#\n\]]*)', bygroup( Bracket, select(call(str.isspace, TEXT), Invalid, skip)), -1 yield r',', Separator yield from cls.values()