o
    ä›ef  ã                   @   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g d¢Zdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚFormula)Ú__sÚ__parserÚ__sheet_refsÚ__xcall_refsc              
   C   sh   z || _ t |¡}t |¡| _| j ¡  | jj| _| jj	| _
W d S  ty3 } zt d| ¡‚d }~ww )Nzcan't parse formula )Ú_Formula__sr   ÚLexerr   ÚParserÚ_Formula__parserÚformulaÚsheet_referencesÚ_Formula__sheet_refsÚxcall_referencesÚ_Formula__xcall_refsr   ÚFormulaParseException)ÚselfÚsÚlexerÚe© r   úD/var/www/html/venv/lib/python3.10/site-packages/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   ÚpatchesÚoffsetÚidxr   r   r   Úpatch_references   s   6ÿ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"   Úantlrr   Úobjectr   r   r   r   r   Ú<module>   s   