o
    l^Ufm+                     @   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,;:-+'{}[]<>()=
0123456789Z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"   6lib/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j|std|tj||fS |tjv rK|  jd7  _|  tj ||| j }|dkrEtj| _tj||fS |dkrp|dv rp|  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rq|  jd7  _| d | j| j$k rl| j| j dkrl|  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 namezOGlyph class names must consist of letters, digits, underscore, period or hypheninclude0ZxX      .-"z[
] z Expected '"' to terminate stringzUnexpected character: %r)(
scan_over_r   CHAR_WHITESPACE_r4   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   r2   startr    limitZcur_charZ	next_charZ
glyphclassr1   stringr"   r"   r#   r/   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#   rF      
   
zLexer.scan_over_c                 C   sH   | j }|| jk r| j| |vr|d7 }|| jk r| j| |vs|| _ d S rZ   r[   )r   Zstop_atr\   r"   r"   r#   rI      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   )maxsplitr7   z-Expected '} %s;' to terminate anonymous blockr   )r4   striprI   r   rJ   rF   rU   splitr   r   r   r   r   )r   tagr2   Z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,   r4   r/   rF   rI   rb   r"   r"   r"   r#   r      sF    

	a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   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 n ty }
 zt|||
d }
~
ww |||fS | j st )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   Zlexerr0   r1   r2   Z
fname_typeZfname_tokenZfname_locationrp   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openrx   getattrcloser   )Zfile_or_pathZfileobjclosingr!   datar"   r"   r#   ri   
  s   


zIncludingLexer.make_lexer_c                 C   s   | j d |S )Nrl   )rj   rb   )r   ra   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     4[