a
    
d                     @   sH   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 )a  PyParser-related utilities.

This module collects various utilities related to the parse trees produced by
the pyparser.

  GetLogicalLine: produces a list of tokens from the logical lines within a
    range.
  GetTokensInSubRange: produces a sublist of tokens from a current token list
    within a range.
  GetTokenIndex: Get the index of a token.
  GetNextTokenIndex: Get the index of the next token after a given position.
  GetPrevTokenIndex: Get the index of the previous token before a given
    position.
  TokenStart: Convenience function to return the token's start as a tuple.
  TokenEnd: Convenience function to return the token's end as a tuple.
c                 C   sV   t |}t|}g }| D ]8}|j|kr* qR|j|ks>|j|kr|t|j| q|S )zDGet a list of tokens within the node's range from the logical lines.)
TokenStartTokenEndstartendextendGetTokensInSubRangetokens)Zlogical_linesnoder   r   r   line r
   e/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/yapf/pyparser/pyparser_utils.pyGetLogicalLine    s    
r   c                 C   sH   t |}t|}g }| D ]*}|j|jf}||kr||k r|| q|S )z-Get a subset of tokens representing the node.)r   r   linenocolumnappend)r   r   r   r   Ztokens_in_rangetokZ	tok_ranger
   r
   r   r   /   s    r   c                 C   s.   t | D ] \}}|j|jf|kr|  S qdS )z"Get the index of the token at pos.N	enumerater   r   r   posindextokenr
   r
   r   GetTokenIndex=   s    
r   c                 C   s.   t | D ] \}}|j|jf|kr|  S qdS )z*Get the index of the next token after pos.Nr   r   r
   r
   r   GetNextTokenIndexF   s    
r   c                 C   s:   t | D ],\}}|dkr|j|jf|kr|d   S qdS )z/Get the index of the previous token before pos.       Nr   r   r
   r
   r   GetPrevTokenIndexO   s    r   c                 C   s   | j | jfS N)r   
col_offsetr   r
   r
   r   r   X   s    r   c                 C   s   | j | jfS r   )
end_linenoend_col_offsetr   r
   r
   r   r   \   s    r   c                 C   s    dd l }t|j| ddd d S )Nr   T   )include_attributesindent)astprintdump)r   r$   r
   r
   r   AstDumpe   s    r'   N)	__doc__r   r   r   r   r   r   r   r'   r
   r
   r
   r   <module>   s   				