o
    V۷i}                     @   s~   d Z ddlmZmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZ G dd	 d	eZG d
d de
eZG dd deZdS )z@Provides a post-lexer for implementing Python-style indentation.    )ABCabstractmethod)ListIterator   )	LarkError)PostLex)Tokenc                   @   s   e Zd ZdS )DedentErrorN)__name__
__module____qualname__ r   r   C/home/ubuntu/vllm_env/lib/python3.10/site-packages/lark/indenter.pyr
      s    r
   c                   @   s   e Zd ZU dZeed< ee ed< dddZdede	e fd	d
Z
dd Zdd Zedd ZeedefddZeedee fddZeedee fddZeedefddZeedefddZeedefddZdS )Indentera  This is a postlexer that "injects" indent/dedent tokens based on indentation.

    It keeps track of the current indentation, as well as the current level of parentheses.
    Inside parentheses, the indentation is ignored, and no indent/dedent tokens get generated.

    Note: This is an abstract class. To use it, inherit and implement all its abstract methods:
        - tab_len
        - NL_type
        - OPEN_PAREN_types, CLOSE_PAREN_types
        - INDENT_type, DEDENT_type

    See also: the ``postlex`` option in `Lark`.
    paren_levelindent_levelreturnNc                 C   s    d| _ dg| _| jdksJ d S Nr   )r   r   tab_lenselfr   r   r   __init__    s   zIndenter.__init__tokenc                 c   s    | j dkrd S |V  |ddd }|d|d| j  }|| jd kr8| j| t| j||V  d S || jd k rT| j	  t| j
||V  || jd k s?|| jd krftd|| jd f d S )Nr   
r    	z5Unexpected dedent to column %s. Expected dedent to %s)r   rsplitcountr   r   appendr	   new_borrow_posINDENT_typepopDEDENT_typer
   )r   r   
indent_strindentr   r   r   	handle_NL%   s    

zIndenter.handle_NLc                 c   s    |D ]6}|j | jkr| |E d H  n|V  |j | jv r%|  jd7  _q|j | jv r9|  jd8  _| jdks9J qt| jdkrT| j  t	| j
dV  t| jdksA| jdgks_J | jd S )Nr   r    )typeNL_typer'   OPEN_PAREN_typesr   CLOSE_PAREN_typeslenr   r#   r	   r$   )r   streamr   r   r   r   _process9   s    
zIndenter._processc                 C   s   d| _ dg| _| |S r   )r   r   r/   )r   r.   r   r   r   processL   s   
zIndenter.processc                 C   s   | j fS )N)r*   r   r   r   r   always_acceptR   s   zIndenter.always_acceptc                 C      t  )zThe name of the newline tokenNotImplementedErrorr   r   r   r   r*   V      zIndenter.NL_typec                 C   r2   )z/The names of the tokens that open a parenthesisr3   r   r   r   r   r+   \   r5   zIndenter.OPEN_PAREN_typesc                 C   r2   )z9The names of the tokens that close a parenthesis
        r3   r   r   r   r   r,   b   s   zIndenter.CLOSE_PAREN_typesc                 C   r2   )zeThe name of the token that starts an indentation in the grammar.

        See also: %declare
        r3   r   r   r   r   r"   i      zIndenter.INDENT_typec                 C   r2   )zbThe name of the token that end an indentation in the grammar.

        See also: %declare
        r3   r   r   r   r   r$   r   r6   zIndenter.DEDENT_typec                 C   r2   )z How many spaces does a tab equalr3   r   r   r   r   r   {   r5   zIndenter.tab_len)r   N)r   r   r   __doc__int__annotations__r   r   r	   r   r'   r/   r0   propertyr1   r   strr*   r+   r,   r"   r$   r   r   r   r   r   r      s8   
 

r   c                   @   s0   e Zd ZdZdZg dZg dZdZdZdZ	dS )	PythonIndenterzA postlexer that "injects" _INDENT/_DEDENT tokens based on indentation, according to the Python syntax.

    See also: the ``postlex`` option in `Lark`.
    _NEWLINE)LPARLSQBLBRACE)RPARRSQBRBRACE_INDENT_DEDENT   N)
r   r   r   r7   r*   r+   r,   r"   r$   r   r   r   r   r   r<      s    r<   N)r7   abcr   r   typingr   r   
exceptionsr   larkr   lexerr	   r
   r   r<   r   r   r   r   <module>   s    s