
    
`i}                         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	e          Z G d
 de
e          Z G d de          ZdS )z@Provides a post-lexer for implementing Python-style indentation.    )ABCabstractmethod)ListIterator   )	LarkError)PostLex)Tokenc                       e Zd ZdS )DedentErrorN)__name__
__module____qualname__     a/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/lark/indenter.pyr   r      s        Dr   r   c                      e Zd ZU dZeed<   ee         ed<   ddZdede	e         fdZ
d	 Zd
 Zed             Zeedefd                        Zeedee         fd                        Zeedee         fd                        Zeedefd                        Zeedefd                        Zeedef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                 >    d| _         dg| _        | j        dk    sJ d S Nr   )r   r   tab_lenselfs    r   __init__zIndenter.__init__    s-    C|ar   tokenc              #   p  K   | j         dk    rd S |V  |                    dd          d         }|                    d          |                    d          | j        z  z   }|| j        d         k    r9| j                            |           t          j        | j        ||          V  d S || j        d         k     rG| j        	                                 t          j        | j
        ||          V  || j        d         k     G|| j        d         k    r t          d|d| j        d                   d S )	Nr   
r    	zUnexpected dedent to column z. Expected dedent to )r   rsplitcountr   r   appendr
   new_borrow_posINDENT_typepopDEDENT_typer   )r   r   
indent_strindents       r   	handle_NLzIndenter.handle_NL%   sV     aF\\$**1-
!!#&&)9)9$)?)?$,)NND%b)))$$V,,,&t'7UKKKKKKK4,R000!%%'''*4+;ZOOOOO 4,R000 *2...!k]c]c]ceievwyezez"{||| /.r   c              #     K   |D ]|}|j         | j        k    r|                     |          E d {V  n|V  |j         | j        v r| xj        dz  c_        Q|j         | j        v r| xj        dz  c_        | j        dk    sJ }t          | j                  dk    rH| j                                         t          | j
        d          V  t          | j                  dk    H| 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   s      r   _processzIndenter._process9   s9      
	- 
	-EzT\))>>%0000000000zT222  A%   t555  A%  '1,,,,$#$$q((!!###("----- $#$$q((  QC'''):'''''r   c                 J    d| _         dg| _        |                     |          S r   )r   r   r6   )r   r5   s     r   processzIndenter.processL   s&    C}}V$$$r   c                     | j         fS )N)r1   r   s    r   always_acceptzIndenter.always_acceptR   s    r   c                     t                      )zThe name of the newline tokenNotImplementedErrorr   s    r   r1   zIndenter.NL_typeV        "###r   c                     t                      )z/The names of the tokens that open a parenthesisr<   r   s    r   r2   zIndenter.OPEN_PAREN_types\   r>   r   c                     t                      )z9The names of the tokens that close a parenthesis
        r<   r   s    r   r3   zIndenter.CLOSE_PAREN_typesb   s    
 "###r   c                     t                      )zeThe name of the token that starts an indentation in the grammar.

        See also: %declare
        r<   r   s    r   r(   zIndenter.INDENT_typei        "###r   c                     t                      )zbThe name of the token that end an indentation in the grammar.

        See also: %declare
        r<   r   s    r   r*   zIndenter.DEDENT_typer   rB   r   c                     t                      )z How many spaces does a tab equalr<   r   s    r   r   zIndenter.tab_len{   r>   r   )r   N)r   r   r   __doc__int__annotations__r   r   r
   r   r-   r6   r8   propertyr:   r   strr1   r2   r3   r(   r*   r   r   r   r   r   r      s          s)       
}u }% } } } }(; ; ;&% % %   X $ $ $ $ ^ X$ $$s) $ $ $ ^ X$ $49 $ $ $ ^ X$
 $S $ $ $ ^ X$ $S $ $ $ ^ X$ $ $ $ $ ^ X$ $ $r   r   c                   2    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   rE   r1   r2   r3   r(   r*   r   r   r   r   rK   rK      sF         
 G111222KKGGGr   rK   N)rE   abcr   r   typingr   r   
exceptionsr   larkr	   lexerr
   r   r   rK   r   r   r   <module>r[      s   B B # # # # # # # # ! ! ! ! ! ! ! ! ! ! ! ! ! !            	 	 	 	 	) 	 	 	p$ p$ p$ p$ p$w p$ p$ p$f    X     r   