def values(cls): yield r'\[', Delimiter, cls.command yield r'"', String, cls.quoted yield r'\{', Delimiter.Bracket, cls.braced yield r'(\$(?:[0-9a-zA-Z_]|::+)+)(\()?', \ bygroup(Name.Variable, Delimiter), ifgroup(2, cls.index) yield r'\${.*?\}', Name.Variable yield r'\\(?:[0-7]{1,3}|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|\n|.)', Escape yield r'^\s*(#)', bygroup(Comment), cls.comment yield RE_TCL_NUMBER, gselect(Number.Octal, Number.Binary, Number.Hexadecimal, Number.Decimal) yield r'(;)(?:[ \t]*(#))?', bygroup(Delimiter.Separator, Comment), \ ifgroup(2, cls.comment)
def common(cls): yield r'(\\begin)(?:\s*(?:(\{)(.*?)(\})|(\[))|(?=[\W\d]))', \ bygroup(Name.Builtin, Delimiter, Name.Tag, Delimiter, Delimiter.Bracket), \ ifgroup(5, cls.environment_option, cls.get_environment_target(MATCH[3])) yield r'(\\[^\W\d]+)(?:\s*(\[))?', bygroup(Name.Command, Delimiter.Bracket), \ ifgroup(2, cls.option) yield r'\{\\(oe|OE|ae|AE|aa|AA|o|O|l|L|ss|SS)\}', Escape yield r"[!?]'", Escape yield r"""\\[`'^"~=.]([a-zA-Z]{1,2}|\\[ij])(?=[\W\d])""", Escape yield r"""\\[`'^"~=.uvHtcdbr]\{([a-zA-Z]{1,2}|\\[ij])\}""", Escape yield r'\{', Delimiter.Brace, cls.brace yield r'\\\[', Delimiter, cls.math(r'\]') yield r'\$\$', Delimiter, cls.math(r'$$') yield r'\\\(', Delimiter, cls.math(r'\)') yield r'\$', Delimiter, cls.math(r'$') yield from cls.base()
def root(cls): yield r'@[@{}. ]', Escape yield r'''@['",=^`~](\{[a-zA-Z]\}|[a-zA-Z]\b)''', Escape yield r'@c(?:omment)?\b', Comment, cls.singleline_comment yield r'@ignore\b', Comment, cls.multiline_comment yield r'@verbatim\b', Keyword.Verbatim, cls.verbatim yield r'@html', Keyword, cls.html yield r'(@lilypond)\b(?:(\[)([^\n\]]*)(\]))?(\{)?', bygroup( Name.Function, Bracket, Name.Property, Bracket, Bracket.Start), \ ifgroup(5, cls.lilypond_brace, cls.lilypond_block) yield r'(@[a-zA-Z]+)(?:(\{)(\})?)?', bygroup( ifgroup(2, ifgroup(3, Name.Symbol, Name.Function), Name.Command), Bracket.Start, Bracket.End), \ ifgroup(2, ifgroup(3, (), cls.brace)) yield default_action, Text
def root(cls): yield r'\A#!.*?$', Comment.Special yield from cls.values() yield r"([^\s\\{}[\]$'();]+)(\()?", bygroup( findmember(MATCH[1], ((operators, Operator), (tcl_commands, Keyword), (tk_commands, Name.Command)), Text.Word), Delimiter), ifgroup(2, cls.index) yield r'\(\)', Delimiter
def attlist(cls): yield words(("#REQUIRED", "#IMPLIED", "#FIXED"), suffix=r'\b'), Name.Builtin yield words(('CDATA', 'ID', 'IDREF', 'IDREFS', 'ENTITY', 'ENTITIES', 'NMTOKEN', 'NMTOKENS'), prefix=r'\b', suffix=r'\b'), Name.Type yield r'\b(NOTATION)\b(?:\s+(\())', bygroup(Name.Type, Bracket), \ ifgroup(2, cls.attlist_notation) yield _N_, Name.Attribute.Definition yield r'\(', Bracket, cls.attlist_enumeration yield from cls.common_defs() yield r'>', Delimiter, -1
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 commands(cls, *, list_target=0): """Yield commands that can occur in all input modes. If a ``list_target`` is given, that lexicon is pushed after a Keyword, to be able to parse symbols, strings, numbers or scheme. This makes sense in e.g. lyrics mode. """ yield r"(\\with)\s*(\{)", bygroup(Keyword, Bracket.Start), cls.layout_context yield r'(' + RE_LILYPOND_COMMAND + r')(?=\s*(\.))?', ifgroup( 3, # part of a \bla.bla or \bla.1 construct, always a user command (Name.Variable, cls.identifier_ref), # no "." or "," , can be a builtin dselect( MATCH[2], { # input modes "lyricsto": (Keyword.Lyric, cls.lyricsto, cls.start_list), "addlyrics": (Keyword.Lyric, cls.lyricmode), "lyrics": (Keyword.Lyric, cls.lyricmode), "lyricmode": (Keyword.Lyric, cls.lyricmode), "chords": (Keyword, cls.chordmode), "chordmode": (Keyword, cls.chordmode), "drums": (Keyword, cls.drummode), "drummode": (Keyword, cls.drummode), "figures": (Keyword, cls.figuremode), "figuremode": (Keyword, cls.figuremode), "notemode": (Keyword, cls.notemode), # \notes doesn't exist anymore # commands that expect some symbols in all input modes "repeat": (Name.Builtin, cls.repeat), }, (findmember(MATCH[2], ( (lilypond_words.keywords, (Keyword, list_target)), (lilypond_words.all_articulations, Articulation), (lilypond_words.dynamics, Dynamic), (lilypond_words.units, Name.Builtin.Unit), (lilypond_words.music_commands, Name.Builtin), (lilypond_words.contexts, Name.Builtin.Context), (lilypond_words.modes, Name.Type), ), (Name.Variable, cls.identifier_ref))))) # seldom used, but nevertheless allowed in LilyPond: \"blabla" yield r'(\\)(?=")', Name.Variable, cls.identifier_ref
def environment_option(cls): yield r'(\])\s*(?:(\{)(.*?)(\})|(\[))?', \ bygroup(Delimiter.Bracket, Delimiter, Name.Tag, Delimiter, Delimiter.Bracket), \ ifgroup(5, 0, (-1, ifgroup(4, cls.get_environment_target(MATCH[3])))) yield from list(cls.option())[1:] # not the first rule
def option(cls): yield r'(\])(?:\s*(\[))?', Delimiter.Bracket, ifgroup(2, 0, -1) yield from cls.common() yield default_action, Pseudo # TODO: find better action