o
    @aB                     @   s<   d Z ddlZddlmZ ddlmZ G dd deejZdS )z-Turns f-strings to format syntax with modulus    N)Transformation)PythranSyntaxErrorc                   @   s   e Zd ZdZdd ZdS )RemoveFStringsaj  Turns f-strings to format syntax with modulus

    >>> import gast as ast
    >>> from pythran import passmanager, backend
    >>> node = ast.parse("f'a = {1+1:4d}; b = {b:s};'")
    >>> pm = passmanager.PassManager("test")
    >>> _, node = pm.apply(RemoveFStrings, node)
    >>> print(pm.dump(backend.Python, node))
    ('a = %4d; b = %s;' % ((1 + 1), b))
    c                 C   s   t |jdkrt|jd tjs|jd S tdd |jD s!|S d}g }|jD ]7}t|tjr:||jdd7 }q(t|tjr^|d7 }|j	d u rNt
d|||j	jd j7 }||j q(ttjtj|d d	t tj|t d
dS )N   r   c                 s   s    | ]	}t |tjV  qd S )N)
isinstanceastFormattedValue).0value r   I/usr/lib/python3/dist-packages/pythran/transformations/remove_fstrings.py	<genexpr>   s    
z1RemoveFStrings.visit_JoinedStr.<locals>.<genexpr> %z%%z0f-strings without format specifier not supported)r
   kind)eltsctx)leftopright)lenvaluesr   r   r   anyZConstantr
   replaceformat_specr   appendNotImplementedErrorZBinOpZModZTupleZLoad)selfZnodeZbase_strelementsr
   r   r   r   visit_JoinedStr   s6   


zRemoveFStrings.visit_JoinedStrN)__name__
__module____qualname____doc__r   r   r   r   r   r   	   s    r   )	r#   Zgastr   Zpythran.passmanagerr   Zpythran.syntaxr   ZNodeTransformerr   r   r   r   r   <module>   s
    