o
    ڷix                      @   s   d dl mZ d dlmZ d dlmZ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mZ d	ZG d
d deZG dd deZd	S )    )StringIO)reduce)PredictionContextmerge)str_list)ATN)	ATNConfig)SemanticContext)UnsupportedOperationExceptionIllegalStateExceptionNc                   @   s   e Zd ZdZd.defddZdd Zd/d	efd
dZd	efddZ	dd Z
dd ZdefddZdefddZdefddZdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)efd*d+Zd,d- ZdS )0ATNConfigSet)	configLookupfullCtxreadonlyconfigs	uniqueAltconflictingAltshasSemanticContextdipsIntoOuterContextcachedHashCodeTr   c                 C   s<   t  | _|| _d| _g | _d| _d | _d| _d| _d| _	d S )NFr   )
dictr   r   r   r   r   r   r   r   r   )selfr    r   M/home/ubuntu/vllm_env/lib/python3.10/site-packages/antlr4/atn/ATNConfigSet.py__init__$   s   
zATNConfigSet.__init__c                 C   s
   | j  S N)r   __iter__r   r   r   r   r   A      
zATNConfigSet.__iter__Nconfigc                 C   s   | j rtd|jtjurd| _|jdkrd| _| |}||u r,d| _	| j
| dS | j }t|j|j||}t|j|j|_|jrGd|_||_dS )NThis set is readonlyTr   r   )r   	ExceptionsemanticContextr	   NONEr   reachesIntoOuterContextr   getOrAddr   r   appendr   r   contextmaxprecedenceFilterSuppressed)r   r    
mergeCacheexistingrootIsWildcardmergedr   r   r   addM   s$   

zATNConfigSet.addc                    sl      }| j|d }|d ur!t fdd|D d }|d ur!|S |d u r/ g}|| j|<  S |   S )Nc                 3   s    | ]
}  |r|V  qd S r   )equalsForConfigSet.0cfgr    r   r   	<genexpr>j   s    z(ATNConfigSet.getOrAdd.<locals>.<genexpr>)hashCodeForConfigSetr   getnextr'   )r   r    hlrr   r4   r   r&   f   s   

zATNConfigSet.getOrAddc                 C      t dd | jD S )Nc                 s   s    | ]}|j V  qd S r   )state)r2   cr   r   r   r5   u   s    z)ATNConfigSet.getStates.<locals>.<genexpr>)setr   r   r   r   r   	getStatest      zATNConfigSet.getStatesc                 C   r<   )Nc                 s   s"    | ]}|j tjkr|j V  qd S r   )r#   r	   r$   r1   r   r   r   r5   x   s     z-ATNConfigSet.getPredicates.<locals>.<genexpr>)listr   r   r   r   r   getPredicatesw   rA   zATNConfigSet.getPredicatesic                 C   s
   | j | S r   )r   )r   rD   r   r   r   r7   z   r   zATNConfigSet.getinterpreterc                 C   s>   | j rtdt| jdkrd S | jD ]	}||j|_qd S )Nr!   r   )r   r   lenr   getCachedContextr(   )r   rE   r    r   r   r   optimizeConfigs}   s   
zATNConfigSet.optimizeConfigscollc                 C   s   |D ]}|  | qdS )NF)r/   )r   rI   r>   r   r   r   addAll   s   zATNConfigSet.addAllc                 C   sp   | |u rdS t |tsdS | jd uo5| j|jko5| j|jko5| j|jko5| j|jko5| j|jko5| j|jk}|S )NTF)
isinstancer   r   r   r   r   r   r   )r   othersamer   r   r   __eq__   s$   







zATNConfigSet.__eq__c                 C   s(   | j r| jdkr|  | _| jS |  S )Nr   )r   r   hashConfigsr   r   r   r   __hash__   s
   

zATNConfigSet.__hash__c                 C   s   t dd | jdS )Nc                 S   s   t | |fS r   )hash)r9   r3   r   r   r   <lambda>   s    z*ATNConfigSet.hashConfigs.<locals>.<lambda>r   )r   r   r   r   r   r   rO      s   zATNConfigSet.hashConfigsc                 C   s
   t | jS r   rF   r   r   r   r   r   __len__   r   zATNConfigSet.__len__c                 C   s   t | jdkS )Nr   rS   r   r   r   r   isEmpty      zATNConfigSet.isEmptyc                 C   sN   | j d u r	td| }| j |d }|d ur%|D ]
}||r$ dS qdS )Nz1This method is not implemented for readonly sets.TF)r   r
   r6   r7   r0   )r   r    r9   r:   r>   r   r   r   __contains__   s   

zATNConfigSet.__contains__c                 C   s,   | j rtd| j  d| _| j  d S )Nr!   r   )r   r   r   clearr   r   r   r   r   r   rX      s
   
zATNConfigSet.clearr   c                 C   s   || _ d | _d S r   )r   r   )r   r   r   r   r   setReadonly   s   
zATNConfigSet.setReadonlyc                 C   s   t  Q}|t| j | jr|d |t| j | jtjkr/|d |t| j | j	d urA|d |t| j	 | j
rI|d | W  d    S 1 sWw   Y  d S )Nz,hasSemanticContext=z,uniqueAlt=z,conflictingAlts=z,dipsIntoOuterContext)r   writer   r   r   strr   r   INVALID_ALT_NUMBERr   r   getvalue)r   bufr   r   r   __str__   s   




$zATNConfigSet.__str__)Tr   )__name__
__module____qualname__	__slots__boolr   r   r   r/   r&   r@   rC   intr7   ATNSimulatorrH   rB   rJ   rN   rP   rO   rT   rU   rW   rX   rY   r_   r   r   r   r   r      s(    r   c                       s   e Zd Z fddZ  ZS )OrderedATNConfigSetc                    s   t    d S r   )superr   r   	__class__r   r   r      rV   zOrderedATNConfigSet.__init__)r`   ra   rb   r   __classcell__r   r   ri   r   rg      s    rg   )ior   	functoolsr   antlr4.PredictionContextr   r   antlr4.Utilsr   antlr4.atn.ATNr   antlr4.atn.ATNConfigr   antlr4.atn.SemanticContextr	   antlr4.error.Errorsr
   r   rf   objectr   rg   r   r   r   r   <module>   s   
 <