
    cwi                    	   S r SSKJr  SSKJr  SSKJr  SSKJrJ	r	J
r
JrJrJrJrJrJrJrJr  SSKJrJrJrJrJrJrJrJrJr  SSKJr  SS	KJ r J!r!  SS
K"J#r#  SSK$J%r%J&r&  / SQr' " S S\!5      r( " S S\5      r) " S S\5      r* " S S\5      r+ " S S\5      r, " S S\5      r- " S S\5      r. " S S\5      r/ " S S\5      r0 " S S \5      r1 " S! S"\R                  5      r2 " S# S$\R                  5      r3 " S% S&\5      r4 " S' S(\5      r5S)\54S* jr6S+ r7\8" \Rr                  Rt                  5       V s0 s H#  n \" \Rr                  Rv                  U    5      U _M%     sn r<\\=\>\#\5S,S-\3\24   r?\\=\>\#\5S,S-\\=   \S-   4   r@\ " S. S-5      5       rA\R                  " \" S/5      S0S19S2 5       rC   SS3\\=   S4\	\A/S,4   S5\\   S6\\    S7\>S8S,4S9 jjrD   SS:\=S4\	\A/S,4   S5\\   S6\\    S7\>S8S,4S; jjrE " S< S=\
S=   5      rF " S> S?5      rGS@\5SA\=S8\A4SB jrHS@\5SA\=S8\A4SC jrIS@\5SD\#S8\A4SE jrJS@\5SF\>SG\AS8\A4SH jrKS@\5SF\>SI\ASJ\AS8\A4
SK jrLS@\5SI\ASJ\AS8\A4SL jrMS@\5SA\=SM\\A   SN\>S8\A4
SO jrNS@\5SM\\A   S8\A4SP jrOSQ\>S8\A4SR jrPSD\AS8\A4SS jrQST\ASU\\A   S8\A4SV jrRSW\>ST\AS8\A4SX jrSS@\5SY\ASZ\\A   S8\A4S[ jrTS@\5S\\\A   S]\\A   S^\\A   S8\A4
S_ jrUS`\\A   SZ\\A   S8\A4Sa jrVS@\5S\\\A   Sb\>S]\\A   S^\\A   S8\A4Sc jrWS`\\A   SZ\AS8\A4Sd jrXS@\5S\\\A   Sb\>S]\\A   S^\\A   S8\A4Se jrYS@\5S]\\A   S8\A4Sf jrZS@\5Sg\>S`\\A   S8\A4Sh jr[S@\5SA\=SM\\A   S8\A4Si jr\Sj\\=   ST\AS8\A4Sk jr]S@\5S]\\A   S8\A4Sl jr^Sm\=ST\AS8\A4Sn jr_S`\\A   SZ\\A   S8\A4So jr`S@\5ST\AS]\\A   Sp\\A   S8\A4
Sq jraS@\5Sr\>Ss\AS8\A4St jrbS@\5SA\=Su\>SF\>S8\A4
Sv jrcS@\5SA\=Sj\\A   S8\A4Sw jrdSj\\=   ST\=S8\A4Sx jreS@\5Sy\>SA\=Sz\>ST\=Sp\\A   S8\A4S{ jrfS@\5S|\AS}\\A   S8\A4S~ jrgS@\5SA\=SQ\AS\>S8\A4
S jrhS@\5SA\=Sz\>S\>S8\A4
S jriS@\5ST\AS}\\A   S8\A4S jrjS@\5S\ASu\AS`\\A   S}\\A   S8\A4S jrkS@\5SA\=S\=S8\A4S jrlS@\5SA\=S\\A   S8\A4S jrmS@\5Ss\AS}\\A   S\AS8\A4
S jrnS@\5S\AS\AS}\\A   S8\A4
S jroS@\5Ss\AS}\\A   S\ASu\AS\AS8\A4S jrpS@\5Ss\AS}\\A   S8\A4S jrqS@\5SA\=Sz\>S\>S8\A4
S jrrS@\5SA\=Sz\>S\>S8\A4
S jrsS@\5SA\=S`\\A   S\\A   S8\A4
S jrtS@\5SQ\=S\>S8\A4S jrug,s  sn f )a%  
Module to work with clingo's non-ground program representation.

Grammar
-------
The grammar below defines valid ASTs. For each upper case identifier there is a
matching function in the module. Arguments follow in parenthesis: each having a
type given on the right-hand side of the colon. The symbols `?`, `*`, and `+`
are used to denote optional arguments (`None` encodes abscence), list
arguments, and non-empty list arguments.

```
# Terms

term = SymbolicTerm
        ( location : Location
        , symbol   : clingo.Symbol
        )
     | Variable
        ( location : Location
        , name     : str
        )
     | UnaryOperation
        ( location      : Location
        , operator_type : UnaryOperator
        , argument      : term
        )
     | BinaryOperation
        ( location      : Location
        , operator_type : BinaryOperator
        , left          : term
        , right         : term
        )
     | Interval
        ( location : Location
        , left     : term
        , right    : term
        )
     | Function
        ( location  : Location
        , name      : str
        , arguments : term*
        , external  : bool
        )
     | Pool
        ( location  : Location
        , arguments : term*
        )

theory_term = SymbolicTerm
               ( location : Location
               , symbol   : clingo.Symbol
               )
            | Variable
               ( location : Location
               , name     : str
               )
            | TheorySequence
               ( location : Location
               , sequence_type : TheorySequenceType
               , terms         : theory_term*
               )
            | TheoryFunction
               ( location  : Location
               , name      : str
               , arguments : theory_term*
               )
            | TheoryUnparsedTerm
               ( location : Location
               , elements : TheoryUnparsedTermElement
                             ( operators : str*
                             , term      : theory_term
                             )+
               )

# Literals

symbolic_atom = SymbolicAtom
                 ( symbol : term
                 )

guard = Guard
         ( comparison : ComparisonOperator
         , term       : term
         )

literal = Literal
           ( location : Location
           , sign     : Sign
           , atom     : Comparison
                         ( term   : term
                         , guards : guard+
                         )
                      | BooleanConstant
                         ( value : bool
                         )
                      | symbolic_atom
           )

# Head and Body Literals

conditional_literal = ConditionalLiteral
                       ( location  : Location
                       , literal   : Literal
                       , condition : Literal*
                       )

aggregate = Aggregate
             ( location    : Location
             , left_guard  : guard?
             , elements    : conditional_literal*
             , right_guard : guard?
             )

theory_atom = TheoryAtom
               ( location : Location
               , term     : term
               , elements : TheoryAtomElement
                             ( terms     : theory_term*
                             , condition : literal*
                             )*
               , guard    : TheoryGuard
                             ( operator_name : str
                             , term          : theory_term
                             )?
               )

body_atom = aggregate
          | BodyAggregate
             ( location    : Location
             , left_guard  : guard?
             , function    : AggregateFunction
             , elements    : BodyAggregateElement
                              ( terms     : term*
                              , condition : literal*
                              )*
             , right_guard : guard?
             )
          | theory_atom

body_literal = literal
             | conditional_literal
             | Literal
                ( location : Location
                , sign     : Sign
                , atom     : body_atom
                )

head = literal
     | aggregate
     | HeadAggregate
        ( location    : Location
        , left_guard  : guard?
        , function    : AggregateFunction
        , elements    : HeadAggregateElement
                         ( terms     : term*
                         , condition : conditional_literal
                         )*
        , right_guard : guard?
        )
     | Disjunction
        ( location : Location
        , elements : conditional_literal*
        )
     | theory_atom

# Statements

statement = Rule
             ( location : Location
             , head     : head
             , body     : body_literal*
             )
          | Definition
             ( location   : Location
             , name       : str
             , value      : term
             , is_default : bool
             )
          | ShowSignature
             ( location   : Location
             , name       : str
             , arity      : int
             , sign       : bool
             )
          | Defined
             ( location   : Location
             , name       : str
             , arity      : int
             , sign       : bool
             )
          | ShowTerm
             ( location : Location
             , term     : term
             , body     : body_literal*
             )
          | Minimize
             ( location : Location
             , weight   : term
             , priority : term
             , terms    : term*
             , body     : body_literal*
             )
          | Script
             ( location : Location
             , name     : str
             , code     : str
             )
          | Program
             ( location   : Location
             , name       : str
             , parameters : Id
                             ( location : Location
                             , id       : str
                             )*
             )
          | External
             ( location : Location
             , atom     : symbolic_atom
             , body     : body_literal*
             , type     : term
             )
          | Edge
             ( location : Location
             , u        : term
             , v        : term
             , body     : body_literal*
             )
          | Heuristic
             ( location : Location
             , atom     : symbolic_atom
             , body     : body_literal*
             , bias     : term
             , priority : term
             , modifier : term
             )
          | ProjectAtom
             ( location : Location
             , atom     : symbolic_atom
             , body     : body_literal*
             )
          | ProjectSignature
             ( location : Location
             , name     : str
             , arity    : int
             , sign     : bool
             )
          | TheoryDefinition
             ( location : Location
             , name     : str
             , terms    : TheoryTermDefinition
                           ( location  : Location
                           , name      : str
                           , operators : TheoryOperatorDefinition
                                          ( location      : Location
                                          , name          : str
                                          , priority      : int
                                          , operator_type : TheoryOperatorType
                                          )*
                           )*
             , atoms    : TheoryAtomDefinition
                           ( location  : Location
                           , atom_type : TheoryAtomType
                           , name      : str
                           , arity     : int
                           , term      : str
                           , guard     : TheoryGuardDefinition
                                          ( operators : str*
                                          , term      : str
                                          )?
                           )*
             )
          | Comment
             ( location     : Location
             , value        : str
             , comment_type : CommentType
             )
```

Examples
--------
The following example parses a program from a string and passes the resulting
`AST` to the builder:

    >>> from clingo import Control, ast
    >>> from clingo.ast import Location, ProgramBuilder, Position, parse_string
    >>>
    >>> ctl = Control()
    >>>
    >>> with ProgramBuilder(ctl) as bld:
    ...     # parse from string
    ...     parse_string('a.', bld.add)
    ...     # build rule manually
    ...     pos = Position('<string>', 1, 1)
    ...     loc = Location(pos, pos)
    ...     fun = ast.Function(loc, 'b', [], False)
    ...     atm = ast.SymbolicAtom(fun)
    ...     lit = ast.Literal(loc, ast.Sign.NoSign, atm)
    ...     bld.add(ast.Rule(loc, lit, []))
    ...
    >>> ctl.ground([('base', [])])
    >>> print(ctl.solve(on_model=print))
    a b
    SAT

The next example shows how to transform ASTs using the `Transformer` class:

    >>> from clingo.ast import Transformer, Variable, parse_string
    >>>
    >>> class VariableRenamer(Transformer):
    ...     def visit_Variable(self, node):
    ...         return node.update(name='_' + node.name)
    ...
    >>> vrt = VariableRenamer()
    >>> parse_string('p(X) :- q(X).', lambda stm: print(str(vrt(stm))))
    #program base.
    p(_X) :- q(_X).
    )abc)IntEnum)total_ordering)AnyCallableContextManagerDictListMutableSequence
NamedTupleOptionalSequenceTupleUnion   )	_c_call_cb_error_handler_CBData_Error_ffi_handle_error_lib_str_to_str)Control)LoggerOrderedEnum)Symbol)SliceSlicedMutableSequence)BASTASTSequenceASTTypeASTValue	AggregateAggregateFunctionGuardBinaryOperationBinaryOperatorBodyAggregateBodyAggregateElementBooleanConstantCommentCommentType
ComparisonComparisonOperatorConditionalLiteralDefined
DefinitionDisjunctionEdgeExternalFunctionHeadAggregateHeadAggregateElement	HeuristicIdIntervalLiteralLocationMinimizePoolPositionProgramProgramBuilderProjectAtomProjectSignatureRuleScriptShowSignatureShowTermSignStrSequenceSymbolicAtomSymbolicTerm
TheoryAtomTheoryAtomDefinitionTheoryAtomElementTheoryAtomTypeTheoryDefinitionTheoryFunctionTheoryGuardTheoryGuardDefinitionTheoryOperatorDefinitionTheoryOperatorTypeTheorySequenceTheorySequenceTypeTheoryTermDefinitionTheoryUnparsedTermTheoryUnparsedTermElementTransformerUnaryOperationUnaryOperatorVariableparse_filesparse_stringc                   h   \ rS rSrSr\R                  r\R                  r	\R                  r\R                  r\R                  r\R                   r\R$                  r\R(                  r\R,                  r\R0                  r\R4                  r\R8                  r\R<                  r\R@                  r!\RD                  r#\RH                  r%\RL                  r'\RP                  r)\RT                  r+\RX                  r-\R\                  r/\R`                  r1\Rd                  r3\Rh                  r5\Rl                  r7\Rp                  r9\Rt                  r;\Rx                  r=\R|                  r?\R                  rA\R                  rC\R                  rE\R                  rG\R                  rI\R                  rK\R                  rM\R                  rO\R                  rQ\R                  rS\R                  rU\R                  rW\R                  rY\R                  r[\R                  r]\R                  r_\R                  raSrbg)r#   i  z 
Enumeration of ast node types.
 N)c__name__
__module____qualname____firstlineno____doc__r   clingo_ast_type_idr;   clingo_ast_type_variabler`   clingo_ast_type_symbolic_termrM   clingo_ast_type_unary_operationr^    clingo_ast_type_binary_operationr(   clingo_ast_type_intervalr<   clingo_ast_type_functionr7   clingo_ast_type_poolr@    clingo_ast_type_boolean_constantr,   clingo_ast_type_symbolic_atomrL   clingo_ast_type_comparisonr/   clingo_ast_type_guardr'   #clingo_ast_type_conditional_literalr1   clingo_ast_type_aggregater%   &clingo_ast_type_body_aggregate_elementr+   clingo_ast_type_body_aggregater*   &clingo_ast_type_head_aggregate_elementr9   clingo_ast_type_head_aggregater8   clingo_ast_type_disjunctionr4   clingo_ast_type_theory_sequencerX   clingo_ast_type_theory_functionrS   ,clingo_ast_type_theory_unparsed_term_elementr\   $clingo_ast_type_theory_unparsed_termr[   clingo_ast_type_theory_guardrT   #clingo_ast_type_theory_atom_elementrP   clingo_ast_type_theory_atomrN   clingo_ast_type_literalr=   *clingo_ast_type_theory_operator_definitionrV   &clingo_ast_type_theory_term_definitionrZ   'clingo_ast_type_theory_guard_definitionrU   &clingo_ast_type_theory_atom_definitionrO   clingo_ast_type_rulerF   clingo_ast_type_definitionr3   clingo_ast_type_show_signaturerH   clingo_ast_type_show_termrI   clingo_ast_type_minimizer?   clingo_ast_type_scriptrG   clingo_ast_type_programrB   clingo_ast_type_externalr6   clingo_ast_type_edger5   clingo_ast_type_heuristicr:   clingo_ast_type_project_atomrD   !clingo_ast_type_project_signaturerE   clingo_ast_type_definedr2   !clingo_ast_type_theory_definitionrR   clingo_ast_type_commentr-   __static_attributes__rd       D/home/james-whalen/.local/lib/python3.13/site-packages/clingo/ast.pyr#   r#     s    
	 	 B,,H55L99N;;O,,H,,H$$D;;O55L00J&&EAA..IFF77MFF77M22K99N99N $ Q QBB33K@@11J**G#NNFF HHFF$$D00J77M--H,,H((F**G,,H$$D..I33K==**G==**Gr   r#   c                       \ rS rSrSr\R                  r \R                  r	 \R                  r \R                  r \R                  rSrg)r&   i  z$
Enumeration of aggegate functions.
rd   N)re   rf   rg   rh   ri   r   #clingo_ast_aggregate_function_countCount!clingo_ast_aggregate_function_maxMax!clingo_ast_aggregate_function_minMin!clingo_ast_aggregate_function_sumSum"clingo_ast_aggregate_function_sumpSumPlusr   rd   r   r   r&   r&     sa     44E 
0
0C 
0
0C 
0
0C 55Gr   r&   c                       \ rS rSrSr\R                  r \R                  r	 \R                  r \R                  r \R                  r \R                   r \R$                  r \R(                  r \R,                  rSrg)r)   i  z"
Enumeration of binary operators.
rd   N)re   rf   rg   rh   ri   r   clingo_ast_binary_operator_andAnd#clingo_ast_binary_operator_divisionDivision clingo_ast_binary_operator_minusMinus!clingo_ast_binary_operator_moduloModulo)clingo_ast_binary_operator_multiplicationMultiplicationclingo_ast_binary_operator_orOrclingo_ast_binary_operator_plusPlus clingo_ast_binary_operator_powerPowerclingo_ast_binary_operator_xorXOrr   rd   r   r   r)   r)     s     
-
-C 77H 11E 33F CCN 
	+	+B //D 11E 
-
-Cr   r)   c                   J    \ rS rSrSr\R                  r \R                  r	Sr
g)r.   i$  z
Enumeration of comment types.
rd   N)re   rf   rg   rh   ri   r   clingo_comment_type_lineLineclingo_comment_type_blockBlockr   rd   r   r   r.   r.   $  s+     ((D **Er   r.   c                       \ rS rSrSr\R                  r \R                  r	 \R                  r \R                  r \R                  r \R                   rSrg)r0   i3  z&
Enumeration of comparison operators.
rd   N)re   rf   rg   rh   ri   r   $clingo_ast_comparison_operator_equalEqual,clingo_ast_comparison_operator_greater_equalGreaterEqual+clingo_ast_comparison_operator_greater_thanGreaterThan)clingo_ast_comparison_operator_less_equal	LessEqual(clingo_ast_comparison_operator_less_thanLessThan(clingo_ast_comparison_operator_not_equalNotEqualr   rd   r   r   r0   r0   3  ss     55E DDL BBK >>I <<H <<Hr   r0   c                   d    \ rS rSrSr\R                  r \R                  r	 \R                  rSrg)rJ   iR  $
Enumeration of signs for literals.
rd   N)re   rf   rg   rh   ri   r   clingo_ast_sign_double_negationDoubleNegationclingo_ast_sign_negationNegationclingo_ast_sign_no_signNoSignr   rd   r   r   rJ   rJ   R  s=     99N ,,H ))Fr   rJ   c                   ~    \ rS rSrSr\R                  r \R                  r	 \R                  r \R                  rSrg)rQ   ie  z#
Enumeration of theory atom types.
rd   N)re   rf   rg   rh   ri   r   *clingo_ast_theory_atom_definition_type_anyr   +clingo_ast_theory_atom_definition_type_bodyBody0clingo_ast_theory_atom_definition_type_directive	Directive+clingo_ast_theory_atom_definition_type_headHeadr   rd   r   r   rQ   rQ   e  sO     
9
9C ;;D EEI ;;Dr   rQ   c                   d    \ rS rSrSr\R                  r \R                  r	 \R                  rSrg)rW   i|  z 
Enumeration of operator types.
rd   N)re   rf   rg   rh   ri   r   +clingo_ast_theory_operator_type_binary_left
BinaryLeft,clingo_ast_theory_operator_type_binary_rightBinaryRight%clingo_ast_theory_operator_type_unaryUnaryr   rd   r   r   rW   rW   |  s=     AAJ CCK 66Er   rW   c                   d    \ rS rSrSr\R                  r \R                  r	 \R                  rSrg)rY   i  z,
Enumeration of theory term sequence types.
rd   N)re   rf   rg   rh   ri   r   $clingo_ast_theory_sequence_type_listr
   #clingo_ast_theory_sequence_type_setSet%clingo_ast_theory_sequence_type_tupler   r   rd   r   r   rY   rY     s=     44D 
2
2C 66Er   rY   c                   d    \ rS rSrSr\R                  r \R                  r	 \R                  rSrg)r_   i  r   rd   N)re   rf   rg   rh   ri   r   "clingo_ast_unary_operator_absoluteAbsoluteclingo_ast_unary_operator_minusr   "clingo_ast_unary_operator_negationr   r   rd   r   r   r_   r_     s=     66H 00E 66Hr   r_   c                   t    \ rS rSrSrS rS rS rS rS r	S\
4S	 jrS
 rS rS rS rS rS rS rS rSrg)r"   i  z
A sequence holding `AST` nodes.

Sequences implement Python's rich comparison operators and are ordered
structurally ignoring the location. They can also be used as dictionary
keys.
c                 \    Xl         X l        [        R                  " U R                   5        g N)_rep
_attributer   clingo_ast_acquireselfrep	attributes      r   __init__ASTSequence.__init__  s    	#		*r   c                 0    [        U 5      [        U5      :H  $ r   tupler   others     r   __eq__ASTSequence.__eq__  s    T{eEl**r   c                 0    [        U 5      [        U5      :  $ r   r   r   s     r   __lt__ASTSequence.__lt__  s    T{U5\))r   c                 *    [        [        U 5      5      $ r   )hashr   r   s    r   __hash__ASTSequence.__hash__  s    E$K  r   c                 D    [         R                  " U R                  5        g r   r   clingo_ast_releaser   r  s    r   __del__ASTSequence.__del__      		*r   returnc                 b    [        S[        R                  U R                  U R                  5      $ Nsize_t)r   r   #clingo_ast_attribute_size_ast_arrayr   r   r  s    r   __len__ASTSequence.__len__  s)    44IIOO	
 	
r   c           	          [        U[        5      (       a  [        U [        U5      5      $ [	        U 5      nUS:  a  X-  nUS:  d  X:  a  [        S5      e[        [        S[        R                  U R                  U R                  U5      5      $ )Nr   invalid indexclingo_ast_t*)
isinstanceslicer    r   len
IndexErrorr!   r   r   clingo_ast_attribute_get_ast_atr   r   r   indexsizes      r   __getitem__ASTSequence.__getitem__  s    eU##(uU|<<4y19ME19_--44		
 	
r   c           
   #      #    [        [        U 5      5       H?  n[        [        S[        R
                  U R                  U R                  U5      5      v   MA     g 7f)Nr  )ranger  r!   r   r   r  r   r   r   r  s     r   __iter__ASTSequence.__iter__  sJ     3t9%E#88IIOO  &   AAc                     [        U[        5      (       a  [        S5      e[        [        R
                  " U R                  U R                  XR                  5      5        g Nslicing not implemented)r  r  	TypeErrorr   r   clingo_ast_attribute_set_ast_atr   r   )r   r  asts      r   __setitem__ASTSequence.__setitem__  sD    eU##56600		4??E88	
r   c                    [        U[        5      (       a  [        S5      e[        U 5      nUS:  a  X-  nUS:  d  X:  a  [	        S5      e[        [        R                  " U R                  U R                  U5      5        g Nr)  r   r  )
r  r  r*  r  r  r   r   "clingo_ast_attribute_delete_ast_atr   r   r  s      r   __delitem__ASTSequence.__delitem__  sk    eU##5664y19ME19_--33DIItPUV	
r   c                     [        [        R                  " U R                  U R                  XR                  5      5        g r   )r   r   "clingo_ast_attribute_insert_ast_atr   r   r   r  values      r   insertASTSequence.insert
  s+    33		4??E::	
r   c                 H    [        [        U 5      SS5       H  nXS-
  	 M
     gz(
Remove all elements from the sequence.
r   r   Nr"  r  r   is     r   clearASTSequence.clear  $     s4y!R(AU )r   c                 *    [        [        U 5      5      $ r   strlistr  s    r   __str__ASTSequence.__str__      4:r   c                 *    [        [        U 5      5      $ r   reprrF  r  s    r   __repr__ASTSequence.__repr__      DJr   r   r   N)re   rf   rg   rh   ri   r   r   r   r  r
  intr  r  r$  r-  r2  r8  r@  rG  rM  r   rd   r   r   r"   r"     sT    +
+*!+
 

$




 r   r"   c                   b    \ rS rSrSrS rS rS\4S jrS r	S r
S	 rS
 rS rS rS rS rSrg)rK   i  z
A sequence holding strings.
c                 \    X l         Xl        [        R                  " U R                  5        g r   )r   r   r   r   r   s      r   r   StrSequence.__init__$  s    #			*r   c                 D    [         R                  " U R                  5        g r   r  r  s    r   r
  StrSequence.__del__)  r  r   r  c                 b    [        S[        R                  U R                  U R                  5      $ r  )r   r   &clingo_ast_attribute_size_string_arrayr   r   r  s    r   r  StrSequence.__len__,  s)    77IIOO	
 	
r   c           	          [        U[        5      (       a  [        U [        U5      5      $ [	        U 5      nUS:  a  X-  nUS:  d  X:  a  [        S5      e[        [        S[        R                  U R                  U R                  U5      5      $ )Nr   r  char*)r  r  r    r   r  r  r   r   r   "clingo_ast_attribute_get_string_atr   r   r  s      r   r  StrSequence.__getitem__4  s    eU##(uU|<<4y19ME19_--77		
 	
r   c           
   #      #    [        [        U 5      5       H?  n[        [        S[        R
                  U R                  U R                  U5      5      v   MA     g 7f)Nr[  )r"  r  r   r   r   r\  r   r   r#  s     r   r$  StrSequence.__iter__F  sJ     3t9%E;;IIOO  &r&  c           	          [        U[        5      (       a  [        S5      e[        [        R
                  " U R                  U R                  XR                  5       5      5        g r(  )	r  r  r*  r   r   "clingo_str_attribute_set_string_atr   r   encoder6  s      r   r-  StrSequence.__setitem__R  sF    eU##56633		4??E<<>	
r   c                    [        U[        5      (       a  [        S5      e[        U 5      nUS:  a  X-  nUS:  d  X:  a  [	        S5      e[        [        R                  " U R                  U R                  U5      5        g r0  )
r  r  r*  r  r  r   r   %clingo_ast_attribute_delete_string_atr   r   r  s      r   r2  StrSequence.__delitem__[  sm    eU##5664y19ME19_--66		4??E	
r   c           	          [        [        R                  " U R                  U R                  XR                  5       5      5        g r   )r   r   %clingo_ast_attribute_insert_string_atr   r   rb  r6  s      r   r8  StrSequence.inserti  s-    66		4??E<<>	
r   c                 H    [        [        U 5      SS5       H  nXS-
  	 M
     gr;  r=  r>  s     r   r@  StrSequence.clearp  rB  r   c                 *    [        [        U 5      5      $ r   rD  r  s    r   rG  StrSequence.__str__w  rI  r   c                 *    [        [        U 5      5      $ r   rK  r  s    r   rM  StrSequence.__repr__z  rO  r   rP  N)re   rf   rg   rh   ri   r   r
  rQ  r  r  r$  r-  r2  r8  r@  rG  rM  r   rd   r   r   rK   rK     sE    +
+
 

$



 r   rK   c                   <    \ rS rSr% Sr\\S'    \\S'    \\S'   Srg)rA   i~  z.
Class to point to a position in a text file.
filenamelinecolumnrd   N)	re   rf   rg   rh   ri   rE  __annotations__rQ  r   rd   r   r   rA   rA   ~  s+     M I Kr   rA   c                   0    \ rS rSr% Sr\\S'    \\S'   Srg)r>   i  z+
Class to point to a range in a text file.
beginendrd   N)re   rf   rg   rh   ri   rA   rt  r   rd   r   r   r>   r>     s     O 
Mr   r>   locc           	         [         R                  " SU R                  R                  R	                  5       5      n[         R                  " SU R
                  R                  R	                  5       5      n[         R                  " SUUU R                  R                  U R
                  R                  U R                  R                  U R
                  R                  45      UU4$ )Nchar[]zclingo_location_t*)r   newrv  rq  rb  rw  rr  rs  )rx  memamembs      r   _c_locationr~    s    88Hcii00779:D88Hcgg..5578D 				  
	
 	 r   c                     [        [        [        U R                  5      U R                  U R
                  5      [        [        U R                  5      U R                  U R                  5      5      $ r   )	r>   rA   r   
begin_file
begin_linebegin_columnend_fileend_line
end_column)r   s    r   _py_locationr    sK    (#..#:J:JK&cnnE r   Nr!   c                     ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 rS
 rS rSS jrSS jrS\SS 4S jrS\\\\4      4S jrS\\   4S jrS\\   4S jr\S\4S j5       r\S\\   4S j5       rSS\S\S\S    4S jjrSrU =r $ )r!   i  a  
Represents a node in the abstract syntax tree.

The attributes of an `AST` are tied to its type. They correspond to the
grammar in the description of the `clingo.ast` module. `AST` nodes can be
constructed using one of the functions provided in this module.

Furthermore, AST nodes implement Python's rich comparison operators and are
ordered structurally ignoring the location. They can also be used as
dictionary keys. Their string representation corresponds to their gringo
representation. In fact, the string representation of any AST obtained from
`parse_files` and `parse_string` can be parsed again. Note that it is
possible to construct ASTs that are not parsable, though.
c                 &   > [         TU ]  SU5        g )Nr   )super__setattr__)r   r   	__class__s     r   r   AST.__init__  s    FC(r   c                     [        U[        5      (       d  [        $ [        R                  " U R
                  UR
                  5      $ r   )r  r!   NotImplementedr   clingo_ast_equalr   r   s     r   r   
AST.__eq__  s0    %%%!!$$TYY

;;r   c                     [        U[        5      (       d  [        $ [        R                  " U R
                  UR
                  5      $ r   )r  r!   r  r   clingo_ast_less_thanr   r   s     r   r   
AST.__lt__  s0    %%%!!((EJJ??r   c                 B    [         R                  " U R                  5      $ r   )r   clingo_ast_hashr   r  s    r   r  AST.__hash__  s    ##DII..r   c                 D    [         R                  " U R                  5        g r   r  r  s    r   r
  AST.__del__  r  r   c                    [         R                  U5      nUb+  [        S[        R                  U R
                  U5      (       d  [        SU 35      e[        S[        R                  U R
                  U5      nU[        R                  :X  a/  [        [        S[        R                  U R
                  U5      5      $ U[        R                  :X  a&  [        S[        R                  U R
                  U5      $ U[        R                  :X  a/  [        [        S[        R                  U R
                  U5      5      $ U[        R                   :X  a/  [#        [        S[        R$                  U R
                  U5      5      $ U[        R&                  :X  aG  [        S[        R(                  U R
                  U5      nU[*        R,                  :w  a  [/        U5      $ S $ U[        R0                  :X  a/  [/        [        S[        R2                  U R
                  U5      5      $ U[        R4                  :X  a  [7        U R
                  U5      $ U[        R8                  :X  d   e[;        U R
                  U5      $ )	Nboolno attribute: clingo_ast_attribute_type_tr[  rQ  clingo_symbol_tclingo_location_tr  )_attribute_namesgetr   r   clingo_ast_has_attributer   AttributeErrorclingo_ast_attribute_type clingo_ast_attribute_type_stringr   clingo_ast_attribute_get_string clingo_ast_attribute_type_numberclingo_ast_attribute_get_number clingo_ast_attribute_type_symbolr   clingo_ast_attribute_get_symbol"clingo_ast_attribute_type_locationr  !clingo_ast_attribute_get_location&clingo_ast_attribute_type_optional_ast%clingo_ast_attribute_get_optional_astr   NULLr!   clingo_ast_attribute_type_astclingo_ast_attribute_get_ast&clingo_ast_attribute_type_string_arrayrK   #clingo_ast_attribute_type_ast_arrayr"   )r   nameattr_id	attr_typer   s        r   __getattr__AST.__getattr__  s   "&&t,?'D11499g#
 #
 !>$!899)**II	
	 ===TAA499g 
 ===t;;TYY  ===%88II	  ???'::II	  CCC::			C  #dii/3s89T9:::#55II	  CCCtyy'22DDDDDD499g..r   c                 P   [        [        SU 35      n[        S[        R                  U R                  U5      (       d  [        SU 35      e[        S[        R                  U R                  U5      nU[        R                  :X  a9  [        [        R                  " U R                  X2R                  5       5      5        g U[        R                  :X  a+  [        [        R                  " U R                  X25      5        g U[        R                  :X  a5  [        [        R                  " U R                  X2R                  5      5        g U[        R                  :X  a9  [!        U5      n[        [        R"                  " U R                  X5S   5      5        g U[        R$                  :X  aH  [        [        R&                  " U R                  X2c  [(        R*                  OUR                  5      5        g U[        R,                  :X  a5  [        [        R.                  " U R                  X2R                  5      5        g U[        R0                  :X  a  [3        U[4        5      (       a5  X2R6                  :X  a%  U R                  UR                  :X  a  [9        U5      nO [3        U[8        5      (       d  [9        U5      n[5        U R                  U5      nUR;                  5         UR=                  U5        g U[        R>                  :X  d   e[3        U[@        5      (       a5  X2R6                  :X  a%  U R                  UR                  :X  a  [9        U5      nO [3        U[8        5      (       d  [9        U5      n[A        U R                  U5      nUR;                  5         UR=                  U5        g )Nclingo_ast_attribute_r  r  r  r   )!getattrr   r   r  r   r  r  r  r   clingo_ast_attribute_set_stringrb  r  clingo_ast_attribute_set_numberr  clingo_ast_attribute_set_symbolr  r~  !clingo_ast_attribute_set_locationr  %clingo_ast_attribute_set_optional_astr   r  r  clingo_ast_attribute_set_astr  r  rK   r   rF  r@  extendr  r"   )r   r  r7  r  r  c_locstr_seqast_seqs           r   r  AST.__setattr__(  s   $"7v >?vt<<diiQQ >$!899)**II	
	 ===44TYYX $???44TYYO $???44TYYT $AAA&E66tyy'QR8T $EEE::IIw]		


 $<<<11$))WjjQ $EEE%--...499

3J KEt,,U!$))W5GMMONN5! H HHHH%--...499

3J KEt,,U!$))W5GMMONN5!r   c                 h    [        [        R                  [        R                  U R                  5      $ r   )r   r   clingo_ast_to_string_sizeclingo_ast_to_stringr   r  s    r   rG  AST.__str__a  s&    **D,E,Etyy
 	
r   c                     [        U R                  5      R                  SS5      nSR                  S U R	                  5        5       5      nU SU S3$ )Nr#   r,  z, c              3   8   #    U  H  n[        U5      v   M     g 7fr   )rL  ).0xs     r   	<genexpr>AST.__repr__.<locals>.<genexpr>h  s     8-Qa-s   ())rE  ast_typereplacejoinvalues)r   r  argss      r   rM  AST.__repr__f  sJ    4==!)))U;yy8$++-88qa  r   r  c                 ^    [        [        S[        R                  U R                  5      5      $ )z#
Return a shallow copy of the ast.
r  )r!   r   r   clingo_ast_copyr   r  s    r   __copy__AST.__copy__k  s"     7?D,@,@$))LMMr   c                 ^    [        [        S[        R                  U R                  5      5      $ )z 
Return a deep copy of the ast.
r  )r!   r   r   clingo_ast_deep_copyr   )r   memos     r   __deepcopy__AST.__deepcopy__q  s"     7?D,E,EtyyQRRr   kwargsc                    U(       d  U $ / nU R                  5        H7  nX1;   a  UR                  X   5        M  UR                  [        X5      5        M9     [        5       [	        U R
                  5      R                  SS5         nU" U6 $ )z
Return a copy of the AST also updating the given attributes.

Note that this function returns a reference to self if no arguments are
given.
ASTType. )keysappendr  globalsrE  r  r  )r   r  r  keyconss        r   update
AST.updatew  ss     K99;C}FK(GD./	  yT]]+33JCDT{r   c                 b    U R                  5        Vs/ s H  o[        X5      4PM     sn$ s  snf )z$
The list of items of the AST node.
r  r  r   r  s     r   items	AST.items  s*     9=		Dwt*+DDDs   ,c                 2   [         R                  R                  U R                  R                     n[         R
                  R                  n[        UR                  5       Vs/ s H'  n[        X!R                  U   R                     5      PM)     sn$ s  snf )z#
The list of keys of the AST node.
)r   g_clingo_ast_constructorsconstructorsr  r7  g_clingo_ast_attribute_namesnamesr"  r  r   	argumentsr   r   r  r  js       r   r  AST.keys  so     --::4==;N;NO1177EJ499EUVEUnnQ/99:;EUVVVs   #.Bc                 `    U R                  5        Vs/ s H  n[        X5      PM     sn$ s  snf )z%
The list of values of the AST node.
r  r  s     r   r  
AST.values  s'     37))+>+$$+>>>s   +c                 ^    [        [        S[        R                  U R                  5      5      $ )z
The type of the node.
clingo_ast_type_t)r#   r   r   clingo_ast_get_typer   r  s    r   r  AST.ast_type  s(    
 ')A)A499M
 	
r   c                    [         R                  R                  U R                  R                     n[         R
                  R                  n[        UR                  5       Vs/ s Hs  nUR                  U   R                  [         R                  [         R                  [         R                  4;   d  MO  [        X!R                  U   R                     5      PMu     sn$ s  snf )z*
List of attribute names containing ASTs.
)r   r  r  r  r7  r  r  r"  r  r  typer  r  r  r   r   r  s       r   
child_keysAST.child_keys  s    
 --::4==;N;NO1177 499%	
%~~a %%22;;88 8GE..+5567%	
 		
 	
s   #AC 5(C r   	conditionc                 V   SnU(       a  U[         R                  -  nU(       a  U[         R                  -  n/ n[        5       n[	        UR
                  U5      n[        R                  " U5      n[        [         R                  " U R                  U[         R                  U5      5        U$ )z
Unpool the AST returning a list of ASTs without pool terms.

Parameters
----------
other
    Remove all pools except those in conditions of conditional
    literals.
condition
    Only remove pools from conditions of conditional literals.
r   )r   clingo_ast_unpool_type_other clingo_ast_unpool_type_conditionr   r   r  r   
new_handler   clingo_ast_unpoolr   pyclingo_ast_callback)r   r   r  unpool_typereterrorcb_data	c_cb_datas           r   unpool
AST.unpool  s     4<<<K4@@@K#**e,OOG,	""		;(B(BI	

 
r   rd   )r  r!   )TT)!re   rf   rg   rh   ri   r   r   r   r  r
  r  r  rG  rM  r  r  	ASTUpdater  r
   r   rE  r$   r  r  r  propertyr#   r  r  r  r  r   __classcell__)r  s   @r   r!   r!     s    )<
@
/+</|7"r

!
NSy U (EtE#x-01 EWd3i W?X ? 
' 
 
 
DI 
 
"D D DK  r   datar
  )onerrorr  c                     [         R                  " U5      R                  n[        R                  " U 5        U" [        U 5      5        g)z
Low-level ast callback.
T)r   from_handler  r   r   r!   )r,  r  callbacks      r   _pyclingo_ast_callbackr    s7    
 %**HC SXr   filesr  controlloggermessage_limitr  c                    Ub  UR                   O[        R                  nUb'  [        R                  " U5      n[        R
                  nO [        R                  n[        R                  n[        5       n[        X5      n	[        R                  " U	5      n
[        [        R                  " U  Vs/ s H(  n[        R                  " SUR                  5       5      PM*     sn[        U 5      [        R                  U
UUUU5      U	5        gs  snf )a  
Parse the programs in the given files and return an abstract syntax tree for
each statement via a callback.

The function follows clingo's handling of files on the command line. Filename
`"-"` is treated as stdin and if an empty list is given, then the parser will
read from stdin.

The optional control object can be added to enable parsing of files in
ASPIF format. The ground statements will be added to the control object.

Parameters
----------
files
    List of file names.
callback
    Callable taking an ast as argument.
control
    Control object to add ground rules to.
logger
    Function to intercept messages normally printed to standard error.
message_limit
    The maximum number of messages passed to the logger.

See Also
--------
ProgramBuilder
Nrz  )r   r   r  r  r   pyclingo_logger_callbackr   r   r   clingo_ast_parse_filesr{  rb  r  r
  )r  r  r  r  r  	c_controlc_logger_datac_loggerr  r  r  fs               r   ra   ra     s    F !( 3I/00		99HEh&G(I##5:;UTXXh
+U;J&&		
 	;s   ./Dprogramc                    Ub  UR                   O[        R                  nUb'  [        R                  " U5      n[        R
                  nO [        R                  n[        R                  n[        5       n[        X5      n	[        R                  " U	5      n
[        [        R                  " U R                  5       [        R                  U
UUUU5      U	5        g)aT  
Parse the given program and return an abstract syntax tree for each
statement via a callback.

The optional control object can be added to enable parsing of files in
ASPIF format. The ground statements will be added to the control object.

Parameters
----------
program
    String representation of the program.
callback
    Callable taking an ast as argument.
control
    Control object to add ground rules to.
logger
    Function to intercept messages normally printed to standard error.
message_limit
    The maximum number of messages passed to the logger.

See Also
--------
ProgramBuilder
N)r   r   r  r  r   r   r   r   r   clingo_ast_parse_stringrb  r
  )r&  r  r  r  r  r"  r#  r$  r  r  r  s              r   rb   rb   #  s    > !( 3I/00		99HEh&G(I$$NN&&	
 	r   c                   D    \ rS rSrSrS\4S jrS rS rS\	SS	4S
 jr
Srg	)rC   i]  a  
Object to build non-ground programs.

Parameters
----------
control
    The `clingo.control.Control` object to attach the builder to.

See Also
--------
parse_string, parse_files

Notes
-----
This class is a context manager and must be used with Python's `with`
statement.
r  c                 X    [        S[        R                  UR                  5      U l        g )Nzclingo_program_builder_t*)r   r   clingo_program_builder_initr   )r   r  s     r   r   ProgramBuilder.__init__p  s    ')I)I7<<
	r   c                 X    [        [        R                  " U R                  5      5        U $ r   )r   r   clingo_program_builder_beginr   r  s    r   	__enter__ProgramBuilder.__enter__u  s    d77		BCr   c                 V    [        [        R                  " U R                  5      5        g)NF)r   r   clingo_program_builder_endr   )r   exc_typeexc_valexc_tbs       r   __exit__ProgramBuilder.__exit__y  s    d55dii@Ar   	statementr  Nc                 l    [        [        R                  " U R                  UR                  5      5        g)zv
Adds a statement in form of an `AST` node to the program.

Parameters
----------
statement
    The statement to add.
N)r   r   clingo_program_builder_addr   )r   r8  s     r   addProgramBuilder.add}  s!     	d55diiPQr   )r   )re   rf   rg   rh   ri   r   r   r/  r6  r!   r;  r   rd   r   r   rC   rC   ]  s3    $
 

	RS 	RT 	Rr   rC   c                       \ rS rSrSrS\S\S\S\4S jrS\S\S\S\\	\
4   4S jrS	\S\S\S\\   4S
 jrS\S\\4   S\S\S\S\\\   4   4S jrS\S\S\S\4S jrSrg)r]   i  a  
Utility class to transform ASTs.

Classes should inherit from this class and implement functions with name
`visit_<ast_type>` where `<ast_type>` is the type of the ASTs to visit and
modify. Such a function should return an updated AST or the same AST if no
change is necessary. The transformer will take care to copy all parent ASTs
involving a modified child. Note that the class works like a visitor if
only self references are returned from such functions.

Any extra arguments passed to the visit method are passed on to child ASTs.
r,  r  r  r  c           	          S[        UR                  5      R                  SS5      -   n[        X5      (       a  [	        X5      " U/UQ70 UD6$ UR
                  " S0 U R                  " U/UQ70 UD6D6$ )zs
Dispatch to a visit method in a base class or visit and transform the
children of the given AST if it is missing.
visit_r  r  rd   )rE  r  r  hasattrr  r  visit_children)r   r,  r  r  attrs        r   visitTransformer.visit  sp    
 #cll+33JCC44&s<T<V<<zzFD//EdEfEFFr   c                     [        5       nUR                   H.  n[        X5      nU R                  " U/UQ70 UD6nXvLd  M*  XtU'   M0     U$ )z
Visit and transform the children of the given AST.

Returns
-------
The functions returns a dictionary that can be passed to `AST.update`.
It contains the attributes and values that have been transformed.
)dictr  r  	_dispatch)r   r,  r  r  r  r  oldr{  s           r   rA  Transformer.visit_children  sN     (,v>>C##C..6t6v6C~!s	 "
 r   sequencec                 l    U/ pTU H*  nUR                  U " U/UQ70 UD65        US   ULd  M(  UnM,     U$ )zn
Transform a sequence of ASTs returning the same sequnce if there are no
changes or a list of ASTs otherwise.
r<  )r  )r   rJ  r  r  r  lstrH  s          r   visit_sequenceTransformer.visit_sequence  sH     RSCJJtC1$1&122wc!  
r   Nc                     Uc  U$ [        U[        5      (       a  U R                  " U/UQ70 UD6$ [        U[        R                  5      (       a  U R
                  " U/UQ70 UD6$ [        S5      e)z>
Visit and transform an (optional) AST or a sequence of ASTs.
zunexpected type)r  r!   rC  r   r   rM  r*  r   r,  r  r  s       r   rG  Transformer._dispatch  sl     ;Jc3::c3D3F33c3<<((&&s<T<V<<)**r   c                 .    U R                   " U/UQ70 UD6$ )z.
Alternative way to call `Transformer.visit`.
)rC  rP  s       r   __call__Transformer.__call__  s     zz#////r   rd   )re   rf   rg   rh   ri   r!   r   rC  r	   rE  r  rA  r"   r   rM  r   rG  rS  r   rd   r   r   r]   r]     s    G GS GC GC G".1	c9n	&#,/;>		+sK/0+9<+HK+	tS/#..	/+"0C 0 0s 0s 0r   r]   locationr  c                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SUR                  5       5      5      5        [        US   5      $ )z-
Construct an AST node of type `ASTType.Id`.
clingo_ast_t**r   char const[])	r   r{  r~  r   r   clingo_ast_buildrj   rb  r!   rU  r  p_ast
c_locations       r   r;   r;     sj     HH%&EX&J##qMHH^T[[]3		
 uQx=r   c                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SUR                  5       5      5      5        [        US   5      $ )z3
Construct an AST node of type `ASTType.Variable`.
rW  r   rX  )	r   r{  r~  r   r   rY  rk   rb  r!   rZ  s       r   r`   r`     sj     HH%&EX&J))qMHH^T[[]3		
 uQx=r   symbolc                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SUR                  5      5      5        [        US   5      $ )z7
Construct an AST node of type `ASTType.SymbolicTerm`.
rW  r   r  )
r   r{  r~  r   r   rY  rl   castr   r!   )rU  r^  r[  r\  s       r   rM   rM     si     HH%&EX&J..qMII'5		
 uQx=r   operator_typeargumentc                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SU5      UR                  5      5        [        US   5      $ )z9
Construct an AST node of type `ASTType.UnaryOperation`.
rW  r   rQ  )
r   r{  r~  r   r   rY  rm   r`  r   r!   )rU  ra  rb  r[  r\  s        r   r^   r^     sk     HH%&EX&J00qMIIe]+MM	
 uQx=r   leftrightc                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SU5      UR                  UR                  5      5        [        US   5      $ )z:
Construct an AST node of type `ASTType.BinaryOperation`.
rW  r   rQ  )
r   r{  r~  r   r   rY  rn   r`  r   r!   )rU  ra  rd  re  r[  r\  s         r   r(   r(      sr     HH%&EX&J11qMIIe]+IIJJ	
	 uQx=r   c           	          [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  X4S   UR                  UR                  5      5        [        US   5      $ )z3
Construct an AST node of type `ASTType.Interval`.
rW  r   )	r   r{  r~  r   r   rY  ro   r   r!   )rU  rd  re  r[  r\  s        r   r<   r<   5  s^     HH%&EX&J))5Q-EJJ	

 uQx=r   r  externalc                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SUR                  5       5      [         R                  " SU Vs/ s H  ofR                  PM     sn5      [         R                  " S[        U5      5      [         R                  " SU5      5      5        [        US   5      $ s  snf )z3
Construct an AST node of type `ASTType.Function`.
rW  r   rX  clingo_ast_t*[]r  rQ  )r   r{  r~  r   r   rY  rp   rb  r   r`  r  r!   )rU  r  r  rh  r[  r\  r  s          r   r7   r7   C  s     HH%&EX&J))qMHH^T[[]3HH&(CA(CDIIhI/IIeX&	

 uQx= )Ds   C+c                 l   [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SU Vs/ s H  oDR                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf )z/
Construct an AST node of type `ASTType.Pool`.
rW  r   rj  r  )r   r{  r~  r   r   rY  rq   r   r`  r  r!   )rU  r  r[  r\  r  s        r   r@   r@   Y  s     HH%&EX&J%%qMHH&(CA(CDIIhI/	
 uQx=	 )D    B1r7  c           
          [         R                  " S5      n[        [        R                  " [        R
                  U[         R                  " SU 5      5      5        [        US   5      $ )z:
Construct an AST node of type `ASTType.BooleanConstant`.
rW  rQ  r   )r   r{  r   r   rY  rr   r`  r!   )r7  r[  s     r   r,   r,   k  sQ     HH%&E115$))E5:Q	

 uQx=r   c                     [         R                  " S5      n[        [        R                  " [        R
                  XR                  5      5        [        US   5      $ )z7
Construct an AST node of type `ASTType.SymbolicAtom`.
rW  r   )r   r{  r   r   rY  rs   r   r!   )r^  r[  s     r   rL   rL   x  sE     HH%&Ed@@%U uQx=r   termguardsc                 d   [         R                  " S5      n[        [        R                  " [        R
                  UU R                  [         R                  " SU Vs/ s H  o3R                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf )z5
Construct an AST node of type `ASTType.Comparison`.
rW  rj  r  r   )
r   r{  r   r   rY  rt   r   r`  r  r!   )ro  rp  r[  r  s       r   r/   r/     s     HH%&E++IIHH&(@A(@AIIhF,	
 uQx=	 )As   B-
comparisonc           
          [         R                  " S5      n[        [        R                  " [        R
                  U[         R                  " SU 5      UR                  5      5        [        US   5      $ )z0
Construct an AST node of type `ASTType.Guard`.
rW  rQ  r   )	r   r{  r   r   rY  ru   r`  r   r!   )rr  ro  r[  s      r   r'   r'     sW     HH%&E&&tyy
/KTYY	

 uQx=r   literalr  c                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   UR                  [         R                  " SU Vs/ s H  oUR                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf )z=
Construct an AST node of type `ASTType.ConditionalLiteral`.
rW  r   rj  r  )r   r{  r~  r   r   rY  rv   r   r`  r  r!   )rU  rt  r  r[  r\  r  s         r   r1   r1     s     HH%&EX&J44qMLLHH&(CA(CDIIhI/	
	 uQx=	 )D   +B<
left_guardelementsright_guardc                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   Uc  [         R                  OUR                  [         R                  " SU Vs/ s H  ofR                  PM     sn5      [         R                  " S[        U5      5      Uc  [         R                  OUR                  5      5        [        US   5      $ s  snf )z4
Construct an AST node of type `ASTType.Aggregate`.
rW  r   rj  r  )r   r{  r~  r   r   rY  rw   r  r   r`  r  r!   )rU  rw  rx  ry  r[  r\  r  s          r   r%   r%     s     HH%&EX&J**qM#+DIIHH&(BA(BCIIhH.$,DII+2B2B	

 uQx= )Cs   >C-termsc                    [         R                  " S5      n[        [        R                  " [        R
                  U[         R                  " SU  Vs/ s H  o3R                  PM     sn5      [         R                  " S[        U 5      5      [         R                  " SU Vs/ s H  o3R                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf s  snf )z?
Construct an AST node of type `ASTType.BodyAggregateElement`.
rW  rj  r  r   )
r   r{  r   r   rY  rx   r   r`  r  r!   r{  r  r[  r  s       r   r+   r+     s     HH%&E77HH&(?A(?@IIhE
+HH&(CA(CDIIhI/	
	 uQx= )@(C   C1 C6functionc                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   Uc  [         R                  OUR                  [         R                  " SU5      [         R                  " SU Vs/ s H  owR                  PM     sn5      [         R                  " S[        U5      5      Uc  [         R                  OUR                  5      5        [        US   5      $ s  snf )z8
Construct an AST node of type `ASTType.BodyAggregate`.
rW  r   rQ  rj  r  )r   r{  r~  r   r   rY  ry   r  r   r`  r  r!   rU  rw  r  rx  ry  r[  r\  r  s           r   r*   r*          HH%&EX&J//qM#+DIIIIeX&HH&(BA(BCIIhH.$,DII+2B2B		
 uQx= )C   Dc                 d   [         R                  " S5      n[        [        R                  " [        R
                  U[         R                  " SU  Vs/ s H  o3R                  PM     sn5      [         R                  " S[        U 5      5      UR                  5      5        [        US   5      $ s  snf )z?
Construct an AST node of type `ASTType.HeadAggregateElement`.
rW  rj  r  r   )
r   r{  r   r   rY  rz   r   r`  r  r!   r}  s       r   r9   r9     s     HH%&E77HH&(?A(?@IIhE
+NN	
 uQx= )@s   B-c                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   Uc  [         R                  OUR                  [         R                  " SU5      [         R                  " SU Vs/ s H  owR                  PM     sn5      [         R                  " S[        U5      5      Uc  [         R                  OUR                  5      5        [        US   5      $ s  snf )z8
Construct an AST node of type `ASTType.HeadAggregate`.
rW  r   rQ  rj  r  )r   r{  r~  r   r   rY  r{   r  r   r`  r  r!   r  s           r   r8   r8     r  r  c                 l   [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SU Vs/ s H  oDR                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf )z6
Construct an AST node of type `ASTType.Disjunction`.
rW  r   rj  r  )r   r{  r~  r   r   rY  r|   r   r`  r  r!   rU  rx  r[  r\  r  s        r   r4   r4   (  s     HH%&EX&J,,qMHH&(BA(BCIIhH.	
 uQx=	 )Crl  sequence_typec                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SU5      [         R                  " SU Vs/ s H  oUR                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf )z9
Construct an AST node of type `ASTType.TheorySequence`.
rW  r   rQ  rj  r  )r   r{  r~  r   r   rY  r}   r`  r   r  r!   )rU  r  r{  r[  r\  r  s         r   rX   rX   :  s     HH%&EX&J00qMIIe]+HH&(?A(?@IIhE
+	
	 uQx=	 )@s   6Cc                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SUR                  5       5      [         R                  " SU Vs/ s H  oUR                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf )z9
Construct an AST node of type `ASTType.TheoryFunction`.
rW  r   rX  rj  r  )r   r{  r~  r   r   rY  r~   rb  r   r`  r  r!   )rU  r  r  r[  r\  r  s         r   rS   rS   M  s     HH%&EX&J00qMHH^T[[]3HH&(CA(CDIIhI/	
	 uQx=	 )D   C	operatorsc                    [         R                  " S5      nU  Vs/ s H(  n[         R                  " SUR                  5       5      PM*     nn[        [        R
                  " [        R                  U[         R                  " SU5      [         R                  " S[        U 5      5      UR                  5      5        [        US   5      $ s  snf )zD
Construct an AST node of type `ASTType.TheoryUnparsedTermElement`.
rW  rz  char*[]r  r   )r   r{  rb  r   r   rY  r   r`  r  r   r!   r  ro  r[  r  c_operatorss        r   r\   r\   `  s     HH%&E;DE9a488Hahhj19KE==HHY,IIhI/II	
 uQx= Fs   /Cc                 l   [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SU Vs/ s H  oDR                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf )z=
Construct an AST node of type `ASTType.TheoryUnparsedTerm`.
rW  r   rj  r  )r   r{  r~  r   r   rY  r   r   r`  r  r!   r  s        r   r[   r[   r  s     HH%&EX&J55qMHH&(BA(BCIIhH.	
 uQx=	 )Crl  operator_namec                    [         R                  " S5      n[        [        R                  " [        R
                  U[         R                  " SU R                  5       5      UR                  5      5        [        US   5      $ )z6
Construct an AST node of type `ASTType.TheoryGuard`.
rW  rX  r   )	r   r{  r   r   rY  r   rb  r   r!   )r  ro  r[  s      r   rT   rT     sc     HH%&E--HH^]%9%9%;<II		
 uQx=r   c                    [         R                  " S5      n[        [        R                  " [        R
                  U[         R                  " SU  Vs/ s H  o3R                  PM     sn5      [         R                  " S[        U 5      5      [         R                  " SU Vs/ s H  o3R                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf s  snf )z<
Construct an AST node of type `ASTType.TheoryAtomElement`.
rW  rj  r  r   )
r   r{  r   r   rY  r   r   r`  r  r!   r}  s       r   rP   rP     s     HH%&E44HH&(?A(?@IIhE
+HH&(CA(CDIIhI/	
	 uQx= )@(Cr~  guardc                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   UR                  [         R                  " SU Vs/ s H  ofR                  PM     sn5      [         R                  " S[        U5      5      Uc  [         R                  OUR                  5      5        [        US   5      $ s  snf )z5
Construct an AST node of type `ASTType.TheoryAtom`.
rW  r   rj  r  )r   r{  r~  r   r   rY  r   r   r`  r  r  r!   )rU  ro  rx  r  r[  r\  r  s          r   rN   rN     s     HH%&EX&J,,qMIIHH&(BA(BCIIhH.DIIEJJ	

 uQx= )Cs   +Csignatomc                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SU5      UR                  5      5        [        US   5      $ )z2
Construct an AST node of type `ASTType.Literal`.
rW  r   rQ  )
r   r{  r~  r   r   rY  r   r`  r   r!   )rU  r  r  r[  r\  s        r   r=   r=     sk     HH%&EX&J((qMIIeT"II	
 uQx=r   priorityc                 d   [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SUR                  5       5      [         R                  " SU5      [         R                  " SU5      5      5        [        US   5      $ )zC
Construct an AST node of type `ASTType.TheoryOperatorDefinition`.
rW  r   rX  rQ  )
r   r{  r~  r   r   rY  r   rb  r`  r!   )rU  r  r  ra  r[  r\  s         r   rV   rV     s     HH%&EX&J;;qMHH^T[[]3IIeX&IIe]+	
	 uQx=r   c                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SUR                  5       5      [         R                  " SU Vs/ s H  oUR                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf )z?
Construct an AST node of type `ASTType.TheoryTermDefinition`.
rW  r   rX  rj  r  )r   r{  r~  r   r   rY  r   rb  r   r`  r  r!   )rU  r  r  r[  r\  r  s         r   rZ   rZ     s     HH%&EX&J77qMHH^T[[]3HH&(CA(CDIIhI/	
	 uQx=	 )Dr  c                    [         R                  " S5      nU  Vs/ s H(  n[         R                  " SUR                  5       5      PM*     nn[        [        R
                  " [        R                  U[         R                  " SU5      [         R                  " S[        U 5      5      [         R                  " SUR                  5       5      5      5        [        US   5      $ s  snf )z@
Construct an AST node of type `ASTType.TheoryGuardDefinition`.
rW  rz  r  r  rX  r   )
r   r{  rb  r   r   rY  r   r`  r  r!   r  s        r   rU   rU     s     HH%&E;DE9a488Hahhj19KE88HHY,IIhI/HH^T[[]3	
 uQx= Fs   /C!	atom_typearityc                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SU5      [         R                  " SUR                  5       5      [         R                  " SU5      [         R                  " SUR                  5       5      Uc  [         R                  OUR                  5      5        [        US   5      $ )z?
Construct an AST node of type `ASTType.TheoryAtomDefinition`.
rW  r   rQ  rX  )r   r{  r~  r   r   rY  r   r`  rb  r  r   r!   )rU  r  r  r  ro  r  r[  r\  s           r   rO   rO   
  s     HH%&EX&J77qMIIeY'HH^T[[]3IIeU#HH^T[[]3DIIEJJ		
 uQx=r   headbodyc                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   UR                  [         R                  " SU Vs/ s H  oUR                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf )z/
Construct an AST node of type `ASTType.Rule`.
rW  r   rj  r  )r   r{  r~  r   r   rY  r   r   r`  r  r!   )rU  r  r  r[  r\  r  s         r   rF   rF   &  s     HH%&EX&J%%qMIIHH&(>A(>?IIhD	*	
	 uQx=	 )?rv  
is_defaultc                 N   [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SUR                  5       5      UR                  [         R                  " SU5      5      5        [        US   5      $ )z5
Construct an AST node of type `ASTType.Definition`.
rW  r   rX  rQ  )r   r{  r~  r   r   rY  r   rb  r   r`  r!   )rU  r  r7  r  r[  r\  s         r   r3   r3   9  s     HH%&EX&J++qMHH^T[[]3JJIIeZ(	
	 uQx=r   positivec                 d   [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SUR                  5       5      [         R                  " SU5      [         R                  " SU5      5      5        [        US   5      $ )z8
Construct an AST node of type `ASTType.ShowSignature`.
rW  r   rX  rQ  )
r   r{  r~  r   r   rY  r   rb  r`  r!   rU  r  r  r  r[  r\  s         r   rH   rH   L  s     HH%&EX&J//qMHH^T[[]3IIeU#IIeX&	
	 uQx=r   c                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   UR                  [         R                  " SU Vs/ s H  oUR                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf )z3
Construct an AST node of type `ASTType.ShowTerm`.
rW  r   rj  r  )r   r{  r~  r   r   rY  r   r   r`  r  r!   )rU  ro  r  r[  r\  r  s         r   rI   rI   _  s     HH%&EX&J**qMIIHH&(>A(>?IIhD	*	
	 uQx=	 )?rv  weightc                 @   [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   UR                  UR                  [         R                  " SU Vs/ s H  owR                  PM     sn5      [         R                  " S[        U5      5      [         R                  " SU Vs/ s H  owR                  PM     sn5      [         R                  " S[        U5      5      5	      5        [        US   5      $ s  snf s  snf )z3
Construct an AST node of type `ASTType.Minimize`.
rW  r   rj  r  )r   r{  r~  r   r   rY  r   r   r`  r  r!   )rU  r  r  r{  r  r[  r\  r  s           r   r?   r?   r  s     HH%&EX&J))qMKKMMHH&(?A(?@IIhE
+HH&(>A(>?IIhD	*
	
 uQx= )@(>s   6DD codec                 T   [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SUR                  5       5      [         R                  " SUR                  5       5      5      5        [        US   5      $ )z1
Construct an AST node of type `ASTType.Script`.
rW  r   rX  )	r   r{  r~  r   r   rY  r   rb  r!   )rU  r  r  r[  r\  s        r   rG   rG     s~     HH%&EX&J''qMHH^T[[]3HH^T[[]3	
 uQx=r   
parametersc                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SUR                  5       5      [         R                  " SU Vs/ s H  oUR                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf )z2
Construct an AST node of type `ASTType.Program`.
rW  r   rX  rj  r  )r   r{  r~  r   r   rY  r   rb  r   r`  r  r!   )rU  r  r  r[  r\  r  s         r   rB   rB     s     HH%&EX&J((qMHH^T[[]3HH&(DA(DEIIhJ0	
	 uQx=	 )Er  external_typec                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   UR                  [         R                  " SU Vs/ s H  ofR                  PM     sn5      [         R                  " S[        U5      5      UR                  5      5        [        US   5      $ s  snf )z3
Construct an AST node of type `ASTType.External`.
rW  r   rj  r  )r   r{  r~  r   r   rY  r   r   r`  r  r!   )rU  r  r  r  r[  r\  r  s          r   r6   r6     s     HH%&EX&J))qMIIHH&(>A(>?IIhD	*	

 uQx= )?s   +Cnode_unode_vc                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   UR                  UR                  [         R                  " SU Vs/ s H  ofR                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf )z/
Construct an AST node of type `ASTType.Edge`.
rW  r   rj  r  )r   r{  r~  r   r   rY  r   r   r`  r  r!   )rU  r  r  r  r[  r\  r  s          r   r5   r5     s     HH%&EX&J%%qMKKKKHH&(>A(>?IIhD	*	

 uQx=	 )?s   6Cbiasmodifierc                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   UR                  [         R                  " SU Vs/ s H  oR                  PM     sn5      [         R                  " S[        U5      5      UR                  UR                  UR                  5	      5        [        US   5      $ s  snf )z4
Construct an AST node of type `ASTType.Heuristic`.
rW  r   rj  r  )r   r{  r~  r   r   rY  r   r   r`  r  r!   )	rU  r  r  r  r  r  r[  r\  r  s	            r   r:   r:     s     HH%&EX&J**qMIIHH&(>A(>?IIhD	*IIMMMM
	
 uQx= )?s   +Cc                    [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   UR                  [         R                  " SU Vs/ s H  oUR                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf )z6
Construct an AST node of type `ASTType.ProjectAtom`.
rW  r   rj  r  )r   r{  r~  r   r   rY  r   r   r`  r  r!   )rU  r  r  r[  r\  r  s         r   rD   rD     s     HH%&EX&J--qMIIHH&(>A(>?IIhD	*	
	 uQx=	 )?rv  c                 d   [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SUR                  5       5      [         R                  " SU5      [         R                  " SU5      5      5        [        US   5      $ )z;
Construct an AST node of type `ASTType.ProjectSignature`.
rW  r   rX  rQ  )
r   r{  r~  r   r   rY  r   rb  r`  r!   r  s         r   rE   rE   	  s     HH%&EX&J22qMHH^T[[]3IIeU#IIeX&	
	 uQx=r   c                 d   [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SUR                  5       5      [         R                  " SU5      [         R                  " SU5      5      5        [        US   5      $ )z2
Construct an AST node of type `ASTType.Defined`.
rW  r   rX  rQ  )
r   r{  r~  r   r   rY  r   rb  r`  r!   r  s         r   r2   r2    	  s     HH%&EX&J((qMHH^T[[]3IIeU#IIeX&	
	 uQx=r   atomsc                 \   [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SUR                  5       5      [         R                  " SU Vs/ s H  ofR                  PM     sn5      [         R                  " S[        U5      5      [         R                  " SU Vs/ s H  ofR                  PM     sn5      [         R                  " S[        U5      5      5      5        [        US   5      $ s  snf s  snf )z;
Construct an AST node of type `ASTType.TheoryDefinition`.
rW  r   rX  rj  r  )r   r{  r~  r   r   rY  r   rb  r   r`  r  r!   )rU  r  r{  r  r[  r\  r  s          r   rR   rR   3	  s     HH%&EX&J22qMHH^T[[]3HH&(?A(?@IIhE
+HH&(?A(?@IIhE
+		
 uQx= )@(?s   D$D)comment_typec                 8   [         R                  " S5      n[        U 5      n[        [        R
                  " [        R                  UUS   [         R                  " SUR                  5       5      [         R                  " SU5      5      5        [        US   5      $ )z2
Construct an AST node of type `ASTType.Comment`.
rW  r   rX  rQ  )
r   r{  r~  r   r   rY  r   rb  r`  r!   )rU  r7  r  r[  r\  s        r   r-   r-   J	  sx     HH%&EX&J((qMHH^U\\^4IIe\*	
 uQx=r   )NN   )vri   collectionsr   enumr   	functoolsr   typingr   r   r   r	   r
   r   r   r   r   r   r   	_internalr   r   r   r   r   r   r   r   r   r  r   corer   r   r^  r   utilr   r    __all__r#   r&   r)   r.   r0   rJ   rQ   rW   rY   r_   r"   rK   rA   r>   r~  r  r"  r  r  r  r  rE  rQ  r$   r  r!   
def_externr  ra   rb   rC   r]   r;   r`   rM   r^   r(   r<   r7   r@   r,   rL   r/   r'   r1   r%   r+   r*   r9   r8   r4   rX   rS   r\   r[   rT   rP   rN   r=   rV   rZ   rU   rO   rF   r3   rH   rI   r?   rG   rB   r6   r5   r:   rD   rE   r2   rR   r-   )r?  s   0r   <module>r     s
  }~	   $   
 
 
  %  .CP2+k 2+j 6(W (V'  >7 &W . & &G &g #%% g T\ #%% \ ~z &z X ( 44499:: D--33A67:: 
 c68T5+{RSfheXc]HUOK	
 N N Nb *629PQ R "&#<C=<ud{#< g< V	<
 < 
<D "&#77ud{#7 g7 V	7
 7 
7t)R^$45 )RXO0 O0d   "x s s "8 V  "X c S S $'*25>A*x s 3 3 !.6smGJ,8  # $
3 
3 
  S (3- C "
c 
 
 
!$19#* sm #	
 	2 (3- C $  sm	
 # 	6 # # "  sm	
 # 	6( hsm  $X c (3- TW &X S Xc] s &# c c $ Xc] s $s # #  Xc] x}  $!-5c]CKC=,h c   $!-0AD*!.6sm*Xc] # # $  	
  C= 	88 3 hsm  &  S c c &H C  s s &x s (3- C &  C=	
 3- 	8X S   $h c x}  &!)1#GJ,8 S # Xc] s (
 3- 	
   	:( # Xc] s &x s 3 # RU &h c #   &!*23-@H.h s # # _,s   ;*S+