
    Ii                     D    S q Sq " S S\5      rS rS rS rS rS	S jrg)
   Nc                       \ rS rSrSrg)ChevronError    N)__name__
__module____qualname____firstlineno____static_attributes__r       7/venv/lib/python3.13/site-packages/chevron/tokenizer.pyr   r      s    r   r   c                      U R                  US5      u  p [        UR                  S5      -  qX 4$ ! [         a    U S4s $ f = f)z!Parse a literal from the templater   
 )split_CURRENT_LINEcount
ValueError)templatel_delliterals      r   grab_literalr      sQ    
	$NN5!4t,,""  "~s   .1 AAc                     UR                  S5      S:w  d  U(       a1  UR                  S5      S   nUR                  5       (       d  US:X  a  ggg)z<Do a preliminary check to see if a tag could be a standaloner   r   TFN)findr   isspace)r   r   is_standalonepaddings       r   
l_sa_checkr      sL     ||DR=--%b) ??2  $1r   c                     U(       a<  US;  a6  U R                  SS5      nUS   R                  5       (       d
  US   (       d  ggg)z5Do a final checkto see if a tag could be a standalone)variable	no escaper   r       TF)r   r   )r   tag_typer   
on_newlines       r   
r_sa_checkr&   /   sE     )BB^^D!,
 a=  ""*Q- r   c           	         SSSSSSSSS	.n U R                  US
5      u  p@UR                  US   S5      nUS:w  a  US
S nUS:X  a<  UR                  S5      (       a  SnUSS nOM[        SR                  [        5      5      eUS:X  a)  US:X  a#  US:X  a  U R                  S5      (       a  U S
S n SnXTR                  5       4U 4$ ! [         a    [        SR                  [        5      5      ef = f)zParse a tag from a templatecommentsectioninverted sectionendpartialset delimiter?z
no escape?r"   )!#^/>={&r   zunclosed tag at line {0}r#   r!   Nr3   set delimiterr   z&unclosed set delimiter tag
at line {0}{{}}})	r   r   r   formatr   getendswith
startswithstrip)r   r   r_del	tag_typestagr$   s         r   	parse_tagrB   A   s1    	I@ ua0 }}SVZ0H :!"g ##<<&Hcr(C   --3VM-BD D 
\	! D=Ud]x/B/B3/G/G|H"H yy{#X..G  @ ))/)>@ 	@@s   C )C.c              #   t  #    Sq Sq U R                  5       n Sn/ nUnUnU (       Ga%  [	        X5      u  ppU (       d  SU4v   GO	[        XU5      n[        XU5      u  pUu  pU	S:X  a)  U
R                  5       R                  S5      nUS   US   peO\U	S	;   a  UR                  U
5        [         qO>U	S
:X  a8   UR                  5       nX:w  a"  [        SR                  X[         S-   5      5      e[        X	U5      nU(       a,  U R                  SS5      S   n U	S:w  a  UR                  S5      nUS:w  a  SU4v   U	S;  a  X4v   U (       a  GM%  U(       a"  [        SR                  US   [        5      5      eg! [         a     GNlf = f! [         a#    [        SR                  U
[         S-   5      5      ef = f7f)a  Tokenize a mustache template

Tokenizes a mustache template in a generator fashion,
using file-like objects. It also accepts a string containing
the template.


Arguments:

template -- a file-like object, or a string of a mustache template

def_ldel -- The default left delimiter
            ("{{" by default, as in spec compliant mustache)

def_rdel -- The default right delimiter
            ("}}" by default, as in spec compliant mustache)


Returns:

A generator of mustache tags in the form of a tuple

-- (tag_type, tag_key)

Where tag_type is one of:
 * literal
 * section
 * inverted section
 * end
 * partial
 * no escape

And tag_key is either the key or in the case of a literal tag,
the literal itself.
r   NTr   r6    r#   r   )r)   r*   r+   z@Trying to close tag "{0}"
Looks like it was not opened.
line {1}z9Trying to close tag "{0}"
last open tag is "{1}"
line {2}r   r,   r   )r(   r-   zDUnexpected EOF
the tag "{0}" was never closed
was opened at line {1})r   _LAST_TAG_LINEreadAttributeErrorr   r   rB   r>   r   appendpop
IndexErrorr   r:   r&   rstrip)r   def_ldeldef_rdelr   open_sectionsr   r?   r   rA   r$   tag_keydelslast_sections                r   tokenizerR   ~   s    L MN==? MMEE
(9 g&& #8mD "(59
 &==?((-D7DH5 88  )*N H,002 &" $. %+F7+81+<%>? ? #8}E ~~dA.r2H 9$!..- b=g&& 88%%K (P  4 #F=#4nEG 	G a  X  H" $. %+F7MA4E$FH HHsG   F8E7 BF86F BF8*F87
FF8FF8-F55F8)r7   r8   )	r   rE   SyntaxErrorr   r   r   r&   rB   rR   r   r   r   <module>rT      s7   	; 	" $6/z@Gr   