3
.ßL]Ò{  ã               @   s  d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
 ddlmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZ ddlmZ d	d
ddddddddddgZd=d>d?d@dAgZedd „ ƒZG d!d"„ d"e ƒZ!ee!ƒG d#d	„ d	e"ƒƒZ#G d$d„ de#ƒZ$G d%d„ de%ƒZ&G d&d'„ d'e"ƒZ'e'ƒ Z(G d(d)„ d)e)ƒZ*G d*d+„ d+e"ƒZ+d,d„ Z,G d-d.„ d.e"ƒZ-e-ƒ Z.d/d„ Z/G d0d„ dƒZ0G d1d„ deƒZ1G d2d3„ d3e!ƒZ2ee2ƒG d4d
„ d
e#ƒƒZ3G d5d„ de"ƒZ4G d6d„ de3ƒZ5d7d8„ Z6G d9d:„ d:e2ƒZ7ee7ƒG d;d<„ d<e3ƒƒZ8dS )Bz´
    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ó   ï»¿úutf-8ó   ÿþ  úutf-32ó     þÿúutf-32beó   ÿþúutf-16ó   þÿúutf-16bec             C   s   dS )Ng        © )Úxr*   r*   ú4/tmp/pip-install-5sebvq2j/pygments/pygments/lexer.pyÚ<lambda>$   s    r-   c               @   s   e Zd ZdZdd„ ZdS )Ú	LexerMetaz‚
    This metaclass automagically converts ``analyse_text`` methods into
    static methods which always return float values.
    c             C   s(   d|krt |d ƒ|d< tj| |||ƒS )NÚanalyse_text)r   ÚtypeÚ__new__)ZmcsÚnameÚbasesÚdr*   r*   r,   r1   -   s    zLexerMeta.__new__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r1   r*   r*   r*   r,   r.   '   s   r.   c               @   sZ   e Zd ZdZdZg Zg Zg Zg ZdZ	dd„ Z
dd„ Zdd	„ Zd
d„ Zddd„Zdd„ ZdS )r   aÈ  
    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.
    Nr   c             K   sˆ   || _ t|ddƒ| _t|ddƒ| _t|ddƒ| _t|ddƒ| _|jdd	ƒ| _|jd
ƒpZ| j| _g | _	xt
|df ƒD ]}| j|ƒ qrW d S )NÚstripnlTÚstripallFÚensurenlÚtabsizer   ÚencodingÚguessZ
inencodingÚfilters)Úoptionsr
   r9   r:   r;   r   r<   Úgetr=   r?   r   Ú
add_filter)Úselfr@   Úfilter_r*   r*   r,   Ú__init__b   s    zLexer.__init__c             C   s(   | j rd| jj| j f S d| jj S d S )Nz<pygments.lexers.%s with %r>z<pygments.lexers.%s>)r@   Ú	__class__r5   )rC   r*   r*   r,   Ú__repr__n   s    
zLexer.__repr__c             K   s&   t |tƒst|f|Ž}| jj|ƒ dS )z8
        Add a new stream filter to this lexer.
        N)Ú
isinstancer   r   r?   Úappend)rC   rD   r@   r*   r*   r,   rB   u   s    
zLexer.add_filterc             C   s   dS )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    zLexer.analyse_textFc                s¨  t ˆtƒsîˆ jdkr"tˆƒ\‰}nÊˆ jdkrÆyddl}W n tk
rT   tdƒ‚Y nX d}x4tD ],\}}ˆj|ƒr`ˆt|ƒd… j	|dƒ}P q`W |dkrÀ|j
ˆdd… ƒ}ˆj	|jdƒpºd	dƒ}|‰n&ˆj	ˆ jƒ‰ˆjd
ƒrìˆtd
ƒd… ‰nˆjd
ƒ�r
ˆtd
ƒd… ‰ˆjddƒ‰ˆjddƒ‰ˆ j�r4ˆjƒ ‰nˆ j�rFˆjdƒ‰ˆ jdk�r^ˆjˆ jƒ‰ˆ j�r|ˆjdƒ �r|ˆd7 ‰‡ ‡fdd„}	|	ƒ }
|�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.
        r>   Úchardetr   NzkTo enable chardet encoding guessing, please install the chardet library from http://chardet.feedparser.org/Úreplacei   r=   zutf-8u   ï»¿z
Ú
úc              3   s(   x"ˆ j ˆƒD ]\} }}||fV  qW d S )N)Úget_tokens_unprocessed)Ú_ÚtÚv)rC   rJ   r*   r,   Ústreamer¾   s    z"Lexer.get_tokens.<locals>.streamer)rH   r   r=   r   rK   ÚImportErrorÚ_encoding_mapÚ
startswithÚlenÚdecodeÚdetectrA   rL   r:   Ústripr9   r<   Ú
expandtabsr;   Úendswithr   r?   )rC   rJ   Z
unfilteredrP   rK   ÚdecodedÚbomr=   ÚencrS   Ústreamr*   )rC   rJ   r,   Ú
get_tokens‹   sL    	






zLexer.get_tokensc             C   s   t ‚dS )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)rC   rJ   r*   r*   r,   rO   Æ   s    zLexer.get_tokens_unprocessed)F)r5   r6   r7   r8   r2   ÚaliasesÚ	filenamesZalias_filenamesÚ	mimetypesÚpriorityrE   rG   rB   r/   ra   rO   r*   r*   r*   r,   r   3   s   
;c               @   s$   e Zd ZdZefdd„Zdd„ ZdS )r   a   
    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.
    c             K   s0   |f |Ž| _ |f |Ž| _|| _tj| f|Ž d S )N)Ú
root_lexerÚlanguage_lexerÚneedler   rE   )rC   Z_root_lexerZ_language_lexerZ_needler@   r*   r*   r,   rE   Û   s    zDelegatingLexer.__init__c             C   sŽ   d}g }g }xX| j j|ƒD ]H\}}}|| jkrR|rH|jt|ƒ|fƒ g }||7 }q|j|||fƒ qW |r||jt|ƒ|fƒ t|| jj|ƒƒS )NÚ )rh   rO   ri   rI   rW   Údo_insertionsrg   )rC   rJ   ZbufferedÚ
insertionsZ
lng_bufferÚirQ   rR   r*   r*   r,   rO   á   s    

z&DelegatingLexer.get_tokens_unprocessedN)r5   r6   r7   r8   r   rE   rO   r*   r*   r*   r,   r   Ñ   s   c               @   s   e Zd ZdZdS )r   zI
    Indicates that a state should include rules from another state.
    N)r5   r6   r7   r8   r*   r*   r*   r,   r   ø   s   c               @   s   e Zd ZdZdd„ ZdS )Ú_inheritzC
    Indicates the a state should inherit from its superclass.
    c             C   s   dS )Nr   r*   )rC   r*   r*   r,   rG     s    z_inherit.__repr__N)r5   r6   r7   r8   rG   r*   r*   r*   r,   rn   ÿ   s   rn   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )Úcombinedz:
    Indicates a state combined from multiple states.
    c             G   s   t j| |ƒS )N)Útupler1   )ÚclsÚargsr*   r*   r,   r1     s    zcombined.__new__c             G   s   d S )Nr*   )rC   rr   r*   r*   r,   rE     s    zcombined.__init__N)r5   r6   r7   r8   r1   rE   r*   r*   r*   r,   ro   	  s   ro   c               @   sF   e Zd ZdZdd„ Zddd„Zddd„Zdd	d
„Zdd„ Zdd„ Z	dS )Ú_PseudoMatchz:
    A pseudo match object constructed from a string.
    c             C   s   || _ || _d S )N)Ú_textÚ_start)rC   ÚstartrJ   r*   r*   r,   rE     s    z_PseudoMatch.__init__Nc             C   s   | j S )N)ru   )rC   Úargr*   r*   r,   rv     s    z_PseudoMatch.startc             C   s   | j t| jƒ S )N)ru   rW   rt   )rC   rw   r*   r*   r,   Úend"  s    z_PseudoMatch.endc             C   s   |rt dƒ‚| jS )NzNo such group)Ú
IndexErrorrt   )rC   rw   r*   r*   r,   Úgroup%  s    z_PseudoMatch.groupc             C   s   | j fS )N)rt   )rC   r*   r*   r,   Úgroups*  s    z_PseudoMatch.groupsc             C   s   i S )Nr*   )rC   r*   r*   r,   Ú	groupdict-  s    z_PseudoMatch.groupdict)N)N)N)
r5   r6   r7   r8   rE   rv   rx   rz   r{   r|   r*   r*   r*   r,   rs     s   


rs   c                 s   d‡ fdd„	}|S )zL
    Callback that yields multiple actions for each group in the match.
    Nc             3   sÄ   x°t ˆ ƒD ]¤\}}|d krq
q
t|ƒtkrT|j|d ƒ}|r®|j|d ƒ||fV  q
|j|d ƒ}|d k	r
|r~|j|d ƒ|_x.|| t|j|d ƒ|ƒ|ƒD ]}|rœ|V  qœW q
W |rÀ|jƒ |_d S )Né   )Ú	enumerater0   r	   rz   rv   Úposrs   rx   )ÚlexerÚmatchÚctxrm   ÚactionÚdataÚitem)rr   r*   r,   Úcallback5  s"    zbygroups.<locals>.callback)Nr*   )rr   r†   r*   )rr   r,   r   1  s    c               @   s   e Zd ZdZdS )Ú_ThiszX
    Special singleton used for indicating the caller class.
    Used by ``using``.
    N)r5   r6   r7   r8   r*   r*   r*   r,   r‡   K  s   r‡   c                sj   i ‰dˆkr:ˆj dƒ}t|ttfƒr.|ˆd< nd|fˆd< ˆ tkrTd‡‡fdd„	}nd	‡ ‡‡fdd„	}|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ÚrootNc             3   sn   ˆrˆj | jƒ | jf ˆŽ}n| }|jƒ }x0|j|jƒ fˆ ŽD ]\}}}|| ||fV  q>W |rj|jƒ |_d S )N)Úupdater@   rF   rv   rO   rz   rx   r   )r€   r�   r‚   ÚlxÚsrm   rQ   rR   )Ú	gt_kwargsÚkwargsr*   r,   r†   i  s    zusing.<locals>.callbackc             3   sb   ˆj | jƒ ˆ f ˆŽ}|jƒ }x0|j|jƒ fˆŽD ]\}}}|| ||fV  q2W |r^|jƒ |_d S )N)r‹   r@   rv   rO   rz   rx   r   )r€   r�   r‚   rŒ   r�   rm   rQ   rR   )Ú_otherrŽ   r�   r*   r,   r†   x  s    
)N)N)ÚpoprH   Úlistrp   r   )r�   r�   r�   r†   r*   )r�   rŽ   r�   r,   r   S  s    


c               @   s   e Zd ZdZdd„ ZdS )r   zÑ
    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
    c             C   s
   || _ d S )N)rˆ   )rC   rˆ   r*   r*   r,   rE   �  s    zdefault.__init__N)r5   r6   r7   r8   rE   r*   r*   r*   r,   r   …  s   c               @   s"   e Zd ZdZddd„Zdd„ ZdS )	r   z•
    Indicates a list of literal words that is transformed into an optimized
    regex that matches any of the words.

    .. versionadded:: 2.0
    rj   c             C   s   || _ || _|| _d S )N)r   ÚprefixÚsuffix)rC   r   r“   r”   r*   r*   r,   rE   ˜  s    zwords.__init__c             C   s   t | j| j| jd�S )N)r“   r”   )r   r   r“   r”   )rC   r*   r*   r,   rA   �  s    z	words.getN)rj   rj   )r5   r6   r7   r8   rE   rA   r*   r*   r*   r,   r   ‘  s   
c               @   sJ   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zddd„Zdd„ Z	dd„ Z
d
S )ÚRegexLexerMetazw
    Metaclass for RegexLexer, creates the self._tokens attribute from
    self.tokens on the first instantiation.
    c             C   s    t |tƒr|jƒ }tj||ƒjS )zBPreprocess the regular expression component of a token definition.)rH   r   rA   ÚreÚcompiler�   )rq   ÚregexÚrflagsrˆ   r*   r*   r,   Ú_process_regex§  s    
zRegexLexerMeta._process_regexc             C   s&   t |ƒtks"t|ƒs"td|f ƒ‚|S )z5Preprocess the token component of a token definition.z2token type must be simple type or callable, not %r)r0   r	   ÚcallableÚAssertionError)rq   Útokenr*   r*   r,   Ú_process_token­  s    zRegexLexerMeta._process_tokenc             C   s  t |tƒrd|dkrdS ||kr$|fS |dkr0|S |dd… dkrRt|dd… ƒ S dsbtd| ƒ‚n¶t |tƒrÎd	| j }|  jd7  _g }x4|D ],}||ks¨td
| ƒ‚|j| j|||ƒƒ q�W |||< |fS t |tƒ�rx(|D ] }||ksà|dksàtd| ƒ‚qàW |S d�std| ƒ‚dS )z=Preprocess the state transition action of a token definition.ú#popr}   ú#pushNé   z#pop:Fzunknown new state %rz_tmp_%dzcircular state ref %rzunknown new state zunknown new state def %réÿÿÿÿ)rŸ   r    )	rH   ÚstrÚintrœ   ro   Ú_tmpnameÚextendÚ_process_staterp   )rq   Ú	new_stateÚunprocessedÚ	processedZ	tmp_stateÚitokensZistater*   r*   r,   Ú_process_new_state³  s6    






z!RegexLexerMeta._process_new_statec             C   s”  t |ƒtkstd| ƒ‚|d dks0td| ƒ‚||kr@|| S g  }||< | j}�x:|| D �],}t|tƒrœ||ks‚td| ƒ‚|j| j||t|ƒƒƒ q^t|tƒr¨q^t|t	ƒrÜ| j
|j||ƒ}|jtjdƒjd|fƒ q^t |ƒtksôtd| ƒ‚y| j|d ||ƒ}W n< tk
�rF }	 ztd	|d || |	f ƒ‚W Y dd}	~	X nX | j|d
 ƒ}
t|ƒdk�rjd}n| j
|d ||ƒ}|j||
|fƒ q^W |S )z%Preprocess a single state definition.zwrong state name %rr   ú#zinvalid state name %rzcircular state reference %rrj   Nzwrong rule def %rz+uncompilable regex %r in state %r of %r: %sr}   é   )r0   r£   rœ   ÚflagsrH   r   r¦   r§   rn   r   r¬   rˆ   rI   r–   r—   r�   rp   rš   Ú	ExceptionÚ
ValueErrorrž   rW   )rq   r©   rª   rˆ   Útokensr™   Ztdefr¨   ÚrexÚerrr�   r*   r*   r,   r§   Ö  s>    


&
zRegexLexerMeta._process_stateNc             C   s@   i  }| j |< |p| j| }xt|ƒD ]}| j|||ƒ q&W |S )z-Preprocess a dictionary of token definitions.)Ú_all_tokensr²   r’   r§   )rq   r2   Ú	tokendefsrª   rˆ   r*   r*   r,   Úprocess_tokendef  s
    zRegexLexerMeta.process_tokendefc       
      C   sà   i }i }xÒ| j D ]È}|jjdi ƒ}x´t|ƒD ]¨\}}|j|ƒ}|dkr~|||< y|jtƒ}W n tk
rr   w,Y nX |||< q,|j|dƒ}|dkr”q,||||d …< y|jtƒ}	W n tk
rÆ   Y q,X ||	 ||< q,W qW |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²   Nr}   )Ú__mro__Ú__dict__rA   r   Úindexr   r±   r‘   )
rq   r²   ÚinheritableÚcÚtoksrˆ   ÚitemsZcuritemsZinherit_ndxZnew_inh_ndxr*   r*   r,   Úget_tokendefs
  s0    
zRegexLexerMeta.get_tokendefsc             O   sL   d| j kr:i | _d| _t| dƒr(| jr(n| jd| jƒ ƒ| _tj	| f|ž|ŽS )z:Instantiate cls after preprocessing its token definitions.Ú_tokensr   Útoken_variantsrj   )
r¹   rµ   r¥   ÚhasattrrÁ   r·   r¿   rÀ   r0   Ú__call__)rq   rr   Úkwdsr*   r*   r,   rÃ   ;  s    
zRegexLexerMeta.__call__)N)r5   r6   r7   r8   rš   rž   r¬   r§   r·   r¿   rÃ   r*   r*   r*   r,   r•   ¡  s   #,
1r•   c               @   s$   e Zd ZdZejZi Zddd„ZdS )r   z±
    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             c   sÔ  d}| j }t|ƒ}||d
  }�x®�x¦|D �]4\}}}	|||ƒ}
|
r*|dk	r„t|ƒtkrj|||
jƒ fV  nx|| |
ƒD ]
}|V  qvW |
jƒ }|	dk	�r^t|	tƒrðx°|	D ]D}|dkrÈt|ƒdkrê|j	ƒ  q¦|dkrà|j
|d ƒ q¦|j
|ƒ q¦W nbt|	tƒ�r&t|	ƒt|ƒk�r|dd…= n
||	d…= n,|	dk�r@|j
|d ƒ nd�sRtd|	 ƒ‚||d  }P q*W yN|| dk�r˜d	g}|d	 }|tdfV  |d7 }w"|t|| fV  |d7 }W q" tk
�rÊ   P Y q"X q"W dS )z}
        Split ``text`` into (tokentype, text) pairs.

        ``stack`` is the inital stack (default: ``['root']``)
        r   r}   Nz#popz#pushFzwrong state def: %rrM   rŠ   r¢   r¢   r¢   r¢   )rÀ   r’   r0   r	   rz   rx   rH   rp   rW   r‘   rI   r¤   Úabsrœ   r   r   ry   )rC   rJ   r‰   r   r¶   Z
statestackÚstatetokensÚrexmatchrƒ   r¨   Úmr…   rˆ   r*   r*   r,   rO   h  sV    






z!RegexLexer.get_tokens_unprocessedN©rŠ   )rÉ   )	r5   r6   r7   r8   r–   Ú	MULTILINEr¯   r²   rO   r*   r*   r*   r,   r   I  s   c               @   s"   e Zd ZdZddd„Zdd„ ZdS )r   z9
    A helper object that holds lexer position data.
    Nc             C   s*   || _ || _|pt|ƒ| _|p"dg| _d S )NrŠ   )rJ   r   rW   rx   r‰   )rC   rJ   r   r‰   rx   r*   r*   r,   rE   ¬  s    zLexerContext.__init__c             C   s   d| j | j| jf S )NzLexerContext(%r, %r, %r))rJ   r   r‰   )rC   r*   r*   r,   rG   ²  s    zLexerContext.__repr__)NN)r5   r6   r7   r8   rE   rG   r*   r*   r*   r,   r   §  s   
c               @   s   e Zd ZdZddd„ZdS )r   zE
    A RegexLexer that uses a context object to store its state.
    Nc             c   sN  | j }|st|dƒ}|d }n|}||jd
  }|j}�x�x|D �]p\}}}|||j|jƒ}	|	rB|dk	rÂt|ƒtkr”|j||	jƒ fV  |	jƒ |_n.x|| |	|ƒD ]
}
|
V  q¢W |sÂ||jd  }|dk	�r²t	|t
ƒ�r8xÊ|D ]T}|dk�rt|jƒdk�r2|jjƒ  qÞ|dk�r&|jj|jd ƒ qÞ|jj|ƒ qÞW nlt	|tƒ�rtt|ƒt|jƒk�rf|jdd…= n|j|d…= n0|dk�r’|jj|jd ƒ nd�s¤td| ƒ‚||jd  }P qBW yt|j|jk�rÊP ||j d	k�rdg|_|d }|jtd	fV  | jd7  _w:|jt||j fV  | jd7  _W q: tk
�rD   P Y q:X q:W dS )z
        Split ``text`` into (tokentype, text) pairs.
        If ``context`` is given, use this lexer context instead.
        r   rŠ   r}   Nz#popz#pushFzwrong state def: %rrM   r¢   r¢   r¢   r¢   r¢   )rÀ   r   r‰   rJ   r   rx   r0   r	   rz   rH   rp   rW   r‘   rI   r¤   rÅ   rˆ   rœ   r   r   ry   )rC   rJ   Úcontextr¶   r‚   rÆ   rÇ   rƒ   r¨   rÈ   r…   rˆ   r*   r*   r,   rO   ¼  sd    







z)ExtendedRegexLexer.get_tokens_unprocessed)NN)r5   r6   r7   r8   rO   r*   r*   r*   r,   r   ·  s   c             c   s°  t | ƒ} yt| ƒ\}}W n( tk
r@   x|D ]
}|V  q.W dS X d}d}xì|D ]ä\}}}	|dkrf|}d}
x¤|o~|t|	ƒ |k�r|	|
|| … }|||fV  |t|ƒ7 }x*|D ]"\}}}|||fV  |t|ƒ7 }q°W || }
yt| ƒ\}}W ql tk
�r
   d}P Y qlX qlW |||	|
d… fV  |t|	ƒ|
 7 }qPW xr|�rª|�pHd}x,|D ]$\}}}	|||	fV  |t|	ƒ7 }�qPW yt| ƒ\}}W n tk
�r¤   d}P Y nX �q:W dS )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.
    NTr   F)ÚiterÚnextÚStopIterationrW   )rl   r²   rº   r«   r…   ÚrealposZinsleftrm   rQ   rR   ZoldiZtmpvalZit_indexZit_tokenZit_valueÚpr*   r*   r,   rk      sL    


rk   c               @   s   e Zd ZdZdd„ ZdS )ÚProfilingRegexLexerMetaz>Metaclass for ProfilingRegexLexer, collects regex timing info.c                sL   t |tƒr t|j|j|jd�‰n|‰tjˆ|ƒ‰tjf‡ ‡‡‡fdd„	}|S )N)r“   r”   c                s`   ˆ j d jˆˆfddgƒ}tjƒ }ˆj| ||ƒ}tjƒ }|d  d7  < |d  || 7  < |S )Nr}   r   g        r¢   )Ú
_prof_dataÚ
setdefaultÚtimer�   )rJ   r   ÚendposÚinfoÚt0ÚresÚt1)rq   Úcompiledr³   rˆ   r*   r,   Ú
match_funcJ  s    z:ProfilingRegexLexerMeta._process_regex.<locals>.match_func)	rH   r   r   r“   r”   r–   r—   ÚsysÚmaxsize)rq   r˜   r™   rˆ   rÛ   r*   )rq   rÚ   r³   rˆ   r,   rš   B  s    

z&ProfilingRegexLexerMeta._process_regexN)r5   r6   r7   r8   rš   r*   r*   r*   r,   rÑ   ?  s   rÑ   c               @   s"   e Zd ZdZg ZdZddd„ZdS )	ÚProfilingRegexLexerzFDrop-in replacement for RegexLexer that does profiling of its regexes.é   rŠ   c             #   sÜ   ˆ j jji ƒ xtjˆ ||ƒD ]
}|V  qW ˆ j jjƒ }tdd„ |jƒ D ƒ‡ fdd„dd�}tdd„ |D ƒƒ}t	ƒ  t	dˆ j j
t|ƒ|f ƒ t	d	d
 ƒ t	dd ƒ t	dd
 ƒ x|D ]}t	d| ƒ q¸W t	d	d
 ƒ d S )Nc             s   sN   | ]F\\}}\}}|t |ƒjd ƒjddƒdd… |d| d| | fV  qdS )zu'z\\ú\NéA   iè  )ÚreprrZ   rL   )Ú.0r�   ÚrÚnrQ   r*   r*   r,   ú	<genexpr>b  s   z=ProfilingRegexLexer.get_tokens_unprocessed.<locals>.<genexpr>c                s
   | ˆ j  S )N)Ú_prof_sort_index)r+   )rC   r*   r,   r-   e  s    z<ProfilingRegexLexer.get_tokens_unprocessed.<locals>.<lambda>T)ÚkeyÚreversec             s   s   | ]}|d  V  qdS )é   Nr*   )rã   r+   r*   r*   r,   ræ   g  s    z2Profiling result for %s lexing %d chars in %.3f msú=én   z$%-20s %-64s ncalls  tottime  percallrˆ   r˜   ú-z%-20s %-65s %5d %8.4f %8.4f)rˆ   r˜   )rF   rÒ   rI   r   rO   r‘   Úsortedr¾   ÚsumÚprintr5   rW   )rC   rJ   r‰   ÚtokÚrawdatar„   Z	sum_totalr4   r*   )rC   r,   rO   \  s$    



z*ProfilingRegexLexer.get_tokens_unprocessedN©rŠ   )ró   )r5   r6   r7   r8   rÒ   rç   rO   r*   r*   r*   r,   rÞ   U  s   rÞ   )r    r!   )r"   r#   )r$   r%   )r&   r'   )r(   r)   )9r8   Ú
__future__r   r–   rÜ   rÔ   Zpygments.filterr   r   Zpygments.filtersr   Zpygments.tokenr   r   r   r	   Zpygments.utilr
   r   r   r   r   r   r   r   r   Zpygments.regexoptr   Ú__all__rU   ÚstaticmethodZ_default_analyser0   r.   Úobjectr   r   r£   r   rn   r   rp   ro   rs   r   r‡   r   r   r   r   r•   r   r   r   rk   rÑ   rÞ   r*   r*   r*   r,   Ú<module>
   sX   , '2 )]I?