U
    :qLe                     @   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-edddZdd Zd.edd	d
ZedddZdd Z	dd Z
edddZedddZedddZdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zed(d)d*Zd+d, ZdS )/ATNConfigSetT)fullCtxc                 C   s<   t  | _|| _d| _g | _d| _d | _d| _d| _d| _	d S )NFr   )
dictconfigLookupr   readonlyconfigs	uniqueAltconflictingAltshasSemanticContextdipsIntoOuterContextcachedHashCode)selfr    r   n/home/p21-0144/sympy/latex2sympy2solve-back-end/sympyEq/lib/python3.8/site-packages/antlr4/atn/ATNConfigSet.py__init__   s    zATNConfigSet.__init__c                 C   s
   | j  S N)r   __iter__r   r   r   r   r   ;   s    zATNConfigSet.__iter__Nconfigc                 C   s   | j rtd|jtjk	r d| _|jdkr0d| _| |}||krXd| _	| j
| dS | j }t|j|j||}t|j|j|_|jrd|_||_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   addG   s$    

zATNConfigSet.addc                    sj      }| j|d }|d k	rBt fdd|D d }|d k	rB|S |d kr\ g}|| j|< n
|   S )Nc                 3   s   | ]}  |r|V  qd S r   )equalsForConfigSet.0cfgr   r   r   	<genexpr>d   s     
 z(ATNConfigSet.getOrAdd.<locals>.<genexpr>)hashCodeForConfigSetr   getnextr'   )r   r    hlrr   r   r   r&   `   s    
zATNConfigSet.getOrAddc                 C   s   t dd | jD S )Nc                 s   s   | ]}|j V  qd S r   )state)r2   cr   r   r   r4   o   s     z)ATNConfigSet.getStates.<locals>.<genexpr>)setr   r   r   r   r   	getStatesn   s    zATNConfigSet.getStatesc                 C   s   t dd | jD S )Nc                 s   s    | ]}|j tjkr|j V  qd S r   )r#   r	   r$   r1   r   r   r   r4   r   s      z-ATNConfigSet.getPredicates.<locals>.<genexpr>)listr   r   r   r   r   getPredicatesq   s    zATNConfigSet.getPredicates)ic                 C   s
   | j | S r   )r   )r   rA   r   r   r   r6   t   s    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   rB   r    r   r   r   optimizeConfigsw   s    
zATNConfigSet.optimizeConfigs)collc                 C   s   |D ]}|  | qdS )NF)r/   )r   rF   r<   r   r   r   addAll   s    zATNConfigSet.addAllc                 C   sp   | |krdS t |tsdS | jd k	oj| j|jkoj| j|jkoj| j|jkoj| j|jkoj| j|jkoj| 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)r8   r3   r   r   r   <lambda>       z*ATNConfigSet.hashConfigs.<locals>.<lambda>r   )r   r   r   r   r   r   rL      s    zATNConfigSet.hashConfigsc                 C   s
   t | jS r   rC   r   r   r   r   r   __len__   s    zATNConfigSet.__len__c                 C   s   t | jdkS )Nr   rQ   r   r   r   r   isEmpty   s    zATNConfigSet.isEmptyc                 C   sN   | j d krtd| }| j |d }|d k	rJ|D ]}||r4 dS q4dS )Nz1This method is not implemented for readonly sets.TF)r   r
   r5   r6   r0   )r   r    r8   r9   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   rU      s
    
zATNConfigSet.clear)r   c                 C   s   || _ d | _d S r   )r   r   )r   r   r   r   r   setReadonly   s    zATNConfigSet.setReadonlyc              
   C   s   t  }|t| j | jr8|d |t| j | jtjkr^|d |t| j | j	d k	r|d |t| j	 | j
r|d | W  5 Q R  S Q R X 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__)T)N)__name__
__module____qualname__boolr   r   r   r/   r&   r>   r@   intr6   ATNSimulatorrE   r?   rG   rK   rM   rL   rR   rS   rT   rU   rV   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      s    zOrderedATNConfigSet.__init__)r]   r^   r_   r   __classcell__r   r   re   r   rc      s   rc   )ior   	functoolsr   antlr4.PredictionContextr   r   antlr4.Utilsr   antlr4.atn.ATNr   antlr4.atn.ATNConfigr   antlr4.atn.SemanticContextr	   antlr4.error.Errorsr
   r   rb   objectr   rc   r   r   r   r   <module>   s    6