o
    xiNy                     @   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 g d	Zg d
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 d!d" d"Z0G d#d$ d$eZ1G d%d& d&e!Z2ee2G d'd( d(e#Z3G d)d* d*e"Z4G d+d, d,e3Z5d-d. Z6G d/d0 d0e2Z7ee7G d1d2 d2e3Z8dS )3z
    pygments.lexer
    ~~~~~~~~~~~~~~

    Base lexer classes.

    :copyright: Copyright 2006-2017 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))s   ﻿utf-8)s     zutf-32)s     zutf-32be)s   zutf-16)s   zutf-16bec                 C      dS )N         xr#   r#   O/home/ubuntu/.local/lib/python3.10/site-packages/wandb/vendor/pygments/lexer.py<lambda>$       r'   c                   @      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|v rt |d |d< t| |||S )Nanalyse_text)r   type__new__)mcsnamebasesdr#   r#   r&   r-   -   s   zLexerMeta.__new__N)__name__
__module____qualname____doc__r-   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| _|dd	| _|d
p-| j| _g | _	t
|ddD ]}| | q8d S )NstripnlTstripallFensurenltabsizer   encodingguess
inencodingfiltersr#   )optionsr
   r6   r7   r8   r   r9   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 )Nz<pygments.lexers.%s with %r>z<pygments.lexers.%s>)r>   	__class__r2   rA   r#   r#   r&   __repr__n   s
   zLexer.__repr__c                 K   s*   t |tst|fi |}| j| dS )z8
        Add a new stream filter to this lexer.
        N)
isinstancer   r   r=   append)rA   rB   r>   r#   r#   r&   r@   u   s   
zLexer.add_filterc                 C   r!   )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+   }   r(   zLexer.analyse_textFc                    s  t tss jdkrt\}no jdkr_zddl}W n ty'   tdw d}tD ]\}}|rCt|d 	|d} nq,|du r\|
dd }	|dpYd	d}|n!	 jd
rrtd
d nd
rtd
d dddd jr n jrd jdkr j jrdsd7  fdd}	|	 }
|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.
        r;   chardetr   NzkTo enable chardet encoding guessing, please install the chardet library from http://chardet.feedparser.org/replacei   r:   r    u   ﻿z

c                  3   s&      D ]
\} }}||fV  qd S N)get_tokens_unprocessed)_tvrA   rI   r#   r&   streamer   s   z"Lexer.get_tokens.<locals>.streamer)rG   r   r:   r   rJ   ImportError_encoding_map
startswithlendecodedetectr?   rK   r7   stripr6   r9   
expandtabsr8   endswithr   r=   )rA   rI   
unfilteredrP   rJ   decodedbomr:   encrT   streamr#   rS   r&   
get_tokens   sT   
	







zLexer.get_tokensc                 C   s   t )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.
        )NotImplementedErrorrS   r#   r#   r&   rO      s   zLexer.get_tokens_unprocessed)F)r2   r3   r4   r5   r/   aliases	filenamesalias_filenames	mimetypespriorityrC   rF   r@   r+   rc   rO   r#   r#   r#   r&   r   3   s    
;r   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   s<   |di || _ |di || _|| _tj| fi | d S Nr#   )
root_lexerlanguage_lexerneedler   rC   )rA   _root_lexer_language_lexer_needler>   r#   r#   r&   rC      s   zDelegatingLexer.__init__c                 C   s   d}g }g }| j |D ]$\}}}|| ju r(|r#|t||f g }||7 }q||||f q|r<|t||f t|| j|S )N )rl   rO   rm   rH   rX   do_insertionsrk   )rA   rI   buffered
insertions
lng_bufferirQ   rR   r#   r#   r&   rO      s   


z&DelegatingLexer.get_tokens_unprocessedN)r2   r3   r4   r5   r   rC   rO   r#   r#   r#   r&   r      s    	r   c                   @      e Zd ZdZdS )r   zI
    Indicates that a state should include rules from another state.
    Nr2   r3   r4   r5   r#   r#   r#   r&   r      s    r   c                   @   r)   )_inheritzC
    Indicates the a state should inherit from its superclass.
    c                 C   r!   )Nr   r#   rE   r#   r#   r&   rF        z_inherit.__repr__N)r2   r3   r4   r5   rF   r#   r#   r#   r&   ry      s    ry   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 | |S rN   )tupler-   )clsargsr#   r#   r&   r-     s   zcombined.__new__c                 G   s   d S rN   r#   )rA   r~   r#   r#   r&   rC     s   zcombined.__init__N)r2   r3   r4   r5   r-   rC   r#   r#   r#   r&   r{   	  s    r{   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 rN   )_text_start)rA   startrI   r#   r#   r&   rC     s   
z_PseudoMatch.__init__Nc                 C   s   | j S rN   )r   rA   argr#   r#   r&   r     s   z_PseudoMatch.startc                 C   s   | j t| j S rN   )r   rX   r   r   r#   r#   r&   end"  s   z_PseudoMatch.endc                 C   s   |rt d| jS )NzNo such group)
IndexErrorr   r   r#   r#   r&   group%  s   z_PseudoMatch.groupc                 C   s   | j fS rN   )r   rE   r#   r#   r&   groups*  s   z_PseudoMatch.groupsc                 C   s   i S rN   r#   rE   r#   r#   r&   	groupdict-  rz   z_PseudoMatch.groupdictrN   )
r2   r3   r4   r5   rC   r   r   r   r   r   r#   r#   r#   r&   r     s    


r   c                     s   d fdd	}|S )zL
    Callback that yields multiple actions for each group in the match.
    Nc                 3   s    t  D ]O\}}|d u rqt|tu r)||d }|r(||d ||fV  q||d }|d urT|r>||d |_|| t||d ||D ]}|rS|V  qLq|r^| |_d S d S )N   )	enumerater,   r	   r   r   posr   r   )lexermatchctxrv   actiondataitemr~   r#   r&   callback5  s,   zbygroups.<locals>.callbackrN   r#   )r~   r   r#   r   r&   r   1  s   r   c                   @   rw   )_ThiszX
    Special singleton used for indicating the caller class.
    Used by ``using``.
    Nrx   r#   r#   r#   r&   r   K  s    r   c                    sl   i dv r d}t|ttfr|d< nd|fd<  tu r+dfdd	}|S 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   sx    r | j | jdi }n| }| }|j| fi  D ]\}}}|| ||fV  q#|r:| |_d S d S rj   )updater>   rD   r   rO   r   r   r   r   r   r   lxsrv   rQ   rR   )	gt_kwargskwargsr#   r&   r   i  s    zusing.<locals>.callbackc                 3   sl     | j  di }| }|j| fi D ]\}}}|| ||fV  q|r4| |_d S d S rj   )r   r>   r   rO   r   r   r   r   _otherr   r   r#   r&   r   x  s    rN   )poprG   listr|   r   )r   r   r   r   r#   r   r&   r   S  s   


r   c                   @   r)   )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 rN   )r   )rA   r   r#   r#   r&   rC     s   
zdefault.__init__N)r2   r3   r4   r5   rC   r#   r#   r#   r&   r     s    r   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
    rq   c                 C   s   || _ || _|| _d S rN   )r   prefixsuffix)rA   r   r   r   r#   r#   r&   rC     s   
zwords.__init__c                 C   s   t | j| j| jdS )Nr   r   )r   r   r   r   rE   r#   r#   r&   r?     s   z	words.getN)rq   rq   )r2   r3   r4   r5   rC   r?   r#   r#   r#   r&   r     s    
r   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	| }t||jS )zBPreprocess the regular expression component of a token definition.)rG   r   r?   recompiler   )r}   regexrflagsr   r#   r#   r&   _process_regex  s   
zRegexLexerMeta._process_regexc                 C   s&   t |tu st|sJ d|f |S )z5Preprocess the token component of a token definition.z2token type must be simple type or callable, not %r)r,   r	   callable)r}   tokenr#   r#   r&   _process_token  s   zRegexLexerMeta._process_tokenc                 C   s  t |tr/|dkrdS ||v r|fS |dkr|S |dd dkr)t|dd  S J d| t |trbd	| j }|  jd
7  _g }|D ]}||ksPJ d| || ||| qD|||< |fS t |tr||D ]}||v sy|dv syJ d| qi|S J d| )z=Preprocess the state transition action of a token definition.#pop#pushN   z#pop:Fzunknown new state %rz_tmp_%dr   zcircular state ref %r)r   r   zunknown new state zunknown new state def %r)rG   strintr{   _tmpnameextend_process_stater|   )r}   	new_stateunprocessed	processed	tmp_stateitokensistater#   r#   r&   _process_new_state  s<   





z!RegexLexerMeta._process_new_statec                 C   s~  t |tu sJ d| |d dksJ d| ||v r || S g  }||< | j}|| D ]}t|trK||ks>J d| || ||t| q-t|trQq-t|trk| 	|j
||}|tdjd|f q-t |tu swJ d| z| |d ||}W n ty }	 ztd	|d || |	f d}	~	ww | |d
 }
t|dkrd}n	| 	|d ||}|||
|f q-|S )z%Preprocess a single state definition.zwrong state name %rr   #zinvalid state name %rzcircular state reference %rrq   Nzwrong rule def %rz+uncompilable regex %r in state %r of %r: %sr      )r,   r   flagsrG   r   r   r   ry   r   r   r   rH   r   r   r   r|   r   	Exception
ValueErrorr   rX   )r}   r   r   r   tokensr   tdefr   rexerrr   r#   r#   r&   r     sH   



zRegexLexerMeta._process_stateNc                 C   s<   i  }| j |< |p| j| }t|D ]	}| ||| q|S )z-Preprocess a dictionary of token definitions.)_all_tokensr   r   r   )r}   r/   	tokendefsr   r   r#   r#   r&   process_tokendef  s
   zRegexLexerMeta.process_tokendefc           
   
   C   s   i }i }| j D ]_}|jdi }t|D ]Q\}}||}|du r;|||< z|t}W n	 ty5   Y qw |||< q||d}|du rFq||||d < z|t}	W n	 ty^   Y qw ||	 ||< 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.
        r   Nr   )__mro____dict__r?   r   indexr   r   r   )
r}   r   inheritablectoksr   itemscuritemsinherit_ndxnew_inh_ndxr#   r#   r&   get_tokendefs
  s6   

zRegexLexerMeta.get_tokendefsc                 O   sR   d| j vri | _d| _t| dr| jrn	| d|  | _tj	| g|R i |S )z:Instantiate cls after preprocessing its token definitions._tokensr   token_variantsrq   )
r   r   r   hasattrr   r   r   r   r,   __call__)r}   r~   kwdsr#   r#   r&   r   ;  s   
zRegexLexerMeta.__call__rN   )r2   r3   r4   r5   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  }	 |D ]|\}}}	|||}
|
r|dur=t|tu r2|||
 fV  n|| |
D ]}|V  q7|
 }|	durt|	trj|	D ]}|dkrW|  qL|dkrc|	|d  qL|	| qLnt|	t
ru||	d= n|	dkr|	|d  nJ d|	 ||d  } n3qz'|| d	krd
g}|d
 }|td	fV  |d7 }W q|t|| fV  |d7 }W n
 ty   Y dS w q)z}
        Split ``text`` into (tokentype, text) pairs.

        ``stack`` is the inital stack (default: ``['root']``)
        r   r   r   Nr   r   Fwrong state def: %rrL   r   )r   r   r,   r	   r   r   rG   r|   r   rH   r   r   r   r   )rA   rI   r   r   r   
statestackstatetokensrexmatchr   r   mr   r   r#   r#   r&   rO   h  sZ   



z!RegexLexer.get_tokens_unprocessedNr   )	r2   r3   r4   r5   r   	MULTILINEr   r   rO   r#   r#   r#   r&   r   I  s
    r   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   )rI   r   rX   r   r   )rA   rI   r   r   r   r#   r#   r&   rC     s   zLexerContext.__init__c                 C   s   d| j | j| jf S )NzLexerContext(%r, %r, %r))rI   r   r   rE   r#   r#   r&   rF     s   zLexerContext.__repr__NN)r2   r3   r4   r5   rC   rF   r#   r#   r#   r&   r     s    
r   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   s   | j }|st|d}|d }n|}||jd  }|j}	 |D ]\}}}|||j|j}	|	r|dur\t|tu rG|j||	 fV  |	 |_n|| |	|D ]}
|
V  qM|s\||jd  }|durt	|t
r|D ] }|dkrs|j  qg|dkr|j|jd  qg|j| qgn t	|tr|j|d= n|dkr|j|jd  nJ d	| ||jd  } nGqz;|j|jkrW dS ||j d
krdg|_|d }|jtd
fV  | jd7  _W q|jt||j fV  | jd7  _W n
 ty   Y dS w q)z
        Split ``text`` into (tokentype, text) pairs.
        If ``context`` is given, use this lexer context instead.
        r   r   r   r   Nr   r   Fr   rL   )r   r   r   rI   r   r   r,   r	   r   rG   r|   r   rH   r   r   r   r   )rA   rI   contextr   r   r   r   r   r   r   r   r   r#   r#   r&   rO     sh   



 z)ExtendedRegexLexer.get_tokens_unprocessedr   )r2   r3   r4   r5   rO   r#   r#   r#   r&   r     s    r   c              	   c   s   t | } zt| \}}W n ty   |D ]}|V  qY dS w d}d}|D ]s\}}}	|du r1|}d}
|r|t|	 |kr|	|
||  }|||fV  |t|7 }|D ]\}}}|||fV  |t|7 }qS|| }
zt| \}}W n ty|   d}Y nw |r|t|	 |ks=|||	|
d fV  |t|	|
 7 }q&|r|pd}|D ]\}}}	|||	fV  |t|	7 }qzt| \}}W n ty   d}Y dS w |sdS 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StopIterationrX   )rt   r   r   r   r   realposinsleftrv   rQ   rR   olditmpvalit_indexit_tokenit_valuepr#   r#   r&   rr     sX   rr   c                   @   r)   )ProfilingRegexLexerMetaz>Metaclass for ProfilingRegexLexer, collects regex timing info.c                    sL   t |trt|j|j|jdn|t|tjf fdd	}|S )Nr   c                    s`    j d fddg}t }| ||}t }|d  d7  < |d  || 7  < |S )Nr   r   r"   r   )
_prof_data
setdefaulttimer   )rI   r   endposinfot0rest1r}   compiledr   r   r#   r&   
match_func@  s   z:ProfilingRegexLexerMeta._process_regex.<locals>.match_func)	rG   r   r   r   r   r   r   sysmaxsize)r}   r   r   r   r   r#   r   r&   r   8  s   

z&ProfilingRegexLexerMeta._process_regexN)r2   r3   r4   r5   r   r#   r#   r#   r&   r   5  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i  t ||D ]}|V  q j j }tdd | D  fdddd}tdd |D }t	  t	d j j
t||f  t	d	 t	d
d  t	d |D ]}t	d|  qVt	d	 d S )Nc                 s   sP    | ]#\\}}\}}|t |d dddd |d| d| | fV  qdS )zu'z\\\NA   i  )reprr[   rK   ).0r   rnrQ   r#   r#   r&   	<genexpr>X  s    z=ProfilingRegexLexer.get_tokens_unprocessed.<locals>.<genexpr>c                    s
   |  j  S rN   )_prof_sort_indexr$   rE   r#   r&   r'   [  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  ]  s    z2Profiling 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)rD   r   rH   r   rO   r   sortedr   sumprintr2   rX   )rA   rI   r   tokrawdatar   	sum_totalr1   r#   rE   r&   rO   R  s,   
z*ProfilingRegexLexer.get_tokens_unprocessedNr   )r2   r3   r4   r5   r   r  rO   r#   r#   r#   r&   r   K  s
    r   )9r5   
__future__r   r   r   r   pygments.filterr   r   pygments.filtersr   pygments.tokenr   r   r   r	   pygments.utilr
   r   r   r   r   r   r   r   r   pygments.regexoptr   __all__rV   staticmethod_default_analyser,   r*   objectr   r   r   r   ry   r   r|   r{   r   r   r   r   r   r   r   r   r   r   r   rr   r   r   r#   r#   r#   r&   <module>   sN   
, '2 )WE?