Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/pygments/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/pygments/__pycache__/lexer.cpython-37.pyc

B

ͽ�\�{�@sdZddlmZddlZddlZddlZddlmZmZddl	m
Z
ddlmZm
Z
mZmZddlmZmZmZmZmZmZmZmZmZddlmZd	d
ddd
dddddddgZdddddgZedd��ZGdd�de �Z!ee!�Gdd	�d	e"��Z#Gdd�de#�Z$Gd d�de%�Z&Gd!d"�d"e"�Z'e'�Z(Gd#d$�d$e)�Z*Gd%d&�d&e"�Z+d'd�Z,Gd(d)�d)e"�Z-e-�Z.d*d�Z/Gd+d�d�Z0Gd,d�de�Z1Gd-d.�d.e!�Z2ee2�Gd/d
�d
e#��Z3Gd0d
�d
e"�Z4Gd1d�de3�Z5d2d3�Z6Gd4d5�d5e2�Z7ee7�Gd6d7�d7e3��Z8dS)8z�
    pygments.lexer
    ~~~~~~~~~~~~~~

    Base lexer classes.

    :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
�)�print_functionN)�
apply_filters�Filter)�get_filter_by_name)�Error�Text�Other�
_TokenType)	�get_bool_opt�get_int_opt�get_list_opt�make_analysator�	text_type�
add_metaclass�	iteritems�Future�guess_decode)�	regex_opt�Lexer�
RegexLexer�ExtendedRegexLexer�DelegatingLexer�LexerContext�include�inherit�bygroups�using�this�default�words)szutf-8)s��zutf-32)s��zutf-32be)s��zutf-16)s��zutf-16becCsdS)Ng�)�xr r �?/opt/alt/python37/lib/python3.7/site-packages/pygments/lexer.py�<lambda>$�r#c@seZdZdZdd�ZdS)�	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__)Zmcs�name�bases�dr r r"r(-szLexerMeta.__new__N)�__name__�
__module__�__qualname__�__doc__r(r r r r"r%'sr%c@sZeZdZdZdZgZgZgZgZdZ	dd�Z
dd�Zdd	�Zd
d�Z
dd
d�Zdd�ZdS)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|_	xt
|dd�D]}|�|�qrWdS)
N�stripnlT�stripallF�ensurenl�tabsizer�encoding�guessZ
inencoding�filtersr )�optionsr
r0r1r2rr3�getr4r6r�
add_filter)�selfr7�filter_r r r"�__init__bszLexer.__init__cCs(|jrd|jj|jfSd|jjSdS)Nz<pygments.lexers.%s with %r>z<pygments.lexers.%s>)r7�	__class__r,)r:r r r"�__repr__ns
zLexer.__repr__cKs&t|t�st|f|�}|j�|�dS)z8
        Add a new stream filter to this lexer.
        N)�
isinstancerrr6�append)r:r;r7r r r"r9us
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 )�textr r r"r&}szLexer.analyse_textFcs�t�t�s�jdkr"t��\�}nʈjdkr�yddl}Wntk
rTtd��YnXd}x4tD],\}}��|�r`�t|�d��	|d�}Pq`W|dkr�|�
�dd��}��	|�d�p�d	d�}|�n&��	�j����d
�r�td
�d��n��d
��r
�td
�d����dd����d
d���j
�r4����n�j�rF��d���jdk�r^���j���j�rz��d��sz�d7���fdd�}	|	�}
|�s�t|
�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.
        r5�chardetrNzkTo enable chardet encoding guessing, please install the chardet library from http://chardet.feedparser.org/�replaceir4zutf-8uz
�
�
c3s(x"����D]\}}}||fVqWdS)N)�get_tokens_unprocessed)�_�t�v)r:rAr r"�streamer�sz"Lexer.get_tokens.<locals>.streamer)r?rr4rrB�ImportError�
_encoding_map�
startswith�len�decode�detectr8rCr1�stripr0r3�
expandtabsr2�endswithrr6)r:rAZ
unfilteredrGrB�decoded�bomr4�encrJ�streamr )r:rAr"�
get_tokens�sL	






zLexer.get_tokenscCst�dS)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)�NotImplementedError)r:rAr r r"rF�szLexer.get_tokens_unprocessed)F)r,r-r.r/r)�aliases�	filenamesZalias_filenamesZ	mimetypes�priorityr<r>r9r&rXrFr r r r"r3s
;c@s$eZdZdZefdd�Zdd�ZdS)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|�dS)N)�
root_lexer�language_lexer�needlerr<)r:Z_root_lexerZ_language_lexerZ_needler7r r r"r<�szDelegatingLexer.__init__cCs�d}g}g}xX|j�|�D]H\}}}||jkrR|rH|�t|�|f�g}||7}q|�|||f�qW|r||�t|�|f�t||j�|��S)N�)r^rFr_r@rN�
do_insertionsr])r:rAZbuffered�
insertionsZ
lng_buffer�irHrIr r r"rF�s

z&DelegatingLexer.get_tokens_unprocessedN)r,r-r.r/rr<rFr r r r"r�sc@seZdZdZdS)rzI
    Indicates that a state should include rules from another state.
    N)r,r-r.r/r r r r"r�sc@seZdZdZdd�ZdS)�_inheritzC
    Indicates the a state should inherit from its superclass.
    cCsdS)Nrr )r:r r r"r>sz_inherit.__repr__N)r,r-r.r/r>r r r r"rd�srdc@s eZdZdZdd�Zdd�ZdS)�combinedz:
    Indicates a state combined from multiple states.
    cGst�||�S)N)�tupler()�cls�argsr r r"r(szcombined.__new__cGsdS)Nr )r:rhr r r"r<szcombined.__init__N)r,r-r.r/r(r<r r r r"re	srec@sFeZdZdZdd�Zddd�Zddd�Zdd	d
�Zdd�Zd
d�Z	dS)�_PseudoMatchz:
    A pseudo match object constructed from a string.
    cCs||_||_dS)N)�_text�_start)r:�startrAr r r"r<sz_PseudoMatch.__init__NcCs|jS)N)rk)r:�argr r r"rlsz_PseudoMatch.startcCs|jt|j�S)N)rkrNrj)r:rmr r r"�end"sz_PseudoMatch.endcCs|rtd��|jS)Nz
No such group)�
IndexErrorrj)r:rmr r r"�group%sz_PseudoMatch.groupcCs|jfS)N)rj)r:r r r"�groups*sz_PseudoMatch.groupscCsiS)Nr )r:r r r"�	groupdict-sz_PseudoMatch.groupdict)N)N)N)
r,r-r.r/r<rlrnrprqrrr r r r"ris


ricsd�fdd�	}|S)zL
    Callback that yields multiple actions for each group in the match.
    Nc3s�x�t��D]�\}}|dkrq
q
t|�tkrT|�|d�}|r�|�|d�||fVq
|�|d�}|dk	r
|r~|�|d�|_x.||t|�|d�|�|�D]}|r�|Vq�Wq
W|r�|��|_dS)N�)�	enumerater'r	rprl�posrirn)�lexer�match�ctxrc�action�data�item)rhr r"�callback5s"zbygroups.<locals>.callback)Nr )rhr|r )rhr"r1sc@seZdZdZdS)�_ThiszX
    Special singleton used for indicating the caller class.
    Used by ``using``.
    N)r,r-r.r/r r r r"r}Ksr}csji�d�kr:��d�}t|ttf�r.|�d<nd|f�d<�tkrTd��fdd�	}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`.
    �state�stack�rootNc3sn�r��|j�|jf��}n|}|��}x0|j|��f��D]\}}}||||fVq>W|rj|��|_dS)N)�updater7r=rlrFrprnru)rvrwrx�lx�srcrHrI)�	gt_kwargs�kwargsr r"r|iszusing.<locals>.callbackc3sb��|j��f��}|��}x0|j|��f��D]\}}}||||fVq2W|r^|��|_dS)N)r�r7rlrFrprnru)rvrwrxr�r�rcrHrI)�_otherr�r�r r"r|xs
)N)N)�popr?�listrfr)r�r�r�r|r )r�r�r�r"rSs



c@seZdZdZdd�ZdS)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
||_dS)N)r~)r:r~r r r"r<�szdefault.__init__N)r,r-r.r/r<r r r r"r�sc@s"eZdZdZddd�Zdd�ZdS)	rz�
    Indicates a list of literal words that is transformed into an optimized
    regex that matches any of the words.

    .. versionadded:: 2.0
    r`cCs||_||_||_dS)N)r�prefix�suffix)r:rr�r�r r r"r<�szwords.__init__cCst|j|j|jd�S)N)r�r�)rrr�r�)r:r r r"r8�sz	words.getN)r`r`)r,r-r.r/r<r8r r r r"r�s
c@sJeZdZdZdd�Zdd�Zdd�Zdd	�Zddd�Zd
d�Z	dd�Z
d
S)�RegexLexerMetazw
    Metaclass for RegexLexer, creates the self._tokens attribute from
    self.tokens on the first instantiation.
    cCs t|t�r|��}t�||�jS)zBPreprocess the regular expression component of a token definition.)r?rr8�re�compilerw)rg�regex�rflagsr~r r r"�_process_regex�s
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'r	�callable�AssertionError)rg�tokenr r r"�_process_token�szRegexLexerMeta._process_tokencCst|t�rd|dkrdS||kr$|fS|dkr0|S|dd�dkrRt|dd��Sdsbtd|��n�t|t�r�d	|j}|jd
7_g}x4|D],}||ks�td|��|�|�|||��q�W|||<|fSt|t��rx(|D] }||ks�|dks�td
|��q�W|Sd�std|��dS)z=Preprocess the state transition action of a token definition.z#pop���z#pushN�z#pop:Fzunknown new state %rz_tmp_%drszcircular state ref %r)z#popz#pushzunknown new state zunknown new state def %r)	r?�str�intr�re�_tmpname�extend�_process_staterf)rg�	new_state�unprocessed�	processedZ	tmp_state�itokensZistater r r"�_process_new_state�s6






z!RegexLexerMeta._process_new_statecCs�t|�tkstd|��|ddks0td|��||kr@||Sg}||<|j}�x:||D�],}t|t�r�||ks�td|��|�|�||t|���q^t|t�r�q^t|t	�r�|�
|j||�}|�t
�d�jd|f�q^t|�tks�td|��y|�|d||�}Wn<tk
�rF}	ztd	|d|||	f��Wdd}	~	XYnX|�|d
�}
t|�dk�rjd}n|�
|d||�}|�||
|f�q^W|S)z%Preprocess a single state definition.zwrong state name %rr�#zinvalid state name %rzcircular state reference %rr`Nzwrong rule def %rz+uncompilable regex %r in state %r of %r: %srs�)r'r�r��flagsr?rr�r�rdrr�r~r@r�r�rwrfr��	Exception�
ValueErrorr�rN)rgr�r�r~�tokensr�Ztdefr��rex�errr�r r r"r��s>


&
zRegexLexerMeta._process_stateNcCs@i}|j|<|p|j|}xt|�D]}|�|||�q&W|S)z-Preprocess a dictionary of token definitions.)�_all_tokensr�r�r�)rgr)�	tokendefsr�r~r r r"�process_tokendefs
zRegexLexerMeta.process_tokendefc

Cs�i}i}x�|jD]�}|j�di�}x�t|�D]�\}}|�|�}|dkr~|||<y|�t�}Wntk
rrw,YnX|||<q,|�|d�}|dkr�q,||||d�<y|�t�}	Wntk
r�Yq,X||	||<q,WqW|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.
        r�Nrs)�__mro__�__dict__r8r�indexrr�r�)
rgr��inheritable�c�toksr~�itemsZcuritemsZinherit_ndxZnew_inh_ndxr r r"�
get_tokendefs
s0
zRegexLexerMeta.get_tokendefscOsLd|jkr:i|_d|_t|d�r(|jr(n|�d|���|_tj	|f|�|�S)z:Instantiate cls after preprocessing its token definitions.�_tokensr�token_variantsr`)
r�r�r��hasattrr�r�r�r�r'�__call__)rgrh�kwdsr r r"r�;s
zRegexLexerMeta.__call__)N)r,r-r.r/r�r�r�r�r�r�r�r r r r"r��s#,
1r�c@s$eZdZdZejZiZddd�ZdS)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.
    �r�c
cs�d}|j}t|�}||d}�x��x�|D�]4\}}}	|||�}
|
r*|dk	r�t|�tkrj|||
��fVnx|||
�D]
}|VqvW|
��}|	dk	�r^t|	t�r�x�|	D]D}|dkr�t|�dkr�|�	�q�|dkr�|�
|d�q�|�
|�q�Wnbt|	t��r&t|	�t|�k�r|dd�=n
||	d�=n,|	dk�r@|�
|d�nd�sRt
d|	��||d}Pq*WyN||d	k�r�d
g}|d
}|td	fV|d7}w"|t||fV|d7}Wq"tk
�r�PYq"Xq"WdS)z}
        Split ``text`` into (tokentype, text) pairs.

        ``stack`` is the inital stack (default: ``['root']``)
        rr�Nz#poprsz#pushFzwrong state def: %rrDr�)r�r�r'r	rprnr?rfrNr�r@r��absr�rrro)
r:rArrur�Z
statestack�statetokens�rexmatchryr��mr{r~r r r"rFhsV






z!RegexLexer.get_tokens_unprocessedN)r�)	r,r-r.r/r��	MULTILINEr�r�rFr r r r"rIsc@s"eZdZdZddd�Zdd�ZdS)rz9
    A helper object that holds lexer position data.
    NcCs*||_||_|pt|�|_|p"dg|_dS)Nr�)rArurNrnr)r:rArurrnr r r"r<�szLexerContext.__init__cCsd|j|j|jfS)NzLexerContext(%r, %r, %r))rArur)r:r r r"r>�szLexerContext.__repr__)NN)r,r-r.r/r<r>r r r r"r�s
c@seZdZdZddd�ZdS)rzE
    A RegexLexer that uses a context object to store its state.
    NccsN|j}|st|d�}|d}n|}||jd}|j}�x�x|D�]p\}}}|||j|j�}	|	rB|dk	r�t|�tkr�|j||	��fV|	��|_n.x|||	|�D]
}
|
Vq�W|s�||jd}|dk	�r�t	|t
��r8x�|D]T}|dk�rt|j�dk�r2|j��q�|dk�r&|j�
|jd�q�|j�
|�q�Wnlt	|t��rtt|�t|j�k�rf|jdd�=n|j|d�=n0|dk�r�|j�
|jd�nd�s�td	|��||jd}PqBWyt|j|jk�r�P||jd
k�rdg|_|d}|jtd
fV|jd7_w:|jt||jfV|jd7_Wq:tk
�rDPYq:Xq:WdS)z
        Split ``text`` into (tokentype, text) pairs.
        If ``context`` is given, use this lexer context instead.
        rr�r�Nz#poprsz#pushFzwrong state def: %rrD)r�rrrArurnr'r	rpr?rfrNr�r@r�r�r~r�rrro)r:rA�contextr�rxr�r�ryr�r�r{r~r r r"rF�sd







z)ExtendedRegexLexer.get_tokens_unprocessed)NN)r,r-r.r/rFr r r r"r�sc	cs�t|�}yt|�\}}Wn(tk
r@x|D]
}|Vq.WdSXd}d}x�|D]�\}}}	|dkrf|}d}
x�|�r|t|	�|k�r|	|
||�}|||fV|t|�7}x*|D]"\}}
}||
|fV|t|�7}q�W||}
yt|�\}}Wqltk
�rd}PYqlXqlW|||	|
d�fV|t|	�|
7}qPWxr|�r�|�pJd}x,|D]$\}}}	|||	fV|t|	�7}�qRWyt|�\}}Wntk
�r�d}PYnX�q<WdS)ag
    Helper for lexers which must combine the results of several
    sublexers.

    ``insertions`` is a list of ``(index, itokens)`` pairs.
    Each ``itokens`` iterable should be inserted at position
    ``index`` into the token stream given by the ``tokens``
    argument.

    The result is a combined token stream.

    TODO: clean up the code here.
    NTrF)�iter�next�
StopIterationrN)rbr�r�r�r{ZrealposZinsleftrcrHrIZoldiZtmpvalZit_indexZit_tokenZit_value�pr r r"rasL


rac@seZdZdZdd�ZdS)�ProfilingRegexLexerMetaz>Metaclass for ProfilingRegexLexer, collects regex timing info.csLt|t�r t|j|j|jd��n|�t��|��tjf����fdd�	}|S)N)r�r�cs`�jd���fddg�}t��}��|||�}t��}|dd7<|d||7<|S)Nr�rgrs)�
_prof_data�
setdefault�timerw)rAru�endpos�info�t0�res�t1)rg�compiledr�r~r r"�
match_funcJsz:ProfilingRegexLexerMeta._process_regex.<locals>.match_func)	r?rrr�r�r�r��sys�maxsize)rgr�r�r~r�r )rgr�r�r~r"r�Bs

z&ProfilingRegexLexerMeta._process_regexN)r,r-r.r/r�r r r r"r�?sr�c@s"eZdZdZgZdZddd�ZdS)�ProfilingRegexLexerzFDrop-in replacement for RegexLexer that does profiling of its regexes.��r�c#s��jj�i�xt��||�D]
}|VqW�jj��}tdd�|��D��fdd�dd�}tdd�|D��}t	�t	d�jj
t|�|f�t	d	�t	d
d�t	d�x|D]}t	d
|�q�Wt	d	�dS)NcssN|]F\\}}\}}|t|��d��dd�dd�|d|d||fVqdS)zu'z\\�\N�Ai�)�reprrQrC)�.0r��r�nrHr r r"�	<genexpr>bsz=ProfilingRegexLexer.get_tokens_unprocessed.<locals>.<genexpr>cs
|�jS)N)�_prof_sort_index)r!)r:r r"r#er$z<ProfilingRegexLexer.get_tokens_unprocessed.<locals>.<lambda>T)�key�reversecss|]}|dVqdS)�Nr )r�r!r r r"r�gsz2Profiling result for %s lexing %d chars in %.3f mszn==============================================================================================================z$%-20s %-64s ncalls  tottime  percall)r~r�zn--------------------------------------------------------------------------------------------------------------z%-20s %-65s %5d %8.4f %8.4f)r=r�r@rrFr��sortedr��sum�printr,rN)r:rAr�tokZrawdatarzZ	sum_totalr+r )r:r"rF\s$



z*ProfilingRegexLexer.get_tokens_unprocessedN)r�)r,r-r.r/r�r�rFr r r r"r�Usr�)9r/�
__future__rr�r�r�Zpygments.filterrrZpygments.filtersrZpygments.tokenrrrr	Z
pygments.utilr
rrr
rrrrrZpygments.regexoptr�__all__rL�staticmethodZ_default_analyser'r%�objectrrr�rrdrrfrerirr}rrrrr�rrrrar�r�r r r r"�<module>
sX,'
2)]I?