o
    @j-                     @   s  d dl Z d dlZd dlZd dlmZmZmZmZmZm	Z	m
Z
 edddZeeeef gef ZdOdede	edf defd	d
ZdedefddZdededee defddZG dd dZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZG d#d$ d$eZG d%d& d&eZG d'd( d(eZG d)d* d*eZG d+d, d,eZG d-d. d.eZ G d/d0 d0eZ!G d1d2 d2eZ"G d3d4 d4eZ#G d5d6 d6eZ$G d7d8 d8eZ%G d9d: d:eZ&G d;d< d<eZ'G d=d> d>eZ(G d?d@ d@eZ)G dAdB dBeZ*G dCdD dDe*Z+G dEdF dFe*Z,G dGdH dHe*Z-G dIdJ dJeZ.G dKdL dLeZ/G dMdN dNeZ0e	eee+e,e-e.f Z1e	eee e!e"e#f Z2dS )P    N)AnyCallableDictListTypeVarUnioncastNodeBaseNode)boundvaluefnreturnc                    sX   t | tr
|  S t | trt fdd| D S t | tr*t fdd| D S | S )Nc                 3       | ]}t | V  qd S Nto_json.0itemr    `/var/www/www-root/data/www/ai-bot.pdev.uz/venv/lib/python3.10/site-packages/fluent/syntax/ast.py	<genexpr>       zto_json.<locals>.<genexpr>c                 3   r   r   r   r   r   r   r   r      r   )
isinstancer
   r   listtuple)r   r   r   r   r   r   
   s   



r   c                 C   sZ   t | trttjt | d }dd |  D }|di |S t | tr+ttt	| S | S )Ntypec                 S   s"   i | ]\}}|d kr|t |qS )r   )	from_json)r   kvr   r   r   
<dictcomp>   s
    zfrom_json.<locals>.<dictcomp>r   )
r   dictgetattrsysmodules__name__itemsr   mapr   )r   clsargsr   r   r   r      s   

r   node1node2ignored_fieldsc                 C   s8   t | t |kr
dS t| tr| ||S tt| |kS )z&Compare two nodes which are not lists.F)r   r   r
   equalsr   bool)r,   r-   r.   r   r   r   scalars_equal$   s
   
r1   c                   @   sl   e Zd ZdZdedefddZdgfdd dee defd	d
Z	dde
edf defddZdefddZdS )r
   zBase class for all Fluent AST nodes.

    All productions described in the ASDL subclass BaseNode, including Span and
    Annotation.  Implements __str__, to_json and traverse.
    selfr   c                    s<   dt dt f fdd | jdi  fddt|  D S )	z(Create a deep clone of the current node.r   r   c                    sR   t | tr	|  S t | tr fdd| D S t | tr't fdd| D S | S )zClone node and its descendants.c                    s   g | ]} |qS r   r   r   childvisitr   r   
<listcomp>>   s    z1BaseNode.clone.<locals>.visit.<locals>.<listcomp>c                 3   s    | ]} |V  qd S r   r   r3   r5   r   r   r   @   s    z0BaseNode.clone.<locals>.visit.<locals>.<genexpr>)r   r
   cloner   r   r   r5   r   r   r6   9   s   


zBaseNode.clone.<locals>.visitc                    s   i | ]	\}}| |qS r   r   r   namer   r5   r   r   r"   E   s    z"BaseNode.clone.<locals>.<dictcomp>Nr   )r   	__class__varsr(   r2   r   r5   r   r8   7   s   zBaseNode.clonespanotherr.   c           
      C   s   t t|  }t t| }|r!|D ]}|| || q||kr'dS |D ]?}t| |}t||}t|tr_t|tr_t|t|krJ dS t||D ]\}}	t	||	|s]  dS qOq)t	|||sh dS q)dS )a  Compare two nodes.

        Nodes are deeply compared on a field by field basis. If possible, False
        is returned early. When comparing attributes and variants in
        SelectExpressions, the order doesn't matter. By default, spans are not
        taken into account.
        FT)
setr=   keysdiscardr$   r   r   lenzipr1   )
r2   r@   r.   	self_keys
other_keyskeyfield1field2elem1elem2r   r   r   r/   H   s.   	


zBaseNode.equalsNr   c                    s<    fddt |  D }|d| jji  r |S |S )Nc                    s   i | ]
\}}|t | qS r   r   r:   r   r   r   r"   p   s    
z$BaseNode.to_json.<locals>.<dictcomp>r   )r=   r(   updater<   r'   )r2   r   objr   r   r   r   o   s   


zBaseNode.to_jsonc                 C   s   t |  S r   )jsondumpsr   r>   r   r   r   __str__y   s   zBaseNode.__str__r   )r'   
__module____qualname____doc__r	   r8   r   strr0   r/   r   ToJsonFnr   r   rQ   r   r   r   r   r
   0   s     '
c                       sF   e Zd ZdZdded def fddZded	ed
dfddZ  Z	S )
SyntaxNodez.Base class for AST nodes which can have Spans.Nr?   )SpanNkwargsc                       t  jdi | || _d S Nr   )super__init__r?   )r2   r?   rY   r<   r   r   r]         
zSyntaxNode.__init__startendr   c                 C   s   t ||| _d S r   )rX   r?   )r2   r`   ra   r   r   r   add_span      zSyntaxNode.add_spanr   )
r'   rR   rS   rT   r   r   r]   intrb   __classcell__r   r   r^   r   rW   }   s    rW   c                       s4   e Zd Zddeed df def fddZ  ZS )ResourceNbody	EntryTyperY   c                    s    t  jdi | |pg | _d S r[   )r\   r]   rg   )r2   rg   rY   r^   r   r   r]      s   zResource.__init__r   r'   rR   rS   r   r   r   r]   re   r   r   r^   r   rf      s    ,rf   c                   @      e Zd ZdZdS )Entryz<An abstract base class for useful elements of Resource.body.Nr'   rR   rS   rT   r   r   r   r   rk          rk   c                       sN   e Zd Z			dddded deed df ded	 d
ef
 fddZ  ZS )MessageNid
Identifierr   )PatternN
attributes	AttributecommentCommentNrY   c                    2   t  jdi | || _|| _|pg | _|| _d S r[   r\   r]   ro   r   rr   rt   r2   ro   r   rr   rt   rY   r^   r   r   r]      s
   

zMessage.__init__)NNNri   r   r   r^   r   rn      s    rn   c                       sH   e Zd Z		ddddddeed df ded	 d
ef
 fddZ  ZS )TermNro   rp   r   rq   rr   rs   rt   ru   rY   c                    rw   r[   rx   ry   r^   r   r   r]      s
   

zTerm.__init__NNri   r   r   r^   r   rz      s    rz   c                       s.   e Zd Zdeed  def fddZ  ZS )rq   elements)TextElement	PlaceablerY   c                    rZ   r[   )r\   r]   r|   )r2   r|   rY   r^   r   r   r]      r_   zPattern.__init__)r'   rR   rS   r   r   r   r]   re   r   r   r^   r   rq          &rq   c                   @   rj   )PatternElementz0An abstract base class for elements of Patterns.Nrl   r   r   r   r   r      rm   r   c                       &   e Zd Zdedef fddZ  ZS )r}   r   rY   c                    rZ   r[   r\   r]   r   r2   r   rY   r^   r   r   r]      r_   zTextElement.__init__r'   rR   rS   rU   r   r]   re   r   r   r^   r   r}          r}   c                       s*   e Zd Zded def fddZ  ZS )r~   
expression)InlineExpressionr~   SelectExpressionrY   c                    rZ   r[   )r\   r]   r   )r2   r   rY   r^   r   r   r]      s   
zPlaceable.__init__r'   rR   rS   r   r   r]   re   r   r   r^   r   r~      s    r~   c                   @   rj   )
Expressionz'An abstract base class for expressions.Nrl   r   r   r   r   r      rm   r   c                       s@   e Zd ZdZdedef fddZdeeef fddZ  Z	S )	Literalz$An abstract base class for literals.r   rY   c                    rZ   r[   r   r   r^   r   r   r]      r_   zLiteral.__init__r   c                 C   s
   d| j iS )Nr   r9   r>   r   r   r   parse   s   
zLiteral.parse)
r'   rR   rS   rT   rU   r   r]   r   r   re   r   r   r^   r   r      s    r   c                   @   s"   e Zd Zdeeef fddZdS )StringLiteralr   c                 C   s*   dt dtfdd}td|| j}d|iS )Nmatchobjr   c                 S   sF   |   \}}}|rtt|S t|p|d}|dksd|kr!t|S dS )N   i  i   u   �)groupsr   rU   rd   chr)r   c
codepoint4
codepoint6	codepointr   r   r   from_escape_sequence   s   
z1StringLiteral.parse.<locals>.from_escape_sequencez0\\(?:(\\|")|u([0-9a-fA-F]{4})|U([0-9a-fA-F]{6}))r   )r   rU   resubr   )r2   r   r   r   r   r   r      s   zStringLiteral.parseN)r'   rR   rS   r   rU   r   r   r   r   r   r      s    r   c                   @   s*   e Zd Zdeeeeef f fddZdS )NumberLiteralr   c                 C   s>   t | j}| jd}d}|dkrt| j| d }||dS )N.r      )r   	precision)floatr   findrD   )r2   r   decimal_positionr   r   r   r   r      s   
zNumberLiteral.parseN)	r'   rR   rS   r   rU   r   r   rd   r   r   r   r   r   r          "r   c                       s0   e Zd Zd	ddded def fddZ  ZS )
MessageReferenceNro   rp   	attributerp   NrY   c                    "   t  jdi | || _|| _d S r[   )r\   r]   ro   r   )r2   ro   r   rY   r^   r   r   r]         
zMessageReference.__init__r   r   r   r   r^   r   r          (r   c                	       s<   e Zd Z		dddded ded def fd	d
Z  ZS )TermReferenceNro   rp   r   r   	arguments)CallArgumentsNrY   c                    (   t  jdi | || _|| _|| _d S r[   )r\   r]   ro   r   r   )r2   ro   r   r   rY   r^   r   r   r]      s   
zTermReference.__init__r{   r   r   r   r^   r   r      s    r   c                       s&   e Zd Zdddef fddZ  ZS )VariableReferencero   rp   rY   c                    rZ   r[   )r\   r]   ro   )r2   ro   rY   r^   r   r   r]     r_   zVariableReference.__init__r'   rR   rS   r   r]   re   r   r   r^   r   r     r   r   c                       s*   e Zd Zdddddef fddZ  ZS )FunctionReferencero   rp   r   r   rY   c                    r   r[   )r\   r]   ro   r   )r2   ro   r   rY   r^   r   r   r]     r   zFunctionReference.__init__r   r   r   r^   r   r     r   r   c                       s.   e Zd Zddded def fddZ  ZS )r   selectorr   variantsVariantrY   c                    r   r[   )r\   r]   r   r   )r2   r   r   rY   r^   r   r   r]     r   zSelectExpression.__init__)r'   rR   rS   r   r   r]   re   r   r   r^   r   r     r   r   c                       sP   e Zd Z		d	deeedef  df deed df def fddZ  ZS )
r   N
positionalr   namedNamedArgumentrY   c                    s@   t  jdi | |d u rg n|| _|d u rg | _d S || _d S r[   )r\   r]   r   r   )r2   r   r   rY   r^   r   r   r]     s   zCallArguments.__init__r{   )	r'   rR   rS   r   r   r~   r   r]   re   r   r   r^   r   r     s    r   c                       s*   e Zd Zdddedef fddZ  ZS )rs   ro   rp   r   rY   c                    r   r[   )r\   r]   ro   r   )r2   ro   r   rY   r^   r   r   r]   &  r   zAttribute.__init__)r'   rR   rS   rq   r   r]   re   r   r   r^   r   rs   %  r   rs   c                	       s8   e Zd Zd	dedef dededef fddZ  Z	S )
r   FrH   rp   r   defaultrY   c                    r   r[   )r\   r]   rH   r   r   )r2   rH   r   r   rY   r^   r   r   r]   -  s   
zVariant.__init__)F)
r'   rR   rS   r   r   rq   r0   r   r]   re   r   r   r^   r   r   ,  s    0r   c                       s2   e Zd Zdddeeef def fddZ  ZS )r   r;   rp   r   rY   c                    r   r[   )r\   r]   r;   r   )r2   r;   r   rY   r^   r   r   r]   5  r   zNamedArgument.__init__)	r'   rR   rS   r   r   r   r   r]   re   r   r   r^   r   r   4  s    *r   c                       r   )rp   r;   rY   c                    rZ   r[   )r\   r]   r;   )r2   r;   rY   r^   r   r   r]   <  r_   zIdentifier.__init__r   r   r   r^   r   rp   ;  r   rp   c                       0   e Zd Zddeedf def fddZ  ZS )BaseCommentNcontentrY   c                    rZ   r[   )r\   r]   r   r2   r   rY   r^   r   r   r]   B  r_   zBaseComment.__init__r   r'   rR   rS   r   rU   r   r]   re   r   r   r^   r   r   A  r   r   c                       r   )rv   Nr   rY   c                       t  j|fi | d S r   r\   r]   r   r^   r   r   r]   H     zComment.__init__r   r   r   r   r^   r   rv   G  r   rv   c                       r   )GroupCommentNr   rY   c                    r   r   r   r   r^   r   r   r]   M  r   zGroupComment.__init__r   r   r   r   r^   r   r   L  r   r   c                       r   )ResourceCommentNr   rY   c                    r   r   r   r   r^   r   r   r]   R  r   zResourceComment.__init__r   r   r   r   r^   r   r   Q  r   r   c                       sN   e Zd Z		ddeedf deed df def fddZdd
dZ  Z	S )JunkNr   annotations
AnnotationrY   c                    s&   t  jdi | || _|pg | _d S r[   )r\   r]   r   r   )r2   r   r   rY   r^   r   r   r]   W  s   zJunk.__init__annotr   c                 C   s   | j | d S r   )r   append)r2   r   r   r   r   add_annotation_  rc   zJunk.add_annotationr{   )r   r   r   N)
r'   rR   rS   r   rU   r   r   r]   r   re   r   r   r^   r   r   V  s    
r   c                       s*   e Zd Zdededef fddZ  ZS )rX   r`   ra   rY   c                    r   r[   )r\   r]   r`   ra   )r2   r`   ra   rY   r^   r   r   r]   d  r   zSpan.__init__)r'   rR   rS   rd   r   r]   re   r   r   r^   r   rX   c  r   rX   c                	       sH   e Zd Z		ddedeee df deedf def fddZ  ZS )	r   Ncoder   messagerY   c                    s,   t  jdi | || _|pg | _|| _d S r[   )r\   r]   r   r   r   )r2   r   r   r   rY   r^   r   r   r]   k  s   

zAnnotation.__init__r{   )	r'   rR   rS   rU   r   r   r   r]   re   r   r   r^   r   r   j  s    
r   r   )3r   r%   rO   typingr   r   r   r   r   r   r   r	   rU   rV   r   r   r0   r1   r
   rW   rf   rk   rn   rz   rq   r   r}   r~   r   r   r   r   r   r   r   r   r   r   rs   r   r   rp   r   rv   r   r   r   rX   r   rh   r   r   r   r   r   <module>   sX    $ M


