
    -Ph#                    |    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                      ZdS )zProvides helpers for building AST

This is meant to make building Meson AST from foreign (largely declarative)
build descriptions easier.
    )annotationsN   )mparserc                      e Zd ZU ded<   dHdZdIdZdJdZdKdZdLdZdMdZ	dNdZ
dOdZdPdZ	 	 dQdRd(Z	 	 dQdSd*ZdTd.ZdTd/ZdTd0ZdTd1ZdUd3ZdVd5ZdWd7ZdXd:ZdYd<ZdZd>Zd[dBZd\dGZd S )]Builderstrfilenametidvaluemparser.TV_TokenTypesreturn$mparser.Token[mparser.TV_TokenTypes]c           	     @    t          j        || 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   s      X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mesonbuild/cargo/builder.py_tokenzBuilder._token   s"     }S$-RXuMMM    valmparser.SymbolNodec                R    t          j        |                     d|                    S )N )r   
SymbolNoder   )r   r   s     r   _symbolzBuilder._symbol#   s!    !$++b#"6"6777r   mparser.BaseNodevarnamemparser.AssignmentNodec                z    t          j        |                     |          |                     d          |          S )N=)r   AssignmentNode
identifierr   r   r   r   s      r   assignzBuilder.assign&   s0    %doog&>&>S@Q@QSXYYYr   mparser.StringNodec                R    t          j        |                     d|                    S )zhBuild A StringNode

        :param value: the value of the string
        :return: A StringNode
        string)r   
StringNoder   r   r   s     r   r'   zBuilder.string)   s#     !$++h">">???r   intmparser.NumberNodec                l    t          j        |                     dt          |                              S )zhBuild A NumberNode

        :param value: the value of the number
        :return: A NumberNode
        number)r   
NumberNoder   r   r)   s     r   r-   zBuilder.number1   s)     !$++hE

"C"CDDDr   builtins.boolmparser.BooleanNodec                R    t          j        |                     d|                    S )zkBuild A BooleanNode

        :param value: the value of the boolean
        :return: A BooleanNode
        bool)r   BooleanNoder   r)   s     r   r2   zBuilder.bool9   s#     "4;;vu#=#=>>>r   T.List[mparser.BaseNode]mparser.ArrayNodec                    t          j        |                     dd                    }||_        t          j        |                     d          ||                     d                    S )zBuild 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   	arguments	ArrayNoder   )r   r   argss      r   r7   zBuilder.arrayA   sV     #DKK$B$BCC c!2!2D$,,s:K:KLLLr   *T.Dict[mparser.BaseNode, mparser.BaseNode]mparser.DictNodec                *   t          j        |                     dd                    }|                                D ]\  }}|                    ||           t          j        |                     d          ||                     d                    S )zBuild an Dictionary Node

        :param value: A dict of nodes to insert into the dictionary
        :return: An DictNode built from the arguments
        dictr8   {})r   r;   r   itemsset_kwarg_no_checkDictNoder   )r   r   r>   keyr   s        r   rB   zBuilder.dictK   s     #DKK$A$ABB 	. 	.HC##C----S 1 14c9J9JKKKr   mparser.IdNodec                R    t          j        |                     d|                    S )zfBuild A IdNode

        :param value: the value of the boolean
        :return: A BooleanNode
        id)r   IdNoder   r)   s     r   r"   zBuilder.identifierV   s"     ~dkk$66777r   Nnameid_pos$T.Optional[T.List[mparser.BaseNode]]kw,T.Optional[T.Mapping[str, mparser.BaseNode]]mparser.MethodNodec           
     ~    t          j                             dd                    }|||_        |% fd|                                D             |_        t          j        |                     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
        r7   r8   Nc                B    i | ]\  }}                     |          |S  r"   .0kvr   s      r   
<dictcomp>z"Builder.method.<locals>.<dictcomp>n   +    HHHTQ4??1--qHHHr   .())	r   r;   r   r<   rE   kwargs
MethodNoder   r"   )r   rM   rN   rO   rQ   r>   s   `     r   methodzBuilder.method^   s     #DKK$B$BCC? DN>HHHHRXXZZHHHDK!#t||C'8'8$//$:O:OQUQ]Q]^aQbQbdhjnjvjvwzj{j{|||r   mparser.FunctionNodec                T    t          j                             dd                    }|||_        |% fd|                                D             |_        t          j                             |                               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
        r7   r8   Nc                B    i | ]\  }}                     |          |S rV   rW   rX   s      r   r\   z$Builder.function.<locals>.<dictcomp>   r]   r   r_   r`   )	r   r;   r   r<   rE   ra   FunctionNoder"   r   )r   rM   rO   rQ   r>   s   `    r   functionzBuilder.functionq   s     #DKK$B$BCC? DN>HHHHRXXZZHHHDK#DOOD$9$94<<;L;LdTXT`T`adTeTefffr   lhsrhsmparser.ComparisonNodec                V    t          j        d||                     d          |          S )zCreate an equality operation

        :param lhs: The left hand side of the equal
        :param rhs: the right hand side of the equal
        :return: A comparison node
        z==r   ComparisonNoder   r   ri   rj   s      r   equalzBuilder.equal   '     %dCd1C1CSIIIr   c                V    t          j        d||                     d          |          S )zCreate an inequality operation

        :param lhs: The left hand side of the "!="
        :param rhs: the right hand side of the "!="
        :return: A comparison node
        z!=rm   ro   s      r   	not_equalzBuilder.not_equal   rq   r   c                V    t          j        d||                     d          |          S )zCreate an "in" operation

        :param lhs: The left hand side of the "in"
        :param rhs: the right hand side of the "in"
        :return: A comparison node
        inrm   ro   s      r   in_zBuilder.in_   rq   r   c                V    t          j        d||                     d          |          S )zCreate an "not in" operation

        :param lhs: The left hand side of the "not in"
        :param rhs: the right hand side of the "not in"
        :return: A comparison node
        notinznot inrm   ro   s      r   not_inzBuilder.not_in   s'     %gsDLL4J4JCPPPr   mparser.OrNodec                T    t          j        ||                     d          |          S )zCreate and OrNode

        :param lhs: The Left of the Node
        :param rhs: The Right of the Node
        :return: The OrNode
        or)r   OrNoder   ro   s      r   or_zBuilder.or_   s$     ~c4<<#5#5s;;;r   mparser.AndNodec                T    t          j        ||                     d          |          S )zCreate an AndNode

        :param lhs: The left of the And
        :param rhs: The right of the And
        :return: The AndNode
        and)r   AndNoder   ro   s      r   and_zBuilder.and_   s$     sDLL$7$7===r   mparser.NotNodec                |    t          j        |                     dd          |                     d          |          S )zbCreate a not node

        :param value: The value to negate
        :return: The NotNode
        notr   )r   NotNoder   r   r)   s     r   not_zBuilder.not_   s2     t{{5"55t||E7J7JERRRr   linesmparser.CodeBlockNodec                d    t          j        |                     dd                    }||_        |S )Nnoder   )r   CodeBlockNoder   r   )r   r   blocks      r   r   zBuilder.block   s,    %dkk&"&=&=>>r   mparser.ArithmeticNodec                V    t          j        d||                     d          |          S )zCreate an addition node

        :param lhs: The left of the addition
        :param rhs: The right of the addition
        :return: The ArithmeticNode
        add+)r   ArithmeticNoder   ro   s      r   pluszBuilder.plus   s'     %eS$,,s2C2CSIIIr   mparser.PlusAssignmentNodec                z    t          j        |                     |          |                     d          |          S )zCreate a "+=" node

        :param value: The value to add
        :param varname: The variable to assign
        :return: The PlusAssignmentNode
        z+=)r   PlusAssignmentNoder"   r   r#   s      r   
plusassignzBuilder.plusassign   s3     )$//'*B*BDLLQUDVDVX]^^^r   	conditionr   mparser.IfClauseNodec                    t          j        |          }|j                            t          j        ||                     d          ||                     t          j        dd| j                  |_        |S )zCreate a "if" block

        :param condition: The condition
        :param block: Lines inside the condition
        :return: The IfClauseNode
        ifr   )	r   IfClauseNodeifsappendIfNoder   	EmptyNoder	   	elseblock)r   r   r   clauses       r   if_zBuilder.if_   se     %i00
'.d1C1CYPUVVWWW",RT]CCr   varnamesT.List[str]rE   mparser.ForeachClauseNodec                     fd|D             } fdt          t          |          dz
            D             }t          j                             d          ||                     d          ||                     d                    S )zCreate a "foreach" loop

        :param varnames: Iterator variable names (one for list, two for dict).
        :param items: The list of dict to iterate
        :param block: Lines inside the loop
        :return: The ForeachClauseNode
        c                :    g | ]}                     |          S rV   rW   rY   ir   s     r   
<listcomp>z#Builder.foreach.<locals>.<listcomp>   s%    777$//!$$777r   c                :    g | ]}                     d           S ),)r   r   s     r   r   z#Builder.foreach.<locals>.<listcomp>   s%    FFF$,,s##FFFr      foreach:
endforeach)rangelenr   ForeachClauseNoder   )r   r   rE   r   varidscommass   `     r   r   zBuilder.foreach   s     8777h777FFFFU3x==13D-E-EFFF(i)@)@&&RVR^R^_bRcRcejlqswss  AM  tN  tN  O  O  	O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   r0   )r   r4   r   r5   )r   r?   r   r@   )r   r   r   rI   )NN)
rM   r   rN   r   rO   rP   rQ   rR   r   rS   )rM   r   rO   rP   rQ   rR   r   rd   )ri   r   rj   r   r   rk   )ri   r   rj   r   r   rz   )ri   r   rj   r   r   r   )r   r   r   r   )r   r4   r   r   )ri   r   rj   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   rE   r   r   r   r   r   )__name__
__module____qualname____annotations__r   r   r$   r'   r-   r2   r7   rB   r"   rc   rh   rp   rs   rv   ry   r~   r   r   r   r   r   r   r   rV   r   r   r   r      sM         MMMN N N N8 8 8 8Z Z Z Z@ @ @ @E E E E? ? ? ?M M M M	L 	L 	L 	L8 8 8 8 <@BF} } } } }( >BDHg g g g g$J J J JJ J J JJ J J JQ Q Q Q< < < <> > > >S S S S   
J J J J_ _ _ _
 
 
 

O 
O 
O 
O 
O 
Or   r   )__doc__
__future__r   dataclassestypingTr   r   TYPE_CHECKINGbuiltins	dataclassr   rV   r   r   <module>r      s     # " " " " "              ? OOO YO YO YO YO YO YO YO YO YO YOr   