
    Xh}                         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y)z@Provides a post-lexer for implementing Python-style indentation.    )ABCabstractmethod)ListIterator   )	LarkError)PostLex)Tokenc                       e Zd Zy)DedentErrorN)__name__
__module____qualname__     A/var/www/html/myenv/lib/python3.12/site-packages/lark/indenter.pyr   r      s    r   r   c                   2   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y)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| _         dg| _        | j                  dkD  sJ y Nr   )r   r   tab_lenselfs    r   __init__zIndenter.__init__    s&    C||ar   tokenc              #     K   | j                   dkD  ry | |j                  dd      d   }|j                  d      |j                  d      | j                  z  z   }|| j                  d   kD  r?| j                  j                  |       t        j                  | j                  ||       y || j                  d   k  rP| j                  j                          t        j                  | j                  ||       || j                  d   k  rP|| j                  d   k7  rt        d|d| j                  d         y w)	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%   s)    a\\$*1-
!!#&)9)9$)?$,,)NND%%b))$$V,&&t'7'7UKK4,,R00!!%%'**4+;+;ZOO 4,,R00 **2..!]ceievevwyez"{|| /s   DE 1E c              #   n  K   |D ]  }|j                   | j                  k(  r| j                  |      E d {    n| |j                   | j                  v r| xj                  dz  c_        h|j                   | j
                  v s| xj                  dz  c_        | j                  dk\  rJ  t        | j                        dkD  rK| j                  j                          t        | j                  d       t        | j                        dkD  rK| j                  dgk(  sJ | j                         y 7 w)Nr   r    )typeNL_typer-   OPEN_PAREN_typesr   CLOSE_PAREN_typeslenr   r)   r
   r*   )r   streamr   s      r   _processzIndenter._process9   s     
	-EzzT\\)>>%000zzT222  A% t555  A% ''1,,,
	- $##$q(!!#(("-- $##$q(   QC':):)::' 1s#   3D5D3AD5$D5+A%D5#D5c                 B    d| _         dg| _        | j                  |      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      s0    s) 
}u }% }(;&%   $ $  $ $$s) $  $ $49 $  $
 $S $  $ $S $  $ $ $  $r   r   c                   0    e Zd ZdZdZg dZg dZdZdZdZ	y)	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      s)    
 G12KKGr   rK   N)rE   abcr   r   typingr   r   
exceptionsr   larkr	   lexerr
   r   r   rK   r   r   r   <module>r[      s@    B # ! !  	) 	p$w p$fX r   