
    <h#                        S r SSKJr  SSKrSSKrSSKJr  \R                  (       a  SSK	r	\R                   " S S5      5       rg)zProvides helpers for building AST

This is meant to make building Meson AST from foreign (largely declarative)
build descriptions easier.
    )annotationsN   )mparserc                  *   \ rS rSr% S\S'   SS jrSS jrSS jrS S jrS!S jr	S"S	 jr
S#S
 jrS$S jrS%S jr  S&     S'S jjr  S&     S(S jjrS)S jrS)S jrS)S jrS)S jrS*S jrS+S jrS,S jrS-S jrS.S jrS/S jrS0S jrS1S jrSrg)2Builder   strfilenamec           	     L    [         R                  " XR                  SSSSU5      $ )zCreate 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
   )selftidvalues      y/mnt/mint/home/seanl/mnt/public/Repos/ladybird/Build/vcpkg/downloads/tools/meson-1.9.0-d1fcc2/mesonbuild/cargo/builder.py_tokenBuilder._token   s!     }}S--RXuMM    c                N    [         R                  " U R                  SU5      5      $ )N )r   
SymbolNoder   )r   vals     r   _symbolBuilder._symbol#   s    !!$++b#"677r   c                n    [         R                  " U R                  U5      U R                  S5      U5      $ )N=)r   AssignmentNode
identifierr   r   r   varnames      r   assignBuilder.assign&   s*    %%doog&>S@QSXYYr   c                N    [         R                  " U R                  SU5      5      $ )zPBuild A StringNode

:param value: the value of the string
:return: A StringNode
string)r   
StringNoder   r   r   s     r   r$   Builder.string)   s      !!$++h">??r   c                `    [         R                  " U R                  S[        U5      5      5      $ )zPBuild A NumberNode

:param value: the value of the number
:return: A NumberNode
number)r   
NumberNoder   r	   r&   s     r   r)   Builder.number1   s$     !!$++hE
"CDDr   c                N    [         R                  " U R                  SU5      5      $ )zSBuild A BooleanNode

:param value: the value of the boolean
:return: A BooleanNode
bool)r   BooleanNoder   r&   s     r   r-   Builder.bool9   s      ""4;;vu#=>>r   c                    [         R                  " U R                  SS5      5      nXl        [         R                  " U R                  S5      X R                  S5      5      $ )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   	arguments	ArrayNoder   )r   r   argss      r   r1   Builder.arrayA   sI     ##DKK$BC  c!2D,,s:KLLr   c                   [         R                  " U R                  SS5      5      nUR                  5        H  u  p4UR	                  X45        M     [         R
                  " U R                  S5      X R                  S5      5      $ )zBuild an Dictionary Node

:param value: A dict of nodes to insert into the dictionary
:return: An DictNode built from the arguments
dictr2   {})r   r5   r   itemsset_kwarg_no_checkDictNoder   )r   r   r8   keyr   s        r   r;   Builder.dictK   sd     ##DKK$ABHC##C- &S 14c9JKKr   c                N    [         R                  " U R                  SU5      5      $ )zNBuild A IdNode

:param value: the value of the boolean
:return: A BooleanNode
id)r   IdNoder   r&   s     r   r   Builder.identifierV   s     ~~dkk$677r   Nc           
        [         R                  " U R                  SS5      5      nUb  X5l        Ub:  UR	                  5        VVs0 s H  u  pgU R                  U5      U_M     snnUl        [         R                  " X R                  S5      U R                  U5      U R                  S5      XPR                  S5      5      $ s  snnf )a  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
r1   r2   .())	r   r5   r   r6   r>   r   kwargs
MethodNoder   )r   nameid_poskwr8   kvs           r   methodBuilder.method^   s     ##DKK$BC? N>=?XXZHZTQ4??1-q0ZHDK!!#||C'8$//$:OQUQ]Q]^aQbdhjvjvwzj{|| Is   Cc                p   [         R                  " U R                  SS5      5      nUb  X$l        Ub:  UR	                  5        VVs0 s H  u  pVU R                  U5      U_M     snnUl        [         R                  " U R                  U5      U R                  S5      X@R                  S5      5      $ s  snnf )zCreate 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
r1   r2   rI   rJ   )	r   r5   r   r6   r>   r   rK   FunctionNoder   )r   rM   rO   rP   r8   rQ   rR   s          r   functionBuilder.functionq   s     ##DKK$BC? N>=?XXZHZTQ4??1-q0ZHDK##DOOD$94<<;LdT`T`adTeff Is   B2c                P    [         R                  " SXR                  S5      U5      $ )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   lhsrhss      r   equalBuilder.equal   "     %%dCd1CSIIr   c                P    [         R                  " SXR                  S5      U5      $ )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!=rZ   r\   s      r   	not_equalBuilder.not_equal   ra   r   c                P    [         R                  " SXR                  S5      U5      $ )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
inrZ   r\   s      r   in_Builder.in_   ra   r   c                P    [         R                  " SXR                  S5      U5      $ )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 inrZ   r\   s      r   not_inBuilder.not_in   s"     %%gsLL4JCPPr   c                N    [         R                  " XR                  S5      U5      $ )zjCreate and OrNode

:param lhs: The Left of the Node
:param rhs: The Right of the Node
:return: The OrNode
or)r   OrNoder   r\   s      r   or_Builder.or_   s     ~~c<<#5s;;r   c                N    [         R                  " XR                  S5      U5      $ )ziCreate an AndNode

:param lhs: The left of the And
:param rhs: The right of the And
:return: The AndNode
and)r   AndNoder   r\   s      r   and_Builder.and_   s     sLL$7==r   c                p    [         R                  " U R                  SS5      U R                  S5      U5      $ )zJCreate a not node

:param value: The value to negate
:return: The NotNode
notr   )r   NotNoder   r   r&   s     r   not_Builder.not_   s+     t{{5"5t||E7JERRr   c                ^    [         R                  " U R                  SS5      5      nXl        U$ )Nnoder   )r   CodeBlockNoder   lines)r   r   blocks      r   r   Builder.block   s'    %%dkk&"&=>r   c                P    [         R                  " SXR                  S5      U5      $ )zCreate an addition node

:param lhs: The left of the addition
:param rhs: The right of the addition
:return: The ArithmeticNode
add+)r   ArithmeticNoder   r\   s      r   plusBuilder.plus   s"     %%eS,,s2CSIIr   c                n    [         R                  " U R                  U5      U R                  S5      U5      $ )zzCreate a "+=" node

:param value: The value to add
:param varname: The variable to assign
:return: The PlusAssignmentNode
z+=)r   PlusAssignmentNoder   r   r   s      r   
plusassignBuilder.plusassign   s-     ))$//'*BDLLQUDVX]^^r   c                    [         R                  " U5      nUR                  R                  [         R                  " X0R                  S5      X5      5        [         R                  " SSU R                  5      Ul        U$ )zxCreate 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   	conditionr   clauses       r   if_Builder.if_   sZ     %%i0

'..d1CYVW",,RT]]Cr   c                N   U Vs/ s H  o@R                  U5      PM     nn[        [        U5      S-
  5       Vs/ s H  o@R                  S5      PM     nn[        R
                  " U R                  S5      XVU R                  S5      X#U R                  S5      5      $ s  snf s  snf )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
   ,foreach:
endforeach)r   rangelenr   r   ForeachClauseNode)r   varnamesr>   r   ivaridscommass          r   r   Builder.foreach   s     /77h//!$h7-23x=13D-EF-E,,s#-EF((i)@&RVR^R^_bRcejswss  AM  tN  O  	O 8Fs
   BB" )r   r	   r   zmparser.TV_TokenTypesreturnz$mparser.Token[mparser.TV_TokenTypes])r   r	   r   zmparser.SymbolNode)r   mparser.BaseNoder    r	   r   zmparser.AssignmentNode)r   r	   r   zmparser.StringNode)r   intr   zmparser.NumberNode)r   zbuiltins.boolr   zmparser.BooleanNode)r   T.List[mparser.BaseNode]r   zmparser.ArrayNode)r   z*T.Dict[mparser.BaseNode, mparser.BaseNode]r   zmparser.DictNode)r   r	   r   zmparser.IdNode)NN)
rM   r	   rN   r   rO   $T.Optional[T.List[mparser.BaseNode]]rP   ,T.Optional[T.Mapping[str, mparser.BaseNode]]r   zmparser.MethodNode)rM   r	   rO   r   rP   r   r   zmparser.FunctionNode)r]   r   r^   r   r   zmparser.ComparisonNode)r]   r   r^   r   r   zmparser.OrNode)r]   r   r^   r   r   zmparser.AndNode)r   r   r   zmparser.NotNode)r   r   r   mparser.CodeBlockNode)r]   r   r^   r   r   zmparser.ArithmeticNode)r   r   r    r	   r   zmparser.PlusAssignmentNode)r   r   r   r   r   zmparser.IfClauseNode)r   zT.List[str]r>   r   r   r   r   zmparser.ForeachClauseNode)__name__
__module____qualname____firstlineno____annotations__r   r   r!   r$   r)   r-   r1   r;   r   rS   rW   r_   rc   rg   rk   rp   ru   rz   r   r   r   r   r   __static_attributes__r   r   r   r   r      s     MN8Z@E?M	L8 <@BF}8}?} '}( >BDHg:gAg +g$JJJQ<>S
J_

Or   r   )__doc__
__future__r   dataclassestypingTr   r   TYPE_CHECKINGbuiltins	dataclassr   r   r   r   <module>r      sG    #   ?? YO YO YOr   