o
    b²“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   úA/home/ubuntu/.local/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