o
    >Di                     @  s   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZmZmZ d dlmZmZ er>d dlmZ d dlmZ dddZG dd dZdS )    )annotationsN)contextmanager)TYPE_CHECKING	GeneratorMatchPatterncastoverload)BlockElementDocument)Literal)Parsertextstrreturnc                 C  s   |  ddS )Nz

)replace)r    r   E/var/www/Datamplify/venv/lib/python3.10/site-packages/marko/source.py_preprocess_text   s   r   c                   @  s   e Zd ZU dZded< d=dd	Zed>ddZed?ddZd@ddZ	d>ddZ
edAddZedBddZedCddZdDd"d#ZeejdEd&d'ZdFd(d)ZedGdHd-d.ZedGdId1d.ZdJdKd3d.ZdLd4d5ZdLd6d7ZdLd8d9ZdLd:d;Zd<S )MSourcez%Wrapper class on content to be parsedr   parserr   r   r   Nonec                 C  s0   t || _d| _d| _g | _d | _t | _d S )Nr   )	r   _bufferpos_anchor_statesmatchtypesSimpleNamespacecontext)selfr   r   r   r   __init__   s   
zSource.__init__r
   c                 C  s   | j std| j d S )z"Returns the current element state.Need to push a state first.)r   RuntimeErrorr!   r   r   r   state#   s   
zSource.stater   c                 C  s   | j stdtt| j d S )zAReturns the root element, which is at the bottom of self._states.r#   r   )r   r%   r   r   r&   r   r   r   root*   s   zSource.rootelementc                 C  s   | j | dS )z$Push a new state to the state stack.N)r   appendr!   r)   r   r   r   
push_state1   s   zSource.push_statec                 C  s
   | j  S )zPop the top most state.)r   popr&   r   r   r   	pop_state5   s   
zSource.pop_stateGenerator[Source, None, None]c                 c  s    |  | | V  |   dS )z4A context manager to enable a new state temporarily.N)r,   r.   r+   r   r   r   under_state9   s   
zSource.under_stateboolc                 C  s   | j t| jkS )z-Indicates whether the source reaches the end.)r   lenr   r&   r   r   r   	exhausted@   s   zSource.exhaustedc                 C  s   d dd | jD S )z%The prefix of each line when parsing. c                 s  s    | ]}|j V  qd S N)_prefix).0sr   r   r   	<genexpr>H   s    z Source.prefix.<locals>.<genexpr>)joinr   r&   r   r   r   prefixE   s   zSource.prefixregexpPattern[str] | strr   intMatch[str] | Nonec                 C  s"   t |tr
t|}|| j|S r5   )
isinstancer   recompiler   r   )r!   r<   r   r   r   r   
_expect_reJ   s   

zSource._expect_rer;   linec                 C  s   t | |d}|s t | |dddrt|d S dS | }|dkr*dS tdt|d D ]}t|d| d|krF|  S q3dS )zCheck if the line starts with given prefix and
        return the position of the end of prefix.
        If the prefix is not matched, return -1.
           r   zd                                                                                                   
   r$   r   N)rA   r   
expandtabsr   r2   endrange)r;   rD   mr   ir   r   r   match_prefixO   s   zSource.match_prefixc                 C  s>   |  | j| jdd}|dkr| || j| }|| _|S dS )zTest against the given regular expression and returns the match object.
        :param regexp: the expression to be tested.
        :returns: the match object.
        F)require_prefixr   N)rL   r;   	next_linerC   r   r   )r!   r<   
prefix_lenr   r   r   r   	expect_rec   s   zSource.expect_re.rM   Literal[False]c                 C     d S r5   r   r!   rM   r   r   r   rN   r      zSource.next_lineLiteral[True]
str | Nonec                 C  rR   r5   r   rS   r   r   r   rN   u   rT   Tc                 C  s4   |r|  d}n| d| j}|| _|r| S dS )zReturn the next line in the source.

        :param require_prefix:  if False, the whole line will be returned.
            otherwise, return the line with prefix stripped or None if the prefix
            is not matched.
        z(?m)[^\n]*?$\n?z(?m)[^\n]*$\n?N)rP   rC   r   r   group)r!   rM   rJ   r   r   r   rN   x   s   c                 C  s>   | j r| j  | _| j  dd dkr|   d| _ dS dS )z6Consume the body of source. ``pos`` will move forward.r$   Nr   )r   rH   r   rW   _update_prefixr&   r   r   r   consume   s   
zSource.consumec                 C     | j | _dS )z!Pin the current parsing position.N)r   r   r&   r   r   r   anchor      zSource.anchorc                 C  rZ   )z&Reset the position to the last anchor.N)r   r   r&   r   r   r   reset   r\   zSource.resetc                 C  s"   | j D ]}t|dr|j|_qd S )N_second_prefix)r   hasattrr^   r6   )r!   r8   r   r   r   rX      s
   

zSource._update_prefixN)r   r   r   r   )r   r
   )r   r   )r)   r
   r   r   )r)   r
   r   r/   )r   r1   )r   r   )r<   r=   r   r>   r   r?   )r;   r   rD   r   r   r>   )r<   r=   r   r?   ).)rM   rQ   r   r   )rM   rU   r   rV   )T)rM   r1   r   rV   )r   r   )__name__
__module____qualname____doc____annotations__r"   propertyr'   r(   r,   r.   r   r0   r3   r;   rC   staticmethod	functools	lru_cacherL   rP   r	   rN   rY   r[   r]   rX   r   r   r   r   r      s<   
 
	






r   )r   r   r   r   )
__future__r   rg   rA   r   
contextlibr   typingr   r   r   r   r   r	   marko.blockr
   r   r   marko.parserr   r   r   r   r   r   r   <module>   s     
