U
    ‰df  ã                   @   s8   d dl mZmZ ddlZd dlmZ G dd„ deƒZdS )é   )ÚExcelFormulaParserÚExcelFormulaLexeré    N)ÚANTLRExceptionc                   @   s@   e Zd ZddddgZdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ ZdS )ÚFormulaZ__sZ__parserZ__sheet_refsZ__xcall_refsc              
   C   st   z>|| _ t |¡}t |¡| _| j ¡  | jj| _| jj	| _
W n0 tk
rn } zt d| ¡‚W 5 d }~X Y nX d S )Nzcan't parse formula )Ú_Formula__sr   ZLexerr   ÚParserÚ_Formula__parserZformulaZsheet_referencesÚ_Formula__sheet_refsZxcall_referencesÚ_Formula__xcall_refsr   ZFormulaParseException)ÚselfÚsÚlexerÚe© r   ú5/tmp/pip-unpacked-wheel-xnx7fvnv/xlwt/ExcelFormula.pyÚ__init__   s    


zFormula.__init__c                 C   s   | j | jfS ©N)r
   r   ©r   r   r   r   Úget_references   s    zFormula.get_referencesc                 C   sF   |D ]<\}}| j jd |… t d|¡ | j j|d d …  | j _qd S )Nú<Hé   )r	   ÚrpnÚstructÚpack)r   ZpatchesÚoffsetÚidxr   r   r   Úpatch_references   s    zFormula.patch_referencesc                 C   s   | j S r   )r   r   r   r   r   Útext   s    zFormula.textc                 C   s   t  dt| jjƒ¡| jj S )zñ
        Offset    Size    Contents
        0         2       Size of the following formula data (sz)
        2         sz      Formula data (RPN token array)
        [2+sz]    var.    (optional) Additional data for specific tokens

        r   )r   r   Úlenr	   r   r   r   r   r   r   "   s    zFormula.rpnN)	Ú__name__Ú
__module__Ú__qualname__Ú	__slots__r   r   r   r   r   r   r   r   r   r      s   r   )Ú r   r   r   Zantlrr   Úobjectr   r   r   r   r   Ú<module>   s   