U ʗRe} @sdZddlZddlZddlZddlmZmZddlmZddl m Z m Z m Z m Z ddlmZmZmZmZmZmZddlmZdd d d d d ddddddg ZdddddgZeddZGdddeZGdddedZGdd d eZGd d d eZ Gd!d"d"Z!e!Z"Gd#d$d$e#Z$Gd%d&d&Z%d'dZ&Gd(d)d)Z'e'Z(d*dZ)Gd+ddZ*Gd,ddeZ+Gd-d.d.eZ,Gd/d d ee,dZ-Gd0d d Z.Gd1d d e-Z/d2d3Z0Gd4d5d5e,Z1Gd6d7d7e-e1dZ2dS)8z pygments.lexer ~~~~~~~~~~~~~~ Base lexer classes. :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. N) apply_filtersFilter)get_filter_by_name)ErrorTextOther _TokenType) get_bool_opt get_int_opt get_list_optmake_analysatorFuture guess_decode) regex_optLexer RegexLexerExtendedRegexLexerDelegatingLexer LexerContextincludeinheritbygroupsusingthisdefaultwords)sutf-8)szutf-32)szutf-32be)szutf-16)szutf-16becCsdS)Nxrr/builddir/build/BUILDROOT/alt-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_vendor/pygments/lexer.py!r"c@seZdZdZddZdS) LexerMetaz This metaclass automagically converts ``analyse_text`` methods into static methods which always return float values. cCs(d|krt|d|d<t||||S)N analyse_text)r type__new__)mcsnamebasesdrrr!r'*szLexerMeta.__new__N)__name__ __module__ __qualname____doc__r'rrrr!r$$sr$c@s^eZdZdZdZdZgZgZgZgZ dZ ddZ ddZ dd Z d d Zdd dZddZdS)ra Lexer for a specific language. Basic options recognized: ``stripnl`` Strip leading and trailing newlines from the input (default: True). ``stripall`` Strip all leading and trailing whitespace from the input (default: False). ``ensurenl`` Make sure that the input ends with a newline (default: True). This is required for some lexers that consume input linewise. .. versionadded:: 1.3 ``tabsize`` If given and greater than 0, expand tabs in the input (default: 0). ``encoding`` If given, must be an encoding name. This encoding will be used to convert the input string to Unicode, if it is not already a Unicode string (default: ``'guess'``, which uses a simple UTF-8 / Locale / Latin1 detection. Can also be ``'chardet'`` to use the chardet library, if it is installed. ``inencoding`` Overrides the ``encoding`` if given. NrcKs||_t|dd|_t|dd|_t|dd|_t|dd|_|dd |_|d pZ|j|_g|_ t |d d D]}| |qpdS) NstripnlTstripallFensurenltabsizerencodingguess inencodingfiltersr) optionsr r0r1r2r r3getr4r7r add_filter)selfr8filter_rrr!__init__aszLexer.__init__cCs(|jrd|jj|jfSd|jjSdS)Nzz)r8 __class__r,r;rrr!__repr__ms zLexer.__repr__cKs&t|tst|f|}|j|dS)z8 Add a new stream filter to this lexer. N) isinstancerrr7append)r;r<r8rrr!r:ts  zLexer.add_filtercCsdS)a~ Has to return a float between ``0`` and ``1`` that indicates if a lexer wants to highlight this text. Used by ``guess_lexer``. If this method returns ``0`` it won't highlight it in any case, if it returns ``1`` highlighting with this lexer is guaranteed. The `LexerMeta` metaclass automatically wraps this function so that it works like a static method (no ``self`` or ``cls`` parameter) and the return value is automatically converted to `float`. If the return value is an object that is boolean `False` it's the same as if the return values was ``0.0``. Nr)textrrr!r%|szLexer.analyse_textFc sttsjdkr$t\}nވjdkrzddlm}Wn,tk rj}ztd|W5d}~XYnXd}tD].\}}|rtt |d |d}qqt|dkr| dd}  | d pd d}|n( jd r t d dnd r t d d d d  dd jrJnjr\d jdkrtjjrd sd 7fdd} | } |st| j} | S)a= Return an iterable of (tokentype, value) pairs generated from `text`. If `unfiltered` is set to `True`, the filtering mechanism is bypassed even if filters are defined. Also preprocess the text, i.e. expand tabs and strip it if wanted and applies registered filters. r5chardetr)rDzkTo enable chardet encoding guessing, please install the chardet library from http://chardet.feedparser.org/Nreplaceir4ruz   c3s$D]\}}}||fVq dSN)get_tokens_unprocessed)_tvr;rCrr!streamersz"Lexer.get_tokens..streamer)rAstrr4r pip._vendorrD ImportError _encoding_map startswithlendecodedetectr9rEr1stripr0r3 expandtabsr2endswithrr7) r;rC unfilteredrJrDedecodedbomr4encrNstreamrrMr! get_tokenssR              zLexer.get_tokenscCstdS)z Return an iterable of (index, tokentype, value) pairs where "index" is the starting position of the token within the input text. In subclasses, implement this method as a generator to maximize effectiveness. N)NotImplementedErrorrMrrr!rIszLexer.get_tokens_unprocessed)F)r,r-r.r/r)urlaliases filenamesalias_filenames mimetypespriorityr=r@r:r%r`rIrrrr!r0s  ;) metaclassc@s$eZdZdZefddZddZdS)ra  This lexer takes two lexer as arguments. A root lexer and a language lexer. First everything is scanned using the language lexer, afterwards all ``Other`` tokens are lexed using the root lexer. The lexers from the ``template`` lexer package use this base lexer. cKs0|f||_|f||_||_tj|f|dSrH) root_lexerlanguage_lexerneedlerr=)r; _root_lexer_language_lexer_needler8rrr!r=s  zDelegatingLexer.__init__cCsd}g}g}|j|D]H\}}}||jkrP|rF|t||fg}||7}q||||fq|rx|t||ft||j|S)N)rjrIrkrBrT do_insertionsri)r;rCbuffered insertions lng_bufferirKrLrrr!rIs   z&DelegatingLexer.get_tokens_unprocessedN)r,r-r.r/rr=rIrrrr!rs c@seZdZdZdS)rzI Indicates that a state should include rules from another state. Nr,r-r.r/rrrr!rsc@seZdZdZddZdS)_inheritzC Indicates the a state should inherit from its superclass. cCsdS)Nrrr?rrr!r@sz_inherit.__repr__N)r,r-r.r/r@rrrr!rvsrvc@s eZdZdZddZddZdS)combinedz: Indicates a state combined from multiple states. cGs t||SrH)tupler')clsargsrrr!r' szcombined.__new__cGsdSrHr)r;rzrrr!r=szcombined.__init__N)r,r-r.r/r'r=rrrr!rwsrwc@sFeZdZdZddZdddZdddZdd d Zd d Zd dZ dS) _PseudoMatchz: A pseudo match object constructed from a string. cCs||_||_dSrH)_text_start)r;startrCrrr!r=sz_PseudoMatch.__init__NcCs|jSrH)r}r;argrrr!r~sz_PseudoMatch.startcCs|jt|jSrH)r}rTr|rrrr!end!sz_PseudoMatch.endcCs|r td|jS)Nz No such group) IndexErrorr|rrrr!group$sz_PseudoMatch.groupcCs|jfSrH)r|r?rrr!groups)sz_PseudoMatch.groupscCsiSrHrr?rrr! groupdict,sz_PseudoMatch.groupdict)N)N)N) r,r-r.r/r=r~rrrrrrrr!r{s   r{csdfdd }|S)zL Callback that yields multiple actions for each group in the match. Nc3stD]\}}|dkrqqt|tkrR||d}|r||d||fVq||d}|dk r|r|||d|_||t||d||D]}|r|Vqq|r||_dS)N) enumerater&rrr~posr{r)lexermatchctxrtactiondataitemrzrr!callback4s&  zbygroups..callback)Nr)rzrrrr!r0sc@seZdZdZdS)_ThiszX Special singleton used for indicating the caller class. Used by ``using``. Nrurrrr!rJsrc sjidkr:d}t|ttfr.|d<n d|fd<tkrTdfdd }nd fdd }|S) a Callback that processes the match with a different lexer. The keyword arguments are forwarded to the lexer, except `state` which is handled separately. `state` specifies the state that the new lexer will start in, and can be an enumerable such as ('root', 'inline', 'string') or a simple string which is assumed to be on top of the root state. Note: For that to work, `_other` must not be an `ExtendedRegexLexer`. statestackrootNc3sjr|j|jf}n|}|}|j|fD]\}}}||||fVq<|rf||_dSrH)updater8r>r~rIrrrrrrlxsrtrKrL) gt_kwargskwargsrr!ris zusing..callbackc3s^|jf}|}|j|fD]\}}}||||fVq0|rZ||_dSrH)rr8r~rIrrrr_otherrrrr!rxs  )N)N)poprAlistrxr)rrrrrrr!rSs     c@seZdZdZddZdS)rz Indicates a state or state action (e.g. #pop) to apply. For example default('#pop') is equivalent to ('', Token, '#pop') Note that state tuples may be used as well. .. versionadded:: 2.0 cCs ||_dSrH)r)r;rrrr!r=szdefault.__init__N)r,r-r.r/r=rrrr!rsc@s"eZdZdZdddZddZdS) rz Indicates a list of literal words that is transformed into an optimized regex that matches any of the words. .. versionadded:: 2.0 rocCs||_||_||_dSrH)rprefixsuffix)r;rrrrrr!r=szwords.__init__cCst|j|j|jdS)Nrr)rrrrr?rrr!r9sz words.getN)roro)r,r-r.r/r=r9rrrr!rs c@sJeZdZdZddZddZddZdd Zdd d Zd dZ ddZ d S)RegexLexerMetazw Metaclass for RegexLexer, creates the self._tokens attribute from self.tokens on the first instantiation. cCs t|tr|}t||jS)zBPreprocess the regular expression component of a token definition.)rAr r9recompiler)ryregexrflagsrrrr!_process_regexs zRegexLexerMeta._process_regexcCs&t|tks"t|s"td|f|S)z5Preprocess the token component of a token definition.z2token type must be simple type or callable, not %r)r&rcallableAssertionError)rytokenrrr!_process_tokenszRegexLexerMeta._process_tokencCst|trd|dkrdS||kr$|fS|dkr0|S|dddkrRt|dd Sdsbtd|nt|trd |j}|jd 7_g}|D],}||kstd ||||||q|||<|fSt|tr|D] }||ks|d kstd |q|Sdstd|dS)z=Preprocess the state transition action of a token definition.#pop#pushNz#pop:Fzunknown new state %rz_tmp_%drzcircular state ref %r)rrzunknown new state zunknown new state def %r) rArOintrrw_tmpnameextend_process_staterx)ry new_state unprocessed processed tmp_stateitokensistaterrr!_process_new_states>     z!RegexLexerMeta._process_new_statec Cst|tkstd||ddks0td|||kr@||Sg}||<|j}||D].}t|tr||ks~td|||||t|qZt|trqZt|t r| |j ||}| t djd|fqZt|tkstd|z||d||}Wn>tk rD} ztd |d||| f| W5d} ~ XYnX||d } t|d krhd}n| |d ||}| || |fqZ|S) z%Preprocess a single state definition.zwrong state name %rr#zinvalid state name %rzcircular state reference %rroNzwrong rule def %rz+uncompilable regex %r in state %r of %r: %sr)r&rOrflagsrArrrrvrrrrBrrrrxr Exception ValueErrorrrT) ryrrrtokensrtdefrrexerrrrrr!rsJ      zRegexLexerMeta._process_stateNcCs<i}|j|<|p|j|}t|D]}||||q$|S)z-Preprocess a dictionary of token definitions.) _all_tokensrrr)ryr) tokendefsrrrrr!process_tokendefs  zRegexLexerMeta.process_tokendefc Csi}i}|jD]}|jdi}|D]\}}||}|dkr||||<z|t}Wntk rpYq(YnX|||<q(||d}|dkrq(||||d<z|t} Wntk rYq(X|| ||<q(q|S)a Merge tokens from superclasses in MRO order, returning a single tokendef dictionary. Any state that is not defined by a subclass will be inherited automatically. States that *are* defined by subclasses will, by default, override that state in the superclass. If a subclass wishes to inherit definitions from a superclass, it can use the special value "inherit", which will cause the superclass' state definition to be included at that point in the state. rNr)__mro____dict__r9itemsindexrrr) ryr inheritablectoksrrcuritems inherit_ndx new_inh_ndxrrr! get_tokendefs s0     zRegexLexerMeta.get_tokendefscOsLd|jkr:i|_d|_t|dr(|jr(n|d||_tj |f||S)z:Instantiate cls after preprocessing its token definitions._tokensrtoken_variantsro) rrrhasattrrrrrr&__call__)ryrzkwdsrrr!r;s zRegexLexerMeta.__call__)N) r,r-r.r/rrrrrrrrrrr!rs#, 1rc@s$eZdZdZejZiZdddZdS)rz Base for simple stateful regular expression-based lexers. Simplifies the lexing process so that you need only provide a list of states and regular expressions. rc csd}|j}t|}||d}|D](\}}} |||} | r"|dk rrt|tkrb||| fVn||| EdH| }| dk rHt| tr| D]D} | dkrt|dkr| q| dkr| |dq| | qnbt| t rt | t|kr|dd=n || d=n,| dkr*| |dndsMetaclass for ProfilingRegexLexer, collects regex timing info.csLt|tr t|j|j|jdn|t|tjffdd }|S)Nrcs`jdfddg}t}|||}t}|dd7<|d||7<|S)Nrrrr) _prof_data setdefaulttimer)rCrendposinfot0rest1rycompiledrrrr! match_funcMsz:ProfilingRegexLexerMeta._process_regex..match_func) rArrrrrrsysmaxsize)ryrrrrrrr!rEs   z&ProfilingRegexLexerMeta._process_regexN)r,r-r.r/rrrrr!rBsrc@s"eZdZdZgZdZdddZdS)ProfilingRegexLexerzFDrop-in replacement for RegexLexer that does profiling of its regexes.rc#sjjit||EdHjj}tdd|Dfdddd}tdd|D}t t djj t ||ft d t d d t d |D]}t d |qt d dS)NcssN|]F\\}}\}}|t|ddddd|d|d||fVqdS)zu'z\\\NAi)reprrWrE).0rrnrKrrr! cs  z=ProfilingRegexLexer.get_tokens_unprocessed..cs |jSrH)_prof_sort_indexrr?rr!r"fr#z.T)keyreversecss|]}|dVqdS)Nr)rr rrr!rhsz2Profiling result for %s lexing %d chars in %.3f mszn==============================================================================================================z$%-20s %-64s ncalls tottime percall)rrzn--------------------------------------------------------------------------------------------------------------z%-20s %-65s %5d %8.4f %8.4f) r>rrBrrIrsortedrsumprintr,rT)r;rCrrawdatar sum_totalr+rr?r!rI^s(   z*ProfilingRegexLexer.get_tokens_unprocessedN)r)r,r-r.r/rrrIrrrr!rXsr)3r/rrrpip._vendor.pygments.filterrrpip._vendor.pygments.filtersrpip._vendor.pygments.tokenrrrrpip._vendor.pygments.utilr r r r r rpip._vendor.pygments.regexoptr__all__rR staticmethod_default_analyser&r$rrrOrrvrrxrwr{rrrrrrrrrrrprrrrrr!s`      !' 2 )aH@