
    hJ!              	       <   S SK r S SKJr  S SKJrJrJrJrJrJ	r	J
r
Jr  \(       a  SSKJrJr   S SKrS SKJr   " S S5      r\
" S	5      r\\S
4   r " S S\	\   5      r\S   r " S S\5      rSS\S\SSSS4S jjrSS\4S jjrSS\4S jjrg! \ a     Ngf = f)    N)deepcopy)ListCallableIteratorUnionOptionalGenericTypeVarTYPE_CHECKING   )TerminalDefToken)Literalc                   v    \ rS rSr% \\S'   \\S'   \\S'   \\S'   \\S'   \\S'   \\S'   S	\S
'   \\S'   S rSrg)Meta   emptylinecolumn	start_posend_line
end_columnend_poszList[TerminalDef]orig_expansion
match_treec                     SU l         g )NTr   selfs    \C:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\lark/tree.py__init__Meta.__init__   s	    
    r   N)	__name__
__module____qualname____firstlineno__bool__annotations__intr!   __static_attributes__ r#   r    r   r      s6    K
IKNMOL''r#   r   _Leaf_TTree[_Leaf_T]c            	       >   \ rS rSr% Sr\\S'   S\S'   S$S\SSS\\   SS4S	 jjr	\
S\4S
 j5       rS rS rS rS%S\S\4S jjrS$S\S   SS4S jjrS rS rS rS\4S jrS&S jrS rS'S jrS\SS4S jrS rSSS\\   4S jrS  rS(S! jrS\SSSS4S" jr S#r!g))Tree$   a  The main tree class.

Creates a new tree, and stores "data" and "children" in attributes of the same name.
Trees can be hashed and compared.

Parameters:
    data: The name of the rule or alias
    children: List of matched sub-rules and terminals
    meta: Line & Column numbers (if ``propagate_positions`` is enabled).
        meta attributes: (line, column, end_line, end_column, start_pos, end_pos,
                          container_line, container_column, container_end_line, container_end_column)
        container_* attributes consider all symbols, including those that have been inlined in the tree.
        For example, in the rule 'a: _A B _C', the regular attributes will mark the start and end of B,
        but the container_* attributes will also include _A and _C in the range. However, rules that
        contain 'a' will consider it in full, including _A and _C for all attributes.
datazList[Branch[_Leaf_T]]childrenNmetareturnc                 (    Xl         X l        X0l        g N)r2   r3   _meta)r   r2   r3   r4   s       r    r!   Tree.__init__9   s    	 
r#   c                 R    U R                   c  [        5       U l         U R                   $ r7   )r8   r   r   s    r    r4   	Tree.meta>   s    ::DJzzr#   c                 @    SU R                   < SU R                  < S3$ )NzTree(z, )r2   r3   r   s    r    __repr__Tree.__repr__D   s    !%DMM::r#   c                     U R                   $ r7   r2   r   s    r    _pretty_labelTree._pretty_labelG   s    yyr#   c              #     #    X!-   U R                  5        3v   [        U R                  5      S:X  a8  [        U R                  S   [        5      (       d  SU R                  S    S3v   g Sv   U R                   HE  n[        U[        5      (       a  UR                  US-   U5       S h  vN   M7  X!S-   -   U S3v   MG     g  N7f)Nr   r   	
)rC   lenr3   
isinstancer0   _pretty)r   level
indent_strns       r    rJ   Tree._prettyJ   s     !"4#5#5#7"899t}}":dmmA6F+M+Mt}}Q'(++J]]a&& yyq*==='q121#R88	 #=s   B*C,C-CrL   c                 D    SR                  U R                  SU5      5      $ )zMReturns an indented string representation of the tree.

Great for debugging.
 r   )joinrJ   )r   rL   s     r    prettyTree.prettyV   s    
 wwt||Az233r#   parentzrich.tree.Treec                 $    U R                  U5      $ )zReturns a tree widget for the 'rich' library.

Example:
    ::
        from rich import print
        from lark import Tree

        tree = Tree('root', ['node1', 'node2'])
        print(tree)
)_rich)r   rT   s     r    __rich__Tree.__rich__]   s     zz&!!r#   c                 F   U(       a   UR                  SU R                   S35      nO)SS KnUR                  R	                  U R                  5      nU R
                   H@  n[        U[        5      (       a  UR                  U5        M+  UR                  SU S35        MB     U$ )Nz[bold]z[/bold]r   z[green]z[/green])addr2   	rich.treetreer0   r3   rI   rV   )r   rT   r\   richcs        r    rV   
Tree._richj   s{    ::tyyk9:D99>>$)),DA!T""71#X./	  r#   c                      U R                   UR                   :H  =(       a    U R                  UR                  :H  $ ! [         a     gf = f)NF)r2   r3   AttributeErrorr   others     r    __eq__Tree.__eq__y   s>    	99

*Nt}}/NN 		s   8; 
AAc                     X:X  + $ r7   r,   rb   s     r    __ne__Tree.__ne__   s    ""r#   c                 V    [        U R                  [        U R                  5      45      $ r7   )hashr2   tupler3   r   s    r    __hash__Tree.__hash__   s    TYYdmm 4566r#   Iterator[Tree[_Leaf_T]]c           	      :   U /n[        5       nU Ha  nX2[        U5      '   U[        UR                  5       Vs/ s H-  n[	        U[
        5      (       d  M  [        U5      U;  d  M+  UPM/     sn-  nMc     A[        [        UR                  5       5      5      $ s  snf )zDepth-first iteration.

Iterates over all the subtrees, never returning to the same node twice (Lark's parse-tree is actually a DAG).
)dictidreversedr3   rI   r0   listvalues)r   queuesubtreessubtreer^   s        r    iter_subtreesTree.iter_subtrees   s    
 6G$+R[!'*:*:!; H!;A#At, 13Ah1F !; H HE 
 X__./00	Hs   BB&Bc              #      #    U /nUR                   nUR                  nU(       aP  U" 5       n[        U[        5      (       d  M%  Uv   [	        UR
                  5       H  nU" U5        M     U(       a  MO  gg7f)zdBreadth-first iteration.

Iterates over all the subtrees, return nodes in order like pretty() does.
N)appendpoprI   r0   rr   r3   )r   stackstack_append	stack_popnodechilds         r    iter_subtrees_topdownTree.iter_subtrees_topdown   sa     
 ||II	;DdD))J!$--0U# 1 es   A0A64A6predc                 4    [        XR                  5       5      $ )z?Returns all nodes of the tree that evaluate pred(node) as true.)filterrx   )r   r   s     r    	find_predTree.find_pred   s    d..011r#   c                 .   ^ U R                  U4S j5      $ )z?Returns all nodes of the tree whose data equals the given data.c                 "   > U R                   T:H  $ r7   rB   )tr2   s    r    <lambda> Tree.find_data.<locals>.<lambda>   s    $r#   )r   )r   r2   s    `r    	find_dataTree.find_data   s    ~~677r#   c                    Sn[        [        U R                  5      S-
  SS5       HX  nU R                  U   n[        U[        5      (       d  M)  UR
                  U;   d  M;  UR                  U R                  X3S-   & SnMZ     U$ )z\Expand (inline) children with any of the given data values. Returns True if anything changedFr   T)rangerH   r3   rI   r0   r2   )r   data_valueschangedir   s        r    expand_kids_by_dataTree.expand_kids_by_data   sp    s4==)!+R4AMM!$E%&&5::+D',~~a!$	 5
 r#   z!Callable[[Branch[_Leaf_T]], bool]c              #      #    U R                    HI  n[        U[        5      (       a  UR                  U5       H  nUv   M	     M6  U" U5      (       d  ME  Uv   MK     g7f)zReturn all values in the tree that evaluate pred(value) as true.

This can be used to find all the tokens in the tree.

Example:
    >>> all_tokens = tree.scan_values(lambda v: isinstance(v, Token))
N)r3   rI   r0   scan_values)r   r   r^   r   s       r    r   Tree.scan_values   sJ      A!T""t,AG - 77G s   AA	Ac                 t    [        U 5      " U R                  [        U R                  U5      U R                  S9$ )N)r4   )typer2   r   r3   r8   )r   memos     r    __deepcopy__Tree.__deepcopy__   s(    Dz$))XdmmT%BTTr#   c                 N    [        U 5      " U R                  U R                  5      $ r7   )r   r2   r3   r   s    r    copy	Tree.copy   s    Dz$))T]]33r#   c                     Xl         X l        g r7   r>   )r   r2   r3   s      r    setTree.set   s    	 r#   )r8   r3   r2   r7   )z  )r5   rn   )r   zCallable[[Tree[_Leaf_T]], bool]r5   rn   )r5   r.   )"r$   r%   r&   r'   __doc__strr)   r   r   r!   propertyr4   r?   rC   rJ   rR   rW   rV   rd   rg   r*   rl   rx   r   r   r   r   r   r-   r   r   r   r   r+   r,   r#   r    r0   r0   $   s   " I%%S ,C 8TX> cg 
 d  
;
94 4c 4"h'78 "BR "#7# 71$ 28c 8&? 8 C QXHY  U4! !'> !4 !r#   r0   r   c                       \ rS rSrSrSrg)SlottedTree   )r2   r3   ruler8   r,   N)r$   r%   r&   r'   	__slots__r+   r,   r#   r    r   r      s    3Ir#   r   r\   filenamerankdirzLiteral["TB", "LR", "BT", "RL"]r5   c                 >    [        X40 UD6nUR                  U5        g r7   )pydot__tree_to_graph	write_pngr\   r   r   kwargsgraphs        r    pydot__tree_to_pngr      s     9&9E	OOHr#   c                 >    [        X40 UD6nUR                  U5        g r7   )r   writer   s        r    pydot__tree_to_dotr      s     9&9E	KKr#   c                 |   ^^^^^ SSK mTR                  " SSUS.UD6mS/mUUU4S jmUUUUU4S jmT" U 5        T$ )a  Creates a colorful image that represents the tree (data+children, without meta)

Possible values for `rankdir` are "TB", "LR", "BT", "RL", corresponding to
directed graphs drawn from top to bottom, from left to right, from bottom to
top, and from right to left, respectively.

`kwargs` can be any graph attribute (e. g. `dpi=200`). For a list of
possible attributes, see https://www.graphviz.org/doc/info/attrs.html.
r   Ndigraph)
graph_typer   c                 |   > TR                  TS   [        U 5      S9nTS==   S-  ss'   TR                  U5        U$ )Nr   )labelr   )Noderepradd_node)leafr   r   r   pydots     r    new_leaf&pydot__tree_to_graph.<locals>.new_leaf   s;    zz!A$d4jz1	!	tr#   c                   > [        U R                  5      S-  nUS-  nU R                   Vs/ s H(  n[        U[        5      (       a  T" U5      OT	" U5      PM*     nnT
R                  TS   SSU-  U R                  S9nTS==   S-  ss'   TR                  U5        U H#  nTR                  T
R                  XE5      5        M%     U$ s  snf )Ni i r   filledz#%x)style	fillcolorr   r   )	rj   r2   r3   rI   r0   r   r   add_edgeEdge)rw   colorr   subnodesr   subnode	_to_pydotr   r   r   r   s         r    r   'pydot__tree_to_graph.<locals>._to_pydot   s    W\\"X- ")!1!13!1 )35$(?(?Ie$Xe_T!1 	 3zz!A$h%%-w||z\	!	tGNN5::d45   3s   /C	r,   )r   Dot)r\   r   r   r   r   r   r   r   s      @@@@@r    r   r      sD     IIFGFvFE	
A  dOLr#   )LR)sysr   r   typingr   r   r   r   r   r	   r
   r   lexerr   r   r]   ImportErrorr   r   r-   Branchr0   	ParseTreer   r   r   r   r   r,   r#   r    <module>r      s    
  ] ] ])    )
	w'	(m!77 m!` M	4$ 4T S ;\ pt 
T 
&t &w  s   B BB