î
nÐR\f  ã               @   sL   d  d l  m Z m Z d d l Z d  d l m Z Gd 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   s˜   yY | |  _  t j | ƒ } t j | ƒ |  _ |  j j ƒ  |  j j |  _ |  j j	 |  _
 Wn8 t k
 r“ } z t j d | ƒ ‚ WYd  d  } ~ Xn Xd  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ÚsZlexerÚe© r   ú5/var/www/dbchiro/venv/build/xlwt/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   s_   xX | D]P \ } } |  j  j d  | … t j d | ƒ |  j  j | d d  … |  j  _ q Wd  S)Nz<Hé   )r	   ÚrpnÚstructÚpack)r   ZpatchesÚoffsetÚidxr   r   r   Úpatch_references   s    zFormula.patch_referencesc             C   s   |  j  S)N)r   )r   r   r   r   Útext   s    zFormula.textc             C   s&   t  j 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

        z<H)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   