U
    Zf13                     @   sx  d dl mZ d dl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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dS )/    )OrderedDictNc                   @   s   e Zd Zdd ZdS )ASTNodec                 C   s   || _ || _|| _dS )z
        Args:
            lineno (int): The line number where the start of this element
                occurs.
            lexpos (int): The character offset into the file where this element
                occurs.
        N)pathlinenolexpos)selfr   r   r    r   6/tmp/pip-unpacked-wheel-vqb3mfeu/stone/frontend/ast.py__init__   s    zASTNode.__init__N)__name__
__module____qualname__r
   r   r   r   r	   r      s   r   c                       s,   e Zd Z fddZdd Zdd Z  ZS )AstNamespacec                    s$   t t| ||| || _|| _dS )z
        Args:
            name (str): The namespace of the spec.
            doc (Optional[str]): The docstring for this namespace.
        N)superr   r
   namedoc)r   r   r   r   r   r   	__class__r   r	   r
      s    zAstNamespace.__init__c                 C   s   |   S N__repr__r   r   r   r	   __str__    s    zAstNamespace.__str__c                 C   s   d | jS )NzAstNamespace({!r}))formatr   r   r   r   r	   r   #   s    zAstNamespace.__repr__r   r   r   r
   r   r   __classcell__r   r   r   r	   r      s   
r   c                       s,   e Zd Z fddZdd Zdd Z  ZS )	AstImportc                    s   t t| ||| || _dS )zV
        Args:
            target (str): The name of the namespace to import.
        N)r   r   r
   target)r   r   r   r   r   r   r   r	   r
   )   s    zAstImport.__init__c                 C   s   |   S r   r   r   r   r   r	   r   1   s    zAstImport.__str__c                 C   s   d | jS )NzAstImport({!r}))r   r   r   r   r   r	   r   4   s    zAstImport.__repr__r   r   r   r   r	   r   '   s   r   c                       s,   e Zd Z fddZdd Zdd Z  ZS )AstAliasc                    s0   t t| ||| || _|| _|| _g | _dS )z
        Args:
            name (str): The name of the alias.
            type_ref (AstTypeRef): The data type of the field.
            doc (Optional[str]): Documentation string for the alias.
        N)r   r   r
   r   type_refr   annotations)r   r   r   r   r   r   r   r   r   r	   r
   9   s
    zAstAlias.__init__c                 C   s
   || _ d S r   r    r   r    r   r   r	   set_annotationsF   s    zAstAlias.set_annotationsc                 C   s   d | j| jS )NzAstAlias({!r}, {!r})r   r   r   r   r   r   r	   r   I   s    zAstAlias.__repr__)r   r   r   r
   r#   r   r   r   r   r   r	   r   7   s   r   c                       s,   e Zd Z fddZdd Zdd Z  ZS )
AstTypeDefc	           	         s   t t| ||| || _t|ttdfs8tt||| _t|t	j
tdfsVt|| _t|tsjt|| _t|ttdfstt||| _dS )a  
        Args:
            name (str): Name assigned to the type.
            extends (Optional[str]); Name of the type this inherits from.
            doc (Optional[str]): Docstring for the type.
            fields (List[AstField]): Fields of a type, not including
                inherited ones.
            examples (Optional[OrderedDict[str, AstExample]]): Map from label
                to example.
        N)r   r%   r
   r   
isinstance
AstTypeReftypeAssertionErrorextendssix	text_typer   listfieldsr   examples)	r   r   r   r   r   r*   r   r.   r/   r   r   r	   r
   N   s    zAstTypeDef.__init__c                 C   s   |   S r   r   r   r   r   r	   r   f   s    zAstTypeDef.__str__c                 C   s   d | j| j| jS )NzAstTypeDef({!r}, {!r}, {!r})r   r   r*   r.   r   r   r   r	   r   i   s
    zAstTypeDef.__repr__r   r   r   r   r	   r%   L   s   r%   c                       s&   e Zd Zd fdd	Zdd Z  ZS )AstStructDefNc
           
   
      sF   t t| |||||||| t|	ttdfs<tt|	|	| _dS )z
        Args:
            subtypes (Tuple[List[AstSubtypeField], bool]): Inner list
                enumerates subtypes. The bool indicates whether this struct
                is a catch-all.

        See AstTypeDef for other constructor args.
        N)r   r1   r
   r&   tupler(   r)   subtypes)
r   r   r   r   r   r*   r   r.   r/   r3   r   r   r	   r
   r   s    
       zAstStructDef.__init__c                 C   s   d | j| j| jS )NzAstStructDef({!r}, {!r}, {!r})r0   r   r   r   r	   r      s
    zAstStructDef.__repr__)Nr   r   r   r
   r   r   r   r   r   r	   r1   p   s    r1   c                       s$   e Zd Z fddZdd Z  ZS )AstStructPatchc                    sV   t t| ||| || _t|ts(t|| _t|tt	d fsLtt	||| _
d S r   )r   r5   r
   r   r&   r-   r)   r.   r   r(   r/   )r   r   r   r   r   r.   r/   r   r   r	   r
      s    zAstStructPatch.__init__c                 C   s   d | j| jS )NzAstStructPatch({!r}, {!r}))r   r   r.   r   r   r   r	   r      s    zAstStructPatch.__repr__r4   r   r   r   r	   r5      s   	r5   c                       s&   e Zd Zd fdd	Zdd Z  ZS )AstUnionDefFc
           
   
      s(   t t| |||||||| |	| _dS )z
        Args:
            closed (bool): Set if this is a closed union.

        See AstTypeDef for other constructor args.
        N)r   r6   r
   closed)
r   r   r   r   r   r*   r   r.   r/   r7   r   r   r	   r
      s    
       zAstUnionDef.__init__c                 C   s   d | j| j| j| jS )Nz#AstUnionDef({!r}, {!r}, {!r}, {!r}))r   r   r*   r.   r7   r   r   r   r	   r      s    zAstUnionDef.__repr__)Fr4   r   r   r   r	   r6      s    r6   c                       s$   e Zd Z fddZdd Z  ZS )AstUnionPatchc                    s\   t t| ||| || _t|ts(t|| _t|tt	d fsLtt	||| _
|| _d S r   )r   r8   r
   r   r&   r-   r)   r.   r   r(   r/   r7   )r   r   r   r   r   r.   r/   r7   r   r   r	   r
      s    zAstUnionPatch.__init__c                 C   s   d | j| j| jS )NzAstUnionPatch({!r}, {!r}, {!r}))r   r   r.   r7   r   r   r   r	   r      s
    zAstUnionPatch.__repr__r4   r   r   r   r	   r8      s   
r8   c                       s$   e Zd Z fddZdd Z  ZS )r'   c                    s0   t t| ||| || _|| _|| _|| _dS )aY  
        Args:
            name (str): Name of the referenced type.
            args (tuple[list, dict]): Arguments to type.
            nullable (bool): Whether the type is nullable (can be null)
            ns (Optional[str]): Namespace that referred type is a member of.
                If none, then refers to the current namespace.
        N)r   r'   r
   r   argsnullablens)r   r   r   r   r   r9   r:   r;   r   r   r	   r
      s
    	zAstTypeRef.__init__c                 C   s   d | j| j| j| jS )Nz"AstTypeRef({!r}, {!r}, {!r}, {!r}))r   r   r9   r:   r;   r   r   r   r	   r      s    zAstTypeRef.__repr__r4   r   r   r   r	   r'      s   r'   c                       s$   e Zd Z fddZdd Z  ZS )	AstTagRefc                    s   t t| ||| || _dS )zK
        Args:
            tag (str): Name of the referenced type.
        N)r   r<   r
   tag)r   r   r   r   r=   r   r   r	   r
      s    zAstTagRef.__init__c                 C   s   d | jS )NzAstTagRef({!r}))r   r=   r   r   r   r	   r      s    zAstTagRef.__repr__r4   r   r   r   r	   r<      s   r<   c                       s$   e Zd Z fddZdd Z  ZS )AstAnnotationRefc                    s$   t t| ||| || _|| _dS )zX
        Args:
            annotation (str): Name of the referenced annotation.
        N)r   r>   r
   
annotationr;   )r   r   r   r   r?   r;   r   r   r	   r
      s    zAstAnnotationRef.__init__c                 C   s   d | j| jS )NzAstAnnotationRef({!r}, {!r}))r   r?   r;   r   r   r   r	   r      s     zAstAnnotationRef.__repr__r4   r   r   r   r	   r>      s   	r>   c                       s$   e Zd Z fddZdd Z  ZS )AstAnnotationDefc	           	         s6   t t| ||| || _|| _|| _|| _|| _dS )a  
        Args:
            name (str): Name of the defined annotation.
            annotation_type (str): Type of annotation to define.
            annotation_type_ns (Optional[str]): Namespace where the annotation
              type was defined. If None, current namespace or builtin.
            args (str): Arguments to define annotation.
            kwargs (str): Keyword Arguments to define annotation.
        N)r   r@   r
   r   annotation_typeannotation_type_nsr9   kwargs)	r   r   r   r   r   rA   rB   r9   rC   r   r   r	   r
      s    zAstAnnotationDef.__init__c                 C   s   d | j| j| j| j| jS )Nz.AstAnnotationDef({!r}, {!r}, {!r}, {!r}, {!r}))r   r   rA   rB   r9   rC   r   r   r   r	   r     s    zAstAnnotationDef.__repr__r4   r   r   r   r	   r@      s   r@   c                       s$   e Zd Z fddZdd Z  ZS )AstAnnotationTypeDefc                    s*   t t| ||| || _|| _|| _dS )a  
        Args:
            name (str): Name of the defined annotation type.
            doc (str): Docstring for the defined annotation type.
            params (List[AstField]): Parameters that can be passed to the
                annotation type.
        N)r   rD   r
   r   r   params)r   r   r   r   r   r   rE   r   r   r	   r
     s    zAstAnnotationTypeDef.__init__c                 C   s   d | j| j| jS )Nz&AstAnnotationTypeDef({!r}, {!r}, {!r}))r   r   r   rE   r   r   r   r	   r   '  s
    zAstAnnotationTypeDef.__repr__r4   r   r   r   r	   rD     s   rD   c                       s@   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Z  Z	S )AstFieldz
    Represents both a field of a struct and a field of a union.
    TODO(kelkabany): Split this into two different classes.
    c                    s<   t t| ||| || _|| _d| _d| _d| _g | _dS )z
        Args:
            name (str): The name of the field.
            type_ref (AstTypeRef): The data type of the field.
        NF)	r   rF   r
   r   r   r   has_defaultdefaultr    r   r   r   r   r   r   r   r   r	   r
   4  s    zAstField.__init__c                 C   s
   || _ d S r   r   r   Z	docstringr   r   r	   set_docB  s    zAstField.set_docc                 C   s   d| _ || _d S )NT)rG   rH   )r   rH   r   r   r	   set_defaultE  s    zAstField.set_defaultc                 C   s
   || _ d S r   r!   r"   r   r   r	   r#   I  s    zAstField.set_annotationsc                 C   s   d | j| j| jS )NzAstField({!r}, {!r}, {!r}))r   r   r   r    r   r   r   r	   r   L  s
    zAstField.__repr__)
r   r   r   __doc__r
   rL   rM   r#   r   r   r   r   r   r	   rF   .  s   rF   c                       s<   e Zd Z fddZdd Zdd Zdd Zd	d
 Z  ZS )AstVoidFieldc                    s*   t t| ||| || _d | _g | _d S r   )r   rO   r
   r   r   r    )r   r   r   r   r   r   r   r	   r
   U  s    zAstVoidField.__init__c                 C   s
   || _ d S r   rJ   rK   r   r   r	   rL   [  s    zAstVoidField.set_docc                 C   s
   || _ d S r   r!   r"   r   r   r	   r#   ^  s    zAstVoidField.set_annotationsc                 C   s   |   S r   r   r   r   r   r	   r   a  s    zAstVoidField.__str__c                 C   s   d | j| jS )NzAstVoidField({!r}, {!r}))r   r   r    r   r   r   r	   r   d  s    zAstVoidField.__repr__)	r   r   r   r
   rL   r#   r   r   r   r   r   r   r	   rO   S  s
   rO   c                       s$   e Zd Z fddZdd Z  ZS )AstSubtypeFieldc                    s$   t t| ||| || _|| _d S r   )r   rP   r
   r   r   rI   r   r   r	   r
   l  s    zAstSubtypeField.__init__c                 C   s   d | j| jS )NzAstSubtypeField({!r}, {!r})r$   r   r   r   r	   r   q  s    zAstSubtypeField.__repr__r4   r   r   r   r	   rP   j  s   rP   c                       s.   e Zd Zd fdd	Zdd Zdd Z  ZS )	AstRouteDefNc
           
         sH   t t| ||| || _|| _|| _|| _|| _|	| _d | _	i | _
d S r   )r   rQ   r
   r   version
deprecatedarg_type_refresult_type_referror_type_refr   attrs)
r   r   r   r   r   rR   rS   rT   rU   rV   r   r   r	   r
   y  s    zAstRouteDef.__init__c                 C   s
   || _ d S r   rJ   rK   r   r   r	   rL     s    zAstRouteDef.set_docc                 C   s
   || _ d S r   )rW   )r   rW   r   r   r	   	set_attrs  s    zAstRouteDef.set_attrs)N)r   r   r   r
   rL   rX   r   r   r   r   r	   rQ   w  s    rQ   c                       s$   e Zd Z fddZdd Z  ZS )AstAttrFieldc                    s$   t t| ||| || _|| _d S r   )r   rY   r
   r   valuer   r   r   r   r   rZ   r   r   r	   r
     s    zAstAttrField.__init__c                 C   s   d | j| jS )NzAstAttrField({!r}, {!r})r   r   rZ   r   r   r   r	   r     s    zAstAttrField.__repr__r4   r   r   r   r	   rY     s   rY   c                       s$   e Zd Z fddZdd Z  ZS )
AstExamplec                    s*   t t| ||| || _|| _|| _d S r   )r   r]   r
   labeltextr.   )r   r   r   r   r^   r_   r.   r   r   r	   r
     s    zAstExample.__init__c                 C   s   d | j| j| jS )NzAstExample({!r}, {!r}, {!r}))r   r^   r_   r.   r   r   r   r	   r     s
    zAstExample.__repr__r4   r   r   r   r	   r]     s   r]   c                       s$   e Zd Z fddZdd Z  ZS )AstExampleFieldc                    s$   t t| ||| || _|| _d S r   )r   r`   r
   r   rZ   r[   r   r   r	   r
     s    zAstExampleField.__init__c                 C   s   d | j| jS )NzAstExampleField({!r}, {!r})r\   r   r   r   r	   r     s    zAstExampleField.__repr__r4   r   r   r   r	   r`     s   r`   c                       s$   e Zd Z fddZdd Z  ZS )AstExampleRefc                    s   t t| ||| || _d S r   )r   ra   r
   r^   )r   r   r   r   r^   r   r   r	   r
     s    zAstExampleRef.__init__c                 C   s   d | jS )NzAstExampleRef({!r}))r   r^   r   r   r   r	   r     s    zAstExampleRef.__repr__r4   r   r   r   r	   ra     s   ra   )collectionsr   r+   objectr   r   r   r   r%   r1   r5   r6   r8   r'   r<   r>   r@   rD   rF   rO   rP   rQ   rY   r]   r`   ra   r   r   r   r	   <module>   s.   $%