o
    Ž:e>  ã                   @  sR   d Z ddlmZ ddlZddlZddlmZ ejrddl	Z	ej
G dd„ dƒƒZdS )zŠProvides helpers for building AST

This is meant to make building Meson AST from foreign (largely declarative)
build descriptions easier.
é    )ÚannotationsNé   )Úmparserc                   @  sÂ   e Zd ZU ded< dHdd	„ZdIdd„ZdJdd„ZdKdd„ZdLdd„ZdMdd„Z	dNd d!„Z
dOd$d%„ZdPd'd(„Z	)	)dQdRd1d2„Z	)	)dQdSd4d5„ZdTd9d:„ZdUd<d=„ZdVd?d@„ZdWdBdC„ZdXdFdG„Zd)S )YÚBuilderÚstrÚfilenameÚtidÚvalueúmparser.TV_TokenTypesÚreturnú$mparser.Token[mparser.TV_TokenTypes]c              	   C  s   t  || jdddd|¡S )a  Create a Token object, but with the line numbers stubbed out.

        :param tid: the token id (such as string, number, etc)
        :param filename: the filename that the token was generated from
        :param value: the value of the token
        :return: A Token object
        éÿÿÿÿ)r   r   )r   ÚTokenr   )Úselfr   r	   © r   ú=/usr/lib/python3.10/site-packages/mesonbuild/cargo/builder.pyÚ_token   s   zBuilder._tokenÚvalúmparser.SymbolNodec                 C  ó   t  |  d|¡¡S )NÚ )r   Z
SymbolNoder   )r   r   r   r   r   Ú_symbol#   s   zBuilder._symbolúmparser.BaseNodeÚvarnameúmparser.AssignmentNodec                 C  s   t  |  |¡|  d¡|¡S )Nú=)r   ZAssignmentNodeÚ
identifierr   )r   r	   r   r   r   r   Úassign&   s   zBuilder.assignúmparser.StringNodec                 C  r   )zhBuild A StringNode

        :param value: the value of the string
        :return: A StringNode
        Ústring)r   Z
StringNoder   ©r   r	   r   r   r   r   )   ó   zBuilder.stringÚintúmparser.NumberNodec                 C  s   t  |  dt|ƒ¡¡S )zhBuild A NumberNode

        :param value: the value of the number
        :return: A NumberNode
        Únumber)r   Z
NumberNoder   r   r    r   r   r   r$   1   s   zBuilder.numberúbuiltins.boolúmparser.BooleanNodec                 C  r   )zkBuild A BooleanNode

        :param value: the value of the boolean
        :return: A BooleanNode
        Úbool)r   ZBooleanNoder   r    r   r   r   r'   9   r!   zBuilder.boolúT.List[mparser.BaseNode]úmparser.ArrayNodec                 C  s2   t  |  dd¡¡}||_t  |  d¡||  d¡¡S )z“Build an Array Node

        :param value: A list of nodes to insert into the array
        :return: An ArrayNode built from the arguments
        ÚarrayÚunusedú[ú])r   ÚArgumentNoder   Ú	argumentsZ	ArrayNoder   )r   r	   Úargsr   r   r   r*   A   s   zBuilder.arrayú*T.Dict[mparser.BaseNode, mparser.BaseNode]úmparser.DictNodec                 C  sJ   t  |  dd¡¡}| ¡ D ]
\}}| ||¡ qt  |  d¡||  d¡¡S )zœBuild an Dictionary Node

        :param value: A dict of nodes to insert into the dictionary
        :return: An DictNode built from the arguments
        Údictr+   Ú{Ú})r   r.   r   ÚitemsZset_kwarg_no_checkZDictNoder   )r   r	   r0   Úkeyr   r   r   r   r3   K   s   zBuilder.dictúmparser.IdNodec                 C  r   )zfBuild A IdNode

        :param value: the value of the boolean
        :return: A BooleanNode
        Úid)r   ZIdNoder   r    r   r   r   r   V   r!   zBuilder.identifierNÚnameÚid_Úposú$T.Optional[T.List[mparser.BaseNode]]Úkwú,T.Optional[T.Mapping[str, mparser.BaseNode]]úmparser.MethodNodec              
     sl   t  ˆ  dd¡¡}|dur||_|dur ‡ fdd„| ¡ D ƒ|_t  |ˆ  d¡ˆ  |¡ˆ  d¡|ˆ  d¡¡S )	a2  Create a method call.

        :param name: the name of the method
        :param id_: the object to call the method of
        :param pos: a list of positional arguments, defaults to None
        :param kw: a dictionary of keyword arguments, defaults to None
        :return: a method call object
        r*   r+   Nc                   ó   i | ]
\}}ˆ   |¡|“qS r   ©r   ©Ú.0ÚkÚv©r   r   r   Ú
<dictcomp>n   ó    z"Builder.method.<locals>.<dictcomp>Ú.ú(ú))	r   r.   r   r/   r6   ÚkwargsZ
MethodNoder   r   )r   r:   r;   r<   r>   r0   r   rG   r   Úmethod^   s   ,zBuilder.methodúmparser.FunctionNodec                   sb   t  ˆ  dd¡¡}|dur||_|dur ‡ fdd„| ¡ D ƒ|_t  ˆ  |¡ˆ  d¡|ˆ  d¡¡S )a  Create a function call.

        :param name: the name of the function
        :param pos: a list of positional arguments, defaults to None
        :param kw: a dictionary of keyword arguments, defaults to None
        :return: a method call object
        r*   r+   Nc                   rA   r   rB   rC   rG   r   r   rH   €   rI   z$Builder.function.<locals>.<dictcomp>rK   rL   )	r   r.   r   r/   r6   rM   ZFunctionNoder   r   )r   r:   r<   r>   r0   r   rG   r   Úfunctionq   s   "zBuilder.functionÚlhsÚrhsúmparser.ComparisonNodec                 C  s   t  d||  d¡|¡S )z²Create an equality operation

        :param lhs: The left hand side of the equal
        :param rhs: the right hand side of the equal
        :return: A compraison node
        z==)r   ZComparisonNoder   ©r   rQ   rR   r   r   r   Úequalƒ   s   zBuilder.equalúmparser.OrNodec                 C  ó   t  ||  d¡|¡S )zŠCreate and OrNode

        :param lhs: The Left of the Node
        :param rhs: The Right of the Node
        :return: The OrNode
        Úor)r   ZOrNoder   rT   r   r   r   Úor_Œ   ó   zBuilder.or_úmparser.AndNodec                 C  rW   )z‰Create an AndNode

        :param lhs: The left of the And
        :param rhs: The right of the And
        :return: The AndNode
        Úand)r   ZAndNoder   rT   r   r   r   Úand_•   rZ   zBuilder.and_úmparser.NotNodec                 C  s   t  |  dd¡|  d¡|¡S )zbCreate a not node

        :param value: The value to negate
        :return: The NotNode
        Únotr   )r   ZNotNoder   r   r    r   r   r   Únot_ž   s   zBuilder.not_Úlinesúmparser.CodeBlockNodec                 C  s   t  |  dd¡¡}||_|S )NÚnoder   )r   ZCodeBlockNoder   ra   )r   ra   Úblockr   r   r   rd   ¦   s   zBuilder.block)r   r   r	   r
   r   r   )r   r   r   r   )r	   r   r   r   r   r   )r	   r   r   r   )r	   r"   r   r#   )r	   r%   r   r&   )r	   r(   r   r)   )r	   r1   r   r2   )r	   r   r   r8   )NN)
r:   r   r;   r8   r<   r=   r>   r?   r   r@   )r:   r   r<   r=   r>   r?   r   rO   )rQ   r   rR   r   r   rS   )rQ   r   rR   r   r   rV   )rQ   r   rR   r   r   r[   )r	   r   r   r^   )ra   r(   r   rb   )Ú__name__Ú
__module__Ú__qualname__Ú__annotations__r   r   r   r   r$   r'   r*   r3   r   rN   rP   rU   rY   r]   r`   rd   r   r   r   r   r      s,   
 










	þþ

	
	
	r   )Ú__doc__Ú
__future__r   ÚdataclassesÚtypingÚTr   r   ÚTYPE_CHECKINGÚbuiltinsÚ	dataclassr   r   r   r   r   Ú<module>   s   