U
    Te                     @  sx   d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	 G dd dZ
G d	d
 d
ZG dd deZdS )    )annotations)copy)Any)
ParseError)UnexpectedCharErrorTOMLCharc                   @  s8   e Zd ZddddddddZd dd	d
Zdd ZdS )_StateFSourcezbool | NoneNone)sourcesave_markerrestorereturnc                 C  s   || _ || _|| _d S N)_source_save_markerr   )selfr   r   r    r   m/mounts/lovelace/software/anaconda3/envs/qiime2-amplicon-2024.2/lib/python3.8/site-packages/tomlkit/source.py__init__   s    z_State.__init__r   c                 C  s0   t | jj| _| jj| _| jj| _| jj| _| S r   )r   r   _chars_idx_current_markerr   r   r   r   	__enter__   s
    


z_State.__enter__c                 C  s<   | j s
|r8| j| j_| j| j_| j| j_| jr8| j| j_d S r   )r   r   r   r   r   r   r   )r   exception_typeexception_valtracer   r   r   __exit__   s    



z_State.__exit__N)FF)__name__
__module____qualname__r   r   r!   r   r   r   r   r	      s
     
	r	   c                   @  s>   e Zd ZdZdddddZdd Zd	d
ddZdd ZdS )_StateHandlerz)
    State preserver for the Parser.
    r
   r   )r   r   c                 C  s   || _ g | _d S r   )r   _states)r   r   r   r   r   r   .   s    z_StateHandler.__init__c                 O  s   t | jf||S r   )r	   r   )r   argskwargsr   r   r   __call__2   s    z_StateHandler.__call__r	   r   c                 C  s   |  }| j | | S r   )r&   appendr   )r   stater   r   r   r   5   s    z_StateHandler.__enter__c                 C  s   | j  }||||S r   )r&   popr!   )r   r   r   r    r+   r   r   r   r!   :   s    
z_StateHandler.__exit__N)r"   r#   r$   __doc__r   r)   r   r!   r   r   r   r   r%   )   s
   r%   c                      s   e Zd ZedZddd fddZdd Zed	d
ddZedd
ddZ	edd
ddZ
edd
ddZdd
ddZd1dddddZd2ddddddZd3d"d#Zdd
d$d%Zdd
d&d'Zefd(d)d)d*d+d,d-Zd.d
d/d0Z  ZS )4r
    strr   )_r   c                   sN   t    tdd t| D | _d| _d| _td| _t	| | _
|   d S )Nc                 S  s   g | ]\}}|t |fqS r   r   ).0icr   r   r   
<listcomp>F   s     z#Source.__init__.<locals>.<listcomp>r    )superr   iter	enumerater   r   r   r   r   r%   _stateinc)r   r0   	__class__r   r   r   B   s    


zSource.__init__c                 C  s   |    |   d S r   )r:   markr   r   r   r   resetP   s    zSource.resetr%   r   c                 C  s   | j S r   )r9   r   r   r   r   r+   W   s    zSource.stateintc                 C  s   | j S r   )r   r   r   r   r   idx[   s    z
Source.idxr   c                 C  s   | j S r   )r   r   r   r   r   current_   s    zSource.currentc                 C  s   | j S r   )r   r   r   r   r   markerc   s    zSource.markerc                 C  s   | | j | j S )z=
        Extracts the value between marker and index
        )r   r   r   r   r   r   extractg   s    zSource.extractNztype[ParseError] | Nonebool)	exceptionr   c                 C  sT   zt | j\| _| _W dS  tk
rN   t| | _| j| _|rH| |Y dS X dS )z
        Increments the parser if the end of the input has not been reached.
        Returns whether or not it was able to advance.
        TFN)nextr   r   r   StopIterationlenEOFparse_error)r   rE   r   r   r   r:   m   s    

z
Source.inc)nrE   r   c                   s   t  fddt|D S )zm
        Increments the parser by n characters
        if the end of the input has not been reached.
        c                 3  s   | ]}j  d V  qdS ))rE   N)r:   )r1   r0   rE   r   r   r   	<genexpr>   s     zSource.inc_n.<locals>.<genexpr>)allrange)r   rK   rE   r   rL   r   inc_n~   s    zSource.inc_nr   c                 C  sH   | j |kr.|dkr.|d8 }|d8 }|  s q.q |dkrD| t| j dS )zD
        Consume chars until min/max is satisfied is valid.
        r      N)rA   r:   rJ   r   )r   charsminmaxr   r   r   consume   s    zSource.consumec                 C  s   | j | jkS )zN
        Returns True if the parser has reached the end of the input.
        )r   rI   r   r   r   r   end   s    z
Source.endc                 C  s   | j | _dS )zA
        Sets the marker to the index's current position
        N)r   r   r   r   r   r   r=      s    zSource.markztype[ParseError]r   r   )rE   r'   r(   r   c                 O  s   |   \}}|||f||S )zJ
        Creates a generic "parse error" at the current position.
        )_to_linecol)r   rE   r'   r(   linecolr   r   r   rJ      s    	zSource.parse_errorztuple[int, int]c                 C  sf   d}t |  D ]D\}}|t| d | jkrD|d | j| f  S |t|d 7 }qt|  dfS )Nr   rR   )r8   
splitlinesrH   r@   )r   curr2   rY   r   r   r   rX      s    zSource._to_linecol)N)N)r   rQ   )r"   r#   r$   r   rI   r   r>   propertyr+   r@   rA   rB   rC   r:   rP   rV   rW   r=   r   rJ   rX   __classcell__r   r   r;   r   r
   ?   s(   
r
   N)
__future__r   r   typingr   tomlkit.exceptionsr   r   tomlkit.toml_charr   r	   r%   r/   r
   r   r   r   r   <module>   s   