U
    >Kef                     @   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-x1drl5t4/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   