o
    Ae#,                     @   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y+   d dl	mZ Y nw 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.\-]+$Z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#   W/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/fontTools/feaLib/lexer.py__init__+   s   
zLexer.__init__c                 C      | S Nr#   r    r#   r#   r$   __iter__4      zLexer.__iter__c                 C      |   S r'   __next__r(   r#   r#   r$   next7      z
Lexer.nextc                 C   s&   	 |   \}}}|tjkr|||fS q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rt || }|d |k r+||d  nd }|dkrI|  jd7  _|  jd7  _| j| _	tj
d |fS |dkrk|  j|dkrVd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rtd|| d | j|k r|| j nd }|dkrt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r.|  jd7  _|  tj ||d | j }t|dk rtd|t|dkrtd|tj|s(td|tj||fS |tjv rW|  jd7  _|  tj ||| j }|dkrQt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r|tjv r|  tj tjt||| j d|fS |tjv r|  tj | j|ks|| 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 rx| j| j dkrx|  jd7  _t%&dd||d | jd  }	tj'|	|fS td|td| |)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_r5   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    r3   startr!   limitZcur_charZ	next_charZ
glyphclassr2   stringr#   r#   r$   r0   D   s   


 






  
zLexer.next_c                 C   sH   | j }|| jk r| j| |v r|d7 }|| jk r| j| |v s|| _ d S Nr   r   r   r   )r    Zvalidpr#   r#   r$   rI      
   
zLexer.scan_over_c                 C   sH   | j }|| jk r| j| |vr|d7 }|| jk r| j| |vs|| _ d S r]   r^   )r    Zstop_atr_   r#   r#   r$   rL      r`   zLexer.scan_until_c                 C   s   |   }| }| tj | tj d| d }tj|| j| j	d  dd}t
|dkr5td| ||  j	t
|d 7  _	tj|d |fS )Nz}\s*z\s*;r   )maxsplitr8   z-Expected '} %s;' to terminate anonymous blockr   )r5   striprL   r   rM   rI   rX   splitr   r   r   r   r   )r    tagr3   regexprc   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   rJ   rM   rW   rO   rU   ZCHAR_LETTER_rT   rQ   rX   compilerR   r   rN   r%   r)   r.   r-   r5   r0   rI   rL   rf   r#   r#   r#   r$   r      sF    

	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   featurefilepathrl   )r    Zfeaturefilerl   r#   r#   r$   r%      s   

zIncludingLexer.__init__c                 C   r&   r'   r#   r(   r#   r#   r$   r)      r*   zIncludingLexer.__iter__c                 C   r+   r'   r,   r(   r#   r#   r$   r.      r/   zIncludingLexer.nextc              
   C   s2  | j r| j d }z	t|\}}}W n ty   | j   Y q w |tju r|dkr| \}}}|tjur:td|tj	
|rC|}n!| jd urL| j}	n| jd urYtj	| j}	nt }	tj	|	|}t| j dkrptd|z| j | | W q ty }
 zt|||
d }
~
ww |||fS | j st )Nr@   zExpected file name   zToo many recursive includes)rn   r.   rK   popr   r   r   r   ospathisabsrl   ro   dirnamegetcwdjoinr   appendrm   FileNotFoundErrorr   )r    lexerr1   r2   r3   Z
fname_typeZfname_tokenZfname_locationrt   Zcurpatherrr#   r#   r$   r-      s>   







$zIncludingLexer.__next__c                 C   sX   t | dr| d}}n| d}}t|ddd}| }t|dd }|r'|  t||S )NreadFTrzutf-8)encodingname)hasattropenr}   getattrcloser   )Zfile_or_pathfileobjclosingr"   datar#   r#   r$   rm     s   


zIncludingLexer.make_lexer_c                 C   s   | j d |S )Nrp   )rn   rf   )r    rd   r#   r#   r$   rf     s   z#IncludingLexer.scan_anonymous_block)rg   rh   ri   __doc__r%   r)   r.   r-   staticmethodrm   rf   r#   r#   r#   r$   rk      s    '
rk   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.   rn   r(   r#   r#   r$   r-   "  s   zNonIncludingLexer.__next__N)rg   rh   ri   r   r-   r#   r#   r#   r$   r     s    r   )ZfontTools.feaLib.errorr   r   ZfontTools.feaLib.locationr   rX   rs   r   ImportErrorZfontTools.miscobjectr   rk   r   r#   r#   r#   r$   <module>   s     8[