Example #1
0
File: html.py Project: wbsoft/parce
 def root(cls):
     yield r'(<)(style|script)\b(>|/\s*>)?', bygroup(Delimiter, Name.Tag, Delimiter), \
         dselect(MATCH[2], {
             "style": dselect(MATCH[3], {'>': cls.css_style_tag, None: cls.attrs("css")}),
             "script": dselect(MATCH[3], {'>': cls.script_tag, None: cls.attrs("js")}),
         })  # by default a close tag, stay in the context.
     yield from super().root
Example #2
0
 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
Example #3
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
Example #4
0
File: html.py Project: wbsoft/parce
 def root(cls):
     yield words(HTML_VOID_ELEMENTS, prefix=r'(<\s*?/)\s*((?:\w+:)?', suffix=r')\s*(>)'), \
         bygroup(Delimiter, Name.Tag, Delimiter) # don't leave no-closing tags
     yield words(HTML_VOID_ELEMENTS, prefix=r'(<)\s*(', suffix=r')(?:\s*((?:/\s*)?>))?'), \
         bygroup(Delimiter, Name.Tag, Delimiter), dselect(MATCH[3], {
             None: cls.attrs("noclose"), # no ">" or "/>": go to attrs/noclose
         })                          # by default ("/>"): stay in context
     yield from super().root
Example #5
0
 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)
Example #6
0
File: html.py Project: wbsoft/parce
 def attrs(cls):
     """Reimplemented to recognize style attributes and switch to style tag."""
     yield r'(style)\s*(=)\s*(")', bygroup(Name.Attribute, Operator, String), \
         cls.css_style_attribute
     yield r'>', Delimiter, -1, dselect(ARG, {
         "js": cls.script_tag,
         "css": cls.css_style_tag,
         None: cls.tag
     })
     yield from super().attrs
Example #7
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
Example #8
0
    def lyriclist(cls):
        """Lyrics between ``{`` ... ``}``.

        Derive with the desired closing delimiter (``}`` or ``>>``).

        """
        yield from cls.inputmode_list(cls.lyriclist)
        yield RE_LILYPOND_LYRIC_TEXT, dselect(TEXT, {
            "--": LyricHyphen,
            "__": LyricExtender,
            "_": LyricSkip,
        }, using(cls.lyricword))
        yield RE_FRACTION, Number.Fraction
        yield RE_LILYPOND_DURATION, Duration, cls.duration
        yield from cls.common()
        yield from cls.commands(list_target=cls.start_list)
Example #9
0
 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)
Example #10
0
 def number(self):
     """Decimal numbers, derive with 2 for binary, 8 for octal, 16 for hexadecimal numbers."""
     yield RE_SCHEME_RIGHT_BOUND, None, -1
     _pat = lambda radix: '[{}]+'.format('0123456789abcdef'[:radix or 10])
     yield pattern(call(_pat, ARG)), \
         dselect(ARG, {2: Number.Binary, 8: Number.Octal, 16: Number.Hexadecimal}, Number.Decimal)
     yield r'[-+]inf.0', Number.Infinity
     yield r'[-+]nan.0', Number.NaN
     yield r'[-+]', Operator.Sign
     yield 'i', Number.Imaginary
     yield ifarg(None, '([esfdl])([-+])?'), bygroup(Number.Exponent,
                                                    Operator.Sign)
     yield ifarg(None, r'\.'), Number.Dot
     yield '@', Separator.Polar
     yield '/', Separator.Fraction
     yield '#+', Number.Special.UnknownDigit
     yield default_action, Number.Invalid
Example #11
0
    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