U
    祡c                     @   s   U d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	m
Z
 ddlmZ eG dd dZG dd	 d	eZd
ddddddedejddddedejeejejejB ddddddZded< G dd  d ZdS )!    N)	dataclass)DictIteratorNoReturnOptionalTupleUnion   )	Specifierc                   @   s&   e Zd ZU eed< eed< eed< dS )TokennametextpositionN)__name__
__module____qualname__str__annotations__int r   r   8/tmp/pip-unpacked-wheel-6wwe1vpl/packaging/_tokenizer.pyr   	   s   
r   c                       sB   e Zd ZdZeeeeef dd fddZedddZ  Z	S )	ParserSyntaxErrorz7The provided source text could not be parsed correctly.N)messagesourcespanreturnc                   s    || _ || _|| _t   d S )N)r   r   r   super__init__)selfr   r   r   	__class__r   r   r      s    zParserSyntaxError.__init__r   c                 C   s>   d| j d  d| j d | j d    d }d| j| j|gS )N r   ~r	   ^z
    )r   joinr   r   )r   markerr   r   r   __str__    s    *zParserSyntaxError.__str__)
r   r   r   __doc__r   r   r   r   r'   __classcell__r   r   r   r   r      s   
r   z\s*\(z\(z\)z\[z\];,zk
            (
                ('[^']*')
                |
                ("[^"]*")
            )
        z(===|==|~=|!=|<=|>=|<|>)z\b(or|and)\bz\bin\bz\bnot\ba  
            \b(
                python_version
                |python_full_version
                |os[._]name
                |sys[._]platform
                |platform_(release|system)
                |platform[._](version|machine|python_implementation)
                |python_implementation
                |implementation_(name|version)
                |extra
            )\b
        z\@z[^ \t]+z\b[a-zA-Z0-9][a-zA-Z0-9._-]*\bz[ \t]+$)LPARENZLEFT_PARENTHESISZRIGHT_PARENTHESISZLEFT_BRACKETZRIGHT_BRACKET	SEMICOLONCOMMAZQUOTED_STRINGOPBOOLOPINZNOTVARIABLEVERSIONATURL
IDENTIFIERZWSZEND&Dict[str, Union[str, re.Pattern[str]]]DEFAULT_RULESc                   @   s   e Zd ZdZedddddZedddd	Zd
deeedddZeee	dddZ
e	dddZdddeee ee edddZejeeee dddZdS )	TokenizerzContext-sensitive token parsing.

    Provides methods to examine the input stream to check whether the next token
    matches.
    r8   N)r   rulesr   c                C   s*   || _ dd | D | _d | _d| _d S )Nc                 S   s   i | ]\}}|t |qS r   )recompile).0r   patternr   r   r   
<dictcomp>b   s     z&Tokenizer.__init__.<locals>.<dictcomp>r   )r   itemsr;   
next_tokenr   )r   r   r;   r   r   r   r   [   s    zTokenizer.__init__)r   r   c                 C   s   |  |r|   dS )z8Move beyond provided token name, if at current position.N)checkread)r   r   r   r   r   consumeh   s    
zTokenizer.consumeF)peek)r   rF   r   c                C   sz   | j dks td|d| j || jks8td|| j| }|| j| j}|dkr^dS |svt||d | j| _ dS )zCheck whether the next token has the provided name.

        By default, if the check succeeds, the token *must* be read before
        another check. If `peek` is set to `True`, the token is not loaded and
        would need to be checked again.
        NzCannot check for z, already have zUnknown token name: Fr   T)rB   AssertionErrorr;   matchr   r   r   )r   r   rF   Z
expressionrH   r   r   r   rC   m   s    
zTokenizer.check)r   expectedr   c                C   s"   |  |s| d| |  S )zsExpect a certain token name next, failing with a syntax error otherwise.

        The token is *not* read.
        z	Expected )rC   raise_syntax_errorrD   )r   r   rI   r   r   r   expect   s    
zTokenizer.expectr!   c                 C   s0   | j }|dk	st|  jt|j7  _d| _ |S )z%Consume the next token and return it.N)rB   rG   r   lenr   )r   tokenr   r   r   rD      s
    zTokenizer.read)
span_startspan_end)r   rN   rO   r   c                C   s8   |dkr| j n||dkr| j n|f}t|| j|ddS )z.Raise ParserSyntaxError at the given position.N)r   r   )r   r   r   )r   r   rN   rO   r   r   r   r   rJ      s    	zTokenizer.raise_syntax_error)
open_tokenclose_tokenr   c                 c   s^   |  |r| j}|   nd }|d k	V  |d kr4d S |  |sR| jd| |d |   d S )NzExpected closing )rN   )rC   r   rD   rJ   )r   rP   rQ   Zopen_positionr   r   r   enclosing_tokens   s    



zTokenizer.enclosing_tokens)r   r   r   r(   r   r   rE   boolrC   r   rK   rD   r   r   r   rJ   
contextlibcontextmanagerr   rR   r   r   r   r   r:   T   s&   	r:   )rT   r<   Zdataclassesr   typingr   r   r   r   r   r   
specifiersr
   r   	Exceptionr   r=   VERBOSEZ_version_regex_str
IGNORECASEr9   r   r:   r   r   r   r   <module>   sF     
/