U
    42i-                     @  sF  U d dl mZ d dlZd dlZd dlmZ d dlmZmZm	Z	 ddl
mZ eG dd dZG d	d
 d
eZedededededededejedededededejeejej ejejB edededededededdZded < G d!d" d"ZdS )#    )annotationsN)	dataclass)	GeneratorMappingNoReturn   )	Specifierc                   @  s&   e Zd ZU ded< ded< ded< dS )TokenstrnametextintpositionN)__name__
__module____qualname____annotations__ r   r   8/tmp/pip-unpacked-wheel-7wv4vqcv/packaging/_tokenizer.pyr	      s   
r	   c                      s:   e Zd ZdZddddd fddZddd	d
Z  ZS )ParserSyntaxErrorz7The provided source text could not be parsed correctly.r
   ztuple[int, int]None)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  sB   d| j d  d| j d | j d    d }| j d| j d| S )N r   ~r   ^z
    )r   r   r   )r   markerr   r   r   __str__"   s    *zParserSyntaxError.__str__)r   r   r   __doc__r   r%   __classcell__r   r   r   r   r      s   r   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)
                |extras?
                |dependency_groups
            )\b
        z\@z[^ \t]+z\b[a-zA-Z0-9][a-zA-Z0-9._-]*\bz\.\*z\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*z[ \t]+$)ZLEFT_PARENTHESISZRIGHT_PARENTHESISZLEFT_BRACKETZRIGHT_BRACKET	SEMICOLONCOMMAZQUOTED_STRINGOPBOOLOPINZNOTVARIABLEZ	SPECIFIERATURL
IDENTIFIERZVERSION_PREFIX_TRAILZVERSION_LOCAL_LABEL_TRAILZWSZENDzdict[str, re.Pattern[str]]DEFAULT_RULESc                   @  s   e Zd ZdZddddddZdddd	d
ZddddddddZddddddZddddZddddddddddZ	e
jddddd d!d"ZdS )#	TokenizerzContext-sensitive token parsing.

    Provides methods to examine the input stream to check whether the next token
    matches.
    r
   zMapping[str, re.Pattern[str]]r   )r   rulesr   c                C  s   || _ || _d | _d| _d S )Nr   )r   r6   
next_tokenr   )r   r   r6   r   r   r   r   b   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   consumem   s    
zTokenizer.consumeF)peekbool)r   r;   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)r7   AssertionErrorr6   matchr   r   r	   )r   r   r;   Z
expressionr>   r   r   r   r8   r   s    
zTokenizer.checkr	   )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 )r8   raise_syntax_errorr9   )r   r   r?   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)r7   r=   r   lenr   )r   tokenr   r   r   r9      s
    zTokenizer.readN)
span_startspan_endz
int | Noner   )r   rD   rE   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   rD   rE   r   r   r   r   r@      s    	zTokenizer.raise_syntax_errorzGenerator[(None, None, None)])
open_tokenclose_tokenaroundr   c                c  sf   |  |r| j}|   nd }d V  |d kr0d S |  |sZ| jd| d| d| |d |   d S )NzExpected matching z for z, after )rD   )r8   r   r9   r@   )r   rF   rG   rH   Zopen_positionr   r   r   enclosing_tokens   s    


zTokenizer.enclosing_tokens)r   r   r   r&   r   r:   r8   rA   r9   r@   
contextlibcontextmanagerrI   r   r   r   r   r5   [   s   	r5   )
__future__r   rJ   reZdataclassesr   typingr   r   r   
specifiersr   r	   	Exceptionr   compileVERBOSEZ_operator_regex_strZ_version_regex_str
IGNORECASEr4   r   r5   r   r   r   r   <module>   sP    


4