a
    w=ic$,                     @   s   d dl mZmZ d dlmZ d dlZd dlZzd dlZW n eyV   d dl	mZ Y n0 G dd de
ZG dd de
ZG d	d
 d
eZdS )    )FeatureLibErrorIncludedFeaNotFound)FeatureLibLocationN)cythonc                   @   s   e Zd ZdZdZdZeeefZdZdZdZ	dZ
dZd	Zd
ZdZdZdZdZdZdZdZdZdZed Zee d ZedZdZdZdd Zdd Zdd Z dd Z!d d! Z"d"d# Z#d$d% Z$d&d' Z%d(d) Z&d*S )+LexerNUMBERHEXADECIMALOCTALFLOATSTRINGNAMEFILENAME
GLYPHCLASSCIDSYMBOLCOMMENTNEWLINEANONYMOUS_BLOCKz 	z
z,;:-+'{}[]<>()=
01234567890123456789ABCDEFabcdefZ4ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzz	_+*:.^~!\z
_.+*:^~!/-z^[A-Za-z_0-9.\-]+$NORMALc                 C   s4   || _ d| _d| _d| _|| _t|| _tj| _	d S )N   r   )
	filename_line_pos_line_start_text_lentext_length_r   MODE_NORMAL_mode_)selftextfilename r$   g/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/fontTools/feaLib/lexer.py__init__+   s    
zLexer.__init__c                 C   s   | S Nr$   r!   r$   r$   r%   __iter__4   s    zLexer.__iter__c                 C   s   |   S r'   __next__r(   r$   r$   r%   next7   s    z
Lexer.nextc                 C   s(   |   \}}}|tjkr |||fS q d S r'   )next_r   r   )r!   
token_typetokenlocationr$   r$   r%   r+   :   s    
zLexer.__next__c                 C   s$   | j | j d }t| jpd| j|S )Nr   z
<features>)r   r   r   r   r   )r!   columnr$   r$   r%   	location_@   s    zLexer.location_c           
      C   s  |  tj |  }| j}| j}t|}||kr6t || }|d |k rV||d  nd }|dkr|  jd7  _|  jd7  _| j| _	tj
d |fS |dkr|  j|dkrdnd7  _|  jd7  _| j| _	tj
d |fS |dkr| tj tj||| j |fS | jtju r|dkr$td|| d | j|k rD|| j nd }|dkr\td	||  jd7  _tj| _tj||d | jd  |fS |d
kr|tjv r|  jd7  _|  tj tjt||d | j d|fS |dkrj|  jd7  _|  tj ||d | j }t|dk r.td|t|dkrFtd|tj|s^td|tj||fS |tjv r|  jd7  _|  tj ||| j }|dkrtj| _tj||fS |dkr|dv r|  jd7  _|  tj tjt||| j d|fS |dkrD|tjv rD|  tj tjt||| j d|fS |tjv r|  tj | j|ksx|| j dkrtjt||| j d|fS |  d |  tj tj t!||| j |fS |dkr\|tjv r\|  jd7  _|  tj | j|ks|| j dkr,tjt||| j d|fS |  d |  tj tj t!||| j |fS |tj"v r|  jd7  _tj#||fS |dkr|  jd7  _| d | j| j$k r| j| j dkr|  jd7  _t%&dd||d | jd  }	tj'|	|fS td|td| |d S )Nr   
   #(zExpected '(' before file name)zExpected ')' after file name\
   @zExpected glyph class name?   z7Glyph class names must not be longer than 63 characterszOGlyph class names must consist of letters, digits, underscore, period or hypheninclude0xX      .-"z[
] z Expected '"' to terminate stringzUnexpected character: %r)(
scan_over_r   CHAR_WHITESPACE_r2   r   r   r   StopIterationr   r   r   scan_until_CHAR_NEWLINE_r   r    MODE_FILENAME_r   r   r   CHAR_DIGIT_r   intCHAR_NAME_CONTINUATION_RE_GLYPHCLASSmatchr   CHAR_NAME_START_r   CHAR_HEXDIGIT_r   r	   r   r
   floatCHAR_SYMBOL_r   r   resubr   )
r!   r0   startr"   limitZcur_charZ	next_charZ
glyphclassr/   stringr$   r$   r%   r-   D   s    





 






  
zLexer.next_c                 C   s2   | j }|| jk r(| j| |v r(|d7 }q|| _ d S Nr   r   r   r   )r!   Zvalidpr$   r$   r%   rF      s    
zLexer.scan_over_c                 C   s2   | j }|| jk r(| j| |vr(|d7 }q|| _ d S rZ   r[   )r!   Zstop_atr\   r$   r$   r%   rI      s    
zLexer.scan_until_c                 C   s   |   }| }| tj | tj d| d }tj|| j| j	d  dd}t
|dkrjtd| ||  j	t
|d 7  _	tj|d |fS )Nz}\s*z\s*;r   )maxsplitr5   z-Expected '} %s;' to terminate anonymous blockr   )r2   striprI   r   rJ   rF   rU   splitr   r   r   r   r   )r!   tagr0   regexpr_   r$   r$   r%   scan_anonymous_block   s    zLexer.scan_anonymous_blockN)'__name__
__module____qualname__r   r   r	   ZNUMBERSr
   r   r   r   r   r   r   r   r   r   rG   rJ   rT   rL   rR   ZCHAR_LETTER_rQ   rN   rU   compilerO   r   rK   r&   r)   r,   r+   r2   r-   rF   rI   rb   r$   r$   r$   r%   r      sD   

	er   c                   @   sJ   e Zd ZdZddddZdd Zdd	 Zd
d Zedd Z	dd Z
dS )IncludingLexera  A Lexer that follows include statements.

    The OpenType feature file specification states that due to
    historical reasons, relative imports should be resolved in this 
    order:

    1. If the source font is UFO format, then relative to the UFO's
       font directory
    2. relative to the top-level include file
    3. relative to the parent include file

    We only support 1 (via includeDir) and 2.
    N)
includeDirc                C   s&   |  |g| _| jd j| _|| _dS )aO  Initializes an IncludingLexer.

        Behavior:
            If includeDir is passed, it will be used to determine the top-level
            include directory to use for all encountered include statements. If it is
            not passed, ``os.path.dirname(featurefile)`` will be considered the
            include directory.
        r   N)make_lexer_lexers_r   featurefilepathrh   )r!   Zfeaturefilerh   r$   r$   r%   r&      s    
zIncludingLexer.__init__c                 C   s   | S r'   r$   r(   r$   r$   r%   r)      s    zIncludingLexer.__iter__c                 C   s   |   S r'   r*   r(   r$   r$   r%   r,      s    zIncludingLexer.nextc              
   C   sL  | j rB| j d }zt|\}}}W n  tyD   | j   Y q Y n0 |tju r6|dkr6| \}}}|tjur~td|tj	
|r|}nB| jd ur| j}	n"| jd urtj	| j}	nt }	tj	|	|}t| j dkrtd|z| j | | W n2 ty2 }
 zt|||
W Y d }
~
n
d }
~
0 0 q |||fS q t d S )Nr=   zExpected file name   zToo many recursive includes)rj   r,   rH   popr   r   r   r   ospathisabsrh   rk   dirnamegetcwdjoinr   appendri   FileNotFoundErrorr   )r!   lexerr.   r/   r0   Z
fname_typeZfname_tokenZfname_locationrp   Zcurpatherrr$   r$   r%   r+      s6    







$zIncludingLexer.__next__c                 C   sX   t | dr| d }}n| d }}t|ddd}| }t|dd }|rN|  t||S )NreadFTrzutf-8)encodingname)hasattropenry   getattrcloser   )Zfile_or_pathfileobjclosingr#   datar$   r$   r%   ri     s    

zIncludingLexer.make_lexer_c                 C   s   | j d |S )Nrl   )rj   rb   )r!   r`   r$   r$   r%   rb     s    z#IncludingLexer.scan_anonymous_block)rc   rd   re   __doc__r&   r)   r,   r+   staticmethodri   rb   r$   r$   r$   r%   rg      s   '
rg   c                   @   s   e Zd ZdZdd ZdS )NonIncludingLexerzBLexer that does not follow `include` statements, emits them as-is.c                 C   s   t | jd S )Nr   )r,   rj   r(   r$   r$   r%   r+   "  s    zNonIncludingLexer.__next__N)rc   rd   re   r   r+   r$   r$   r$   r%   r     s   r   )ZfontTools.feaLib.errorr   r   ZfontTools.feaLib.locationr   rU   ro   r   ImportErrorZfontTools.miscobjectr   rg   r   r$   r$   r$   r%   <module>   s    8[