Edit File: parse_expr.cpython-36.pyc
3 �e � @ s: d dl Z e jd�Ze jd�Ze jd�Zdd� Zdd� ZdS ) � Nz([a-z]+[a-z0-9_]+)z0x[0-9a-f]+z^[()<>+*/&0-9-]+$c C sD | j d�}|jd�r"|dd� }ntjd|�s2|S t|d�}t|�S )zn Convert an hexadecimal number to decimal number (as string). Callback used by parseExpression(). r �0x� Nz[a-f]� )�group� startswith�re�search�int�str)�regs�text�value� r �C/tmp/pip-build-uv1wutoy/python-ptrace/ptrace/debugger/parse_expr.py�replaceHexadecimal s r c s� |j � }|}d|kr td| ��|j� }� fdd�}tjt|�}tj||�}tj|�sbtd| ��|j dd�}yt |�}W n tk r� td| ��Y nX |S )a� Parse an expression. Syntax: - "10": decimal number - "0x10": hexadecimal number - "eax": register value - "a+b", "a-b", "a*b", "a/b", "a**b", "a<<b", "a>>b": operators >>> from ptrace.mockup import FakeProcess >>> process = FakeProcess() >>> parseExpression(process, "1+1") 2 >>> process.setreg("eax", 3) >>> parseExpression(process, "eax*0x10") 48 � zSpace are forbidden: %rc s | j d�}� j|�}t|�S )N� )r Zgetregr )r �namer )�processr r �readRegister5 s z%parseExpression.<locals>.readRegisterzInvalid expression: %r�/z//)�strip� ValueError�lower�HEXADECIMAL_REGEX�subr �REGISTER_REGEX� EXPR_REGEX�match�replace�eval�SyntaxError)r r � orig_textr r r )r r �parseExpression s r# )r �compiler r r r r# r r r r �<module> s