o
    §ƒðj®
  ã                   @   s`   d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
mZmZmZ G dd„ deƒZdd„ Zd	S )
aƒ  
This module implements the functionality to take any Python expression as a
string and fix all numbers and other things before evaluating it,
thus

1/2

returns

Integer(1)/Integer(2)

We use the ast module for this. It is well documented at docs.python.org.

Some tips to understand how this works: use dump() to get a nice
representation of any node. Then write a string of what you want to get,
e.g. "Integer(1)", parse it, dump it and you'll see that you need to do
"Call(Name('Integer', Load()), [node], [], None, None)". You do not need
to bother with lineno and col_offset, just call fix_missing_locations()
before returning the node.
é    )ÚBasic)ÚSympifyError)ÚparseÚNodeTransformerÚCallÚNameÚLoadÚfix_missing_locationsÚConstantÚTuplec                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
Ú	Transformc                 C   s   t  | ¡ || _|| _d S )N)r   Ú__init__Ú
local_dictÚglobal_dict)Úselfr   r   © r   úš/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/venv/lib/python3.10/site-packages/sympy/parsing/ast_parser.pyr      s   

zTransform.__init__c                 C   sT   t |jtƒrtttdtƒ ƒ|gg d�ƒS t |jtƒr(tttdtƒ ƒ|gg d�ƒS |S )NÚInteger©ÚfuncÚargsÚkeywordsÚFloat)Ú
isinstanceÚvalueÚintr	   r   r   r   Úfloat)r   Únoder   r   r   Úvisit_Constant#   s   ÿÿzTransform.visit_Constantc                 C   st   |j | jv r|S |j | jv r"| j|j  }t|ttfƒst|ƒr!|S n|j dv r)|S ttt	dt
ƒ ƒt|j ƒgg d�ƒS )N)ÚTrueÚFalseÚSymbolr   )Úidr   r   r   r   ÚtypeÚcallabler	   r   r   r   r
   )r   r   Úname_objr   r   r   Ú
visit_Name,   s   ÿ
ÿzTransform.visit_Namec                    sL   ‡ fdd„|j j D ƒ}ˆ  |j¡}ttdtƒ ƒt|tƒ ƒ|gg d�}t|ƒS )Nc                    s   g | ]}ˆ   |¡‘qS r   )Úvisit)Ú.0Úarg©r   r   r   Ú
<listcomp>:   s    z*Transform.visit_Lambda.<locals>.<listcomp>ÚLambdar   )r   r'   Úbodyr   r   r   r   r	   )r   r   r   r-   Únr   r*   r   Úvisit_Lambda9   s   ÿzTransform.visit_LambdaN)Ú__name__Ú
__module__Ú__qualname__r   r   r&   r/   r   r   r   r   r      s
    	r   c                 C   sj   i }t d|ƒ z
t|  ¡ dd�}W n ty    tdt| ƒ ƒ‚w t||ƒ |¡}t|ddƒ}t	|||ƒS )z³
    Converts the string "s" to a SymPy expression, in local_dict.

    It converts all numbers to Integers before feeding it to Python and
    automatically creates Symbols.
    zfrom sympy import *Úeval)ÚmodezCannot parse %s.z<string>)
Úexecr   ÚstripÚSyntaxErrorr   Úreprr   r'   Úcompiler3   )Úsr   r   ÚaÚer   r   r   Ú
parse_expr@   s   
ÿr=   N)Ú__doc__Úsympy.core.basicr   Úsympy.core.sympifyr   Úastr   r   r   r   r   r	   r
   r   r   r=   r   r   r   r   Ú<module>   s    ($