
    bis                     "   d dl mZmZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ erddlmZ ddlmZ ddlmZ d dl
m Z  dd	l!m"Z" dd
l#m$Z$m%Z%m&Z& ddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 ddlm4Z4 ddl5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z=m>Z>m?Z? ddl@mAZA ddl!mBZBmCZCmDZDmEZE ddlFmGZG 	 d dlHZHdZI G d de      ZK G d de(      ZLh dZMdZNdZO edd      ZP G d de(      ZQy# eJ$ r dZIY =w xY w)     )ABCabstractmethodN)TypeVarTypeListDictIteratorCallableUnionOptionalSequenceTupleIterableIOAnyTYPE_CHECKING
Collection   )InteractiveParser)	ParseTree)Transformer)Literal)ParsingFrontend)ConfigurationErrorassert_configUnexpectedInput)	SerializeSerializeMemoizerFSloggerTextOrSlice	LarkInput)load_grammarFromPackageLoaderGrammarverify_used_filesPackageResourcesha256_digest)Tree)	LexerConf
ParserConf_ParserArgType_LexerArgType)Lexer
BasicLexerTerminalDefLexerThreadToken)ParseTreeBuilder)_validate_frontend_args_get_lexer_callbacks_deserialize_parsing_frontend_construct_parsing_frontend)RuleTFc                   H    e Zd ZU edee   dee   fd       ZdZee	   e
d<   y)PostLexstreamreturnc                     |S N )selfr;   s     D/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/lark/lark.pyprocesszPostLex.process)   s        r?   always_acceptN)__name__
__module____qualname__r   r	   r2   rB   rD   r   str__annotations__r?   rC   rA   r:   r:   (   s:    huo (5/   $&M8C=%rC   r:   c            	          e Zd ZU dZee   ed<   eed<   eed<   ded<   eeef   ed<   eed<   eeef   ed	<   eed
<   eed<   e	ed<   eed<   e
eeegef      ed<   eed<   eed<   ded<   e
e   ed<   ded<   eeeegef   f   ed<   eed<   eed<   e
eegef      ed<   ded<   e
e   ed<   dZereez  Zi ddddddddd	dd
ddddd dd!dddddd!dd!dddddi dd"dd#dd"g di d$Zeeef   ed%<   d&eeef   d'dfd(Zd)ed'efd*Zd)ed+ed'dfd,Zd1d'eeef   fd-Zed.eeef   d/ee	eeef   f   d'd fd0       Zy)2LarkOptionsz$Specifies the options for Lark

    startdebugstrictzOptional[Transformer]transformerpropagate_positionsmaybe_placeholderscachecache_grammarregexg_regex_flagskeep_all_tokens
tree_classparserlexerz0Literal["auto", "resolve", "explicit", "forest"]	ambiguitypostlexz-Optional[Literal["auto", "normal", "invert"]]prioritylexer_callbacks	use_bytesordered_setsedit_terminalszUList[Union[str, Callable[[Union[None, str, PackageResource], str], Tuple[str, str]]]]import_pathssource_patha?  
    **===  General Options  ===**

    start
            The start symbol. Either a string, or a list of strings for multiple possible starts (Default: "start")
    debug
            Display debug information and extra warnings. Use only when debugging (Default: ``False``)
            When used with Earley, it generates a forest graph as "sppf.png", if 'dot' is installed.
    strict
            Throw an exception on any potential ambiguity, including shift/reduce conflicts, and regex collisions.
    transformer
            Applies the transformer to every parse tree (equivalent to applying it after the parse, but faster)
    propagate_positions
            Propagates positional attributes into the 'meta' attribute of all tree branches.
            Sets attributes: (line, column, end_line, end_column, start_pos, end_pos,
                              container_line, container_column, container_end_line, container_end_column)
            Accepts ``False``, ``True``, or a callable, which will filter which nodes to ignore when propagating.
    maybe_placeholders
            When ``True``, the ``[]`` operator returns ``None`` when not matched.
            When ``False``,  ``[]`` behaves like the ``?`` operator, and returns no value at all.
            (default= ``True``)
    cache
            Cache the results of the Lark grammar analysis, for x2 to x3 faster loading. LALR only for now.

            - When ``False``, does nothing (default)
            - When ``True``, caches to a temporary file in the local directory
            - When given a string, caches to the path pointed by the string
    cache_grammar
            For use with ``cache`` option. When ``True``, the unanalyzed grammar is also included in the cache.
            Useful for classes that require the ``Lark.grammar`` to be present (e.g. Reconstructor).
            (default= ``False``)
    regex
            When True, uses the ``regex`` module instead of the stdlib ``re``.
    g_regex_flags
            Flags that are applied to all terminals (both regex and strings)
    keep_all_tokens
            Prevent the tree builder from automagically removing "punctuation" tokens (Default: ``False``)
    tree_class
            Lark will produce trees comprised of instances of this class instead of the default ``lark.Tree``.

    **=== Algorithm Options ===**

    parser
            Decides which parser engine to use. Accepts "earley" or "lalr". (Default: "earley").
            (there is also a "cyk" option for legacy)
    lexer
            Decides whether or not to use a lexer stage

            - "auto" (default): Choose for me based on the parser
            - "basic": Use a basic lexer
            - "contextual": Stronger lexer (only works with parser="lalr")
            - "dynamic": Flexible and powerful (only with parser="earley")
            - "dynamic_complete": Same as dynamic, but tries *every* variation of tokenizing possible.
    ambiguity
            Decides how to handle ambiguity in the parse. Only relevant if parser="earley"

            - "resolve": The parser will automatically choose the simplest derivation
              (it chooses consistently: greedy for tokens, non-greedy for rules)
            - "explicit": The parser will return all derivations wrapped in "_ambig" tree nodes (i.e. a forest).
            - "forest": The parser will return the root of the shared packed parse forest.

    **=== Misc. / Domain Specific Options ===**

    postlex
            Lexer post-processing (Default: ``None``) Only works with the basic and contextual lexers.
    priority
            How priorities should be evaluated - "auto", ``None``, "normal", "invert" (Default: "auto")
    lexer_callbacks
            Dictionary of callbacks for the lexer. May alter tokens during lexing. Use with caution.
    use_bytes
            Accept an input of type ``bytes`` instead of ``str``.
    ordered_sets
            Should Earley use ordered-sets to achieve stable output (~10% slower than regular sets. Default: True)
    edit_terminals
            A callback for editing the terminals before parse.
    import_paths
            A List of either paths or loader functions to specify from where grammars are imported
    source_path
            Override the source of from where the grammar was loaded. Useful for relative imports and unconventional grammar loading
    **=== End of Options ===**
    FNearleyautoTr   )r`   rU   r^   r_   ra   rb   _plugins	_defaultsoptions_dictr<   c                 *   t        |      }i }| j                  j                         D ]A  \  }}||v r1|j                  |      }t	        |t
              r|dvrt        |      }n|}|||<   C t	        |d   t              r	|d   g|d<   || j                  d<   t        | j                  d       | j                  dk(  r| j                  rt        d      | j                  r| j                  st        d      |rt        d|j                         z        y )	N)rR   r^   rP   rL   options)rc   lalrcykNrc   zCannot specify an embedded transformer when using the Earley algorithm. Please use your transformer on the resulting parse tree, or use a different algorithm (i.e. LALR)z2cache_grammar cannot be set when cache is disabledzUnknown options: %s)dictrf   itemspop
isinstanceboolrH   __dict__r   rX   rO   r   rS   rR   keys)r@   rg   ori   namedefaultvalues          rA   __init__zLarkOptions.__init__   s   !^^113 	"MD'qydgt,=j1j KE!GDM	" gg&, ' 01GG#*i  	dkk#BC;;("t'7'7$ &A B B djj$%YZZ$%:QVVX%EFF rC   rt   c                 `    	 | j                   d   |   S # t        $ r}t        |      d }~ww xY w)Nri   )rq   KeyErrorAttributeError)r@   rt   es      rA   __getattr__zLarkOptions.__getattr__   s6    	$==+D11 	$ ##	$s    	-(-rv   c                 l    t        || j                  j                         d       || j                  |<   y )Nz,%r isn't a valid option. Expected one of: %s)r   ri   rr   )r@   rt   rv   s      rA   __setattr__zLarkOptions.__setattr__   s*    dDLL--/1_`"TrC   c                     | j                   S r>   ri   )r@   memos     rA   	serializezLarkOptions.serialize   s    ||rC   datar   c                      | |      S r>   r?   )clsr   r   s      rA   deserializezLarkOptions.deserialize   s    4yrC   r>   )rE   rF   rG   __doc__r   rH   rI   rp   r   intr   r
   r   r,   r-   r:   r   r2   r0   OPTIONS_DOCrf   rw   r|   r~   r   classmethodr8   r   r?   rC   rA   rK   rK   /   s    9KL((tSy))sK3+s"2344AAg==#x7788OX{m[&@ABBii#PKb ;!!%! 	5! 	d	!
 	! 	! 	4! 	(! 	! 	t! 	! 	F! 	V! 	! 	u!  	2!!" 	d#!$ 1!ItCH~ 6GT#s(^ G G@$ $ $# #C #D #S#X  tCH~ T#u[RVEV?W:W5X ]j  rC   rK   >
   rM   rT   r[   re   r^   rW   rO   rU   r]   rP   )rd   normalinvertN)rd   resolveexplicitforest_TLark)boundc                       e Zd ZU dZeed<   eed<   ded<   eed<   eed<   ded	<   ee	   ed
<   g dZ
d4dZeredej                  z   z  Zd5dedefdZd6dZd7dZd8dee   ddfdZedee   defd       Zdeeef   deeee	ef   f   dedefdZdededefdZed        Zed9dee   ded e e   defd!       Z!ed"gfdee   d#ed$ed%d&def
d'       Z"d( Z#d5d)e$dede%e&   fd*Z'd+ede	fd,Z(d:d)e e)   d-e e   dd.fd/Z*d:d)e)d-e e   d0d1dd2fd3Z+y);r   a}  Main interface for the library.

    It's mostly a thin wrapper for the many different parsers, and for the tree constructor.

    Parameters:
        grammar: a string or file-object containing the grammar spec (using Lark's ebnf syntax)
        options: a dictionary controlling various aspects of Lark.

    Example:
        >>> Lark(r'''start: "foo" ''')
        Lark(...)
    rb   source_grammarr%   grammarri   rY   r   rX   	terminals)rX   rulesri   r<   Nc           
         t        |      | _        | j                  j                  r| j                  dgz   | _        | j                  j                  }|rt
        rt        }nt        d      t        }| j                  j                  	 |j                  | _        n| j                  j                  | _        	 |j                  } |       }d }d }t        |t              r|| _        | j                  j                  r|j!                         st#        d      | j                  j$                  r!| j                  j&                  dk7  rt#        d      ddj)                  fd	|j+                         D              }d
dlm}	 ||z   |	z   t        t0        j2                  d d       z   }
t5        |
      }t        | j                  j$                  t              r| j                  j$                  }n| j                  j$                  durt#        d      	 t7        j8                         }t=        j>                         d| j                  j                  rdnd||gt0        j2                  d d z  z   }| j                  }	 tA        jB                  |d      5 }tE        jF                  d|       tI        |      tJ        z
  D ]  }||=  |jM                         jO                  d      }tQ        jR                  |      }||jU                  d      k(  r=tW        |      r2tQ        jR                  |      } | jX                  |fi | 	 d d d        y d d d        t_        || j                  | j                  j`                  | j                  jb                        \  | _2        }nt        |tf              sJ || _2        | j                  jh                  dk(  r| j                  j&                  dk(  rd| j                  _4        n| j                  j&                  dk(  rO| j                  jj                  'tE        jl                  d       d| j                  _4        nXd| j                  _4        nF| j                  j&                  dk(  rd| j                  _4        nJ | j                  j&                         | j                  jh                  }t        |tn              rtq        |tr              s3J tu        |d       | j                  jj                  d|v rt#        d       | j                  jv                  dk(  r+| j                  j&                  dk(  r3d!| j                  _;        n!tu        | j                  j&                  d"d#       | j                  jx                  dk(  rd$| j                  _<        | j                  jx                  tz        vr)t#        d%| j                  jx                  d&tz              | j                  jv                  t|        vr)t#        d'| j                  jv                  d&t|              | j                  j&                  d(}nJ| j                  jj                  *tI        | j                  jj                  j~                        }n
tI               }| jd                  j                  | j                  j                  |      \  | _B        | _C        | _D        | j                  j                  r,| j                  D ]  }| j                  j                  |        | j                  D ci c]  }|j                  | c}| _F        | j                  jx                  d)k(  rr| j                  D ]?  }|j                  jx                  |j                  jx                   |j                  _<        A | j                  D ]  }|jx                   |_<         ng| j                  jx                  Q| j                  D ]*  }|j                  jx                  d |j                  _<        , | j                  D ]	  }d*|_<         t        | j                  || j                  | j                  jj                  | j                  j                  | j                  j                  | j                  j                  | j                  j                  +      | _K        | j                  j&                  r| j                         | _        n|r| j                         | _4        |rtE        jF                  d,|       	 tA        jB                  |d-      5 }|J |j                  |jU                  d      dz          tQ        j                  |       | j                  |tJ               d d d        y y # t        $ r d| _        Y w xY w# t        $ r Y w xY w# t:        $ r d}Y w xY w# 1 sw Y   }xY w# tZ        $ r Y t:        $ r! tE        j\                  d|       || _        Y w xY wc c}w # 1 sw Y   y xY w# t        $ r!}tE        j\                  d.||       Y d }~y d }~ww xY w)/Nr   z?`regex` module must be installed if calling `Lark(regex=True)`.z<string>z/Grammar must be ascii only, when use_bytes=Truerj   z+cache only works with parser='lalr' for now)rO   r[   r]   r`   re    c              3   J   K   | ]  \  }}|vs|t        |      z     y wr>   )rH   ).0kv
unhashables      rA   	<genexpr>z Lark.__init__.<locals>.<genexpr>F  s%     %b41aaWaNaaAh%bs   ##r   )__version__   Tz"cache argument must be bool or strunknownz/.lark_%s_%s_%s_%s_%s.tmprS   rR   rbzLoading grammar from cache: %s   
utf8z<Failed to load Lark from cache: %r. We will try to carry on.rd   
contextualrc   z~postlex can't be used with the dynamic lexer, so we use 'basic' instead. Consider using lalr with contextual instead of earleybasicdynamicrk   )r   r   r   dynamic_completezGCan't use postlex with a dynamic lexer. Use basic or contextual insteadr   )rc   rk   zG%r doesn't support disambiguation. Use one of these parsers instead: %sr   zinvalid priority option: z. Must be one of zinvalid ambiguity option: *r   r   )r^   rN   zSaving grammar to cache: %swbz!Failed to save Lark to cache: %r.)RrK   ri   rS   __serialize_fields__rT   
_has_regexImportErrorrerb   rt   rz   readro   rH   r   r^   isasciir   rR   rX   joinrm   r   r   sysversion_infor(   getpassgetuser	Exceptiontempfile
gettempdirr   openr    rM   set_LOAD_ALLOWED_OPTIONSreadlinerstrippickleloadencoder&   _loadFileNotFoundError	exceptionr#   ra   rV   r   r%   rY   r[   infotype
issubclassr.   r   rZ   r\   _VALID_PRIORITY_OPTIONS_VALID_AMBIGUITY_OPTIONSrD   compilerL   r   r   ignore_tokensr`   _terminals_dictr*   r]   rU   rN   
lexer_conf_build_parser_build_lexerwritedumpsaveIOError)r@   r   ri   	use_regex	re_moduler   cache_fncache_sha256options_strr   susernameold_optionsfrt   file_sha256cached_used_filescached_parser_data
used_filesrY   terminals_to_keeptruletermr{   r   s                            @rA   rw   zLark.__init__  s   "7+ <<%%(,(A(AYK(OD% LL&&	!	!"cddI <<##+.#*<<   $||77D	<<D fGgs#")D||%%(,-^__||!!<<&&&0,-Z[[h
 gg%b7==?%bb)k)K7#c>N>NrPQ>R:SS,Q/dll00#6#||11H||))501UVV-#*??#4  (2247R+/<<+E+E7T\^jVCmpm}m}  A  @A  nBVC 8C  CH #ll/40 
#A%ExP%(\4I%I .D '.&'jjl&9&9%&@,2KKN)&,*=*=f*EEJ[\mJn17Q.&DJJ'9EWE"
# 
# 
#. (4GT=M=Mt||OhOhjnjvjv  kG  kG  (H$DL*gw///"DL <<'||""f,%1"$$0<<''3KK !X Y)0DLL&)2DLL&$$-%,"1dll111u""eT"eU+++%!WX||##/I4F()rss<<!!V+||""h.)2&$,,--/@  CL  M<<  F*$,DLL!<<  (??$Y]YeYeYnYn  qH  &I  J  J<<!!)AA$Z^ZfZfZpZp  sK  &L  M  M<<& #\\!!- #DLL$8$8$F$F G # :>9M9MdllN`N`bs9t6
D$6<<&&^^ /++A./ 48>>Ba	B <<  H,

 C<<((4-1\\-B-B,BDLL)C  /!%/
 \\""*

 1<<((4,0DLL)1  " !" $	4+=+=t||?S?S,,dll.H.HTXT`T`TjTjswss  tG  tG
 <<,,.DK**,DJLL6ASWWXt, 8'333GGL//7%?@KK
A.IIa!67	8 8 A " .#- .  		> % - $-	-
# 
# )   /$$%cemn $/DL/B  CB8 8
  S  !DhPQRRSs   
f
 8f! f1 <g B-g?g g hh ,Ah h 
ff!	f.-f.1g ?g gg 	h%hhhh h 	i"h>>iz

dont_ignorec                 ^    | j                   }|rddlm}  ||      }d|_        t        |      S )Nr   )copyr?   )r   r   ignorer/   )r@   r   r   r   s       rA   r   zLark._build_lexer  s.    __
!j)J "J*%%rC   c                 Z   i | _         | j                  j                  dk7  rt        | j                  | j                  j
                  xs t        | j                  j                  | j                  j                  dk7  xr | j                  j                  dk(  | j                  j                        | _
        | j                  j                  | j                  j                        | _         | j                   j                  t        | j                  j                  | j                               y )Nr   rj   r   )
_callbacksri   rZ   r3   r   rW   r)   rP   rX   rQ   _parse_tree_buildercreate_callbackrO   updater5   r   r@   s    rA   _prepare_callbackszLark._prepare_callbacks  s    <<!!X-'7JJLL++3tLL44LL''61Zdll6L6LPZ6ZLL33(D$ #66FFt||G_G_`DO3DLL4L4Ldnn]^rC   c                    | j                          t        | j                  j                  | j                  j                         t        | j                  | j                  | j                  j                        }t        | j                  j                  | j                  j                  | j                  || j                        S )Nr   )r   r4   ri   rX   rY   r+   r   r   rL   r7   r   )r@   parser_confs     rA   r   zLark._build_parser  s    ! 3 3T\\5G5GH T__dll>P>PQ*LLLLOOLL
 	
rC   exclude_optionsc                 H   | j                   j                  dk7  rt        d      | j                  t        t
        g      \  }}|r/|d   j                         D ci c]  \  }}||vs|| c}}|d<   t        j                  ||d|t        j                         yc c}}w )zgSaves the instance into the given file object

        Useful for caching and multiprocessing.
        rj   z7Lark.save() is only implemented for the LALR(1) parser.ri   r   r   )protocolN)
ri   rX   NotImplementedErrormemo_serializer0   r8   rm   r   r   HIGHEST_PROTOCOL)r@   r   r   r   mnr   s          rA   r   z	Lark.save  s    
 <<&(%&_``%%{D&9:a04Y0E0E0Gd11TcKcq!tdDOT1-q6;R;RS es   B(Br   c                 F    | j                  |       }|j                  |      S )zfLoads an instance from the given file object

        Useful for caching and multiprocessing.
        __new__r   )r   r   insts      rA   r   z	Lark.load  s      {{3zz!}rC   r   r   c                    t        j                  |d   |      }|j                  xs i |_        |j                  rt        nt
        |_        |j                  |_        |j                  |_        d|_	        |j                  |_
        |S )Nr   T)r*   r   r]   	callbacksrT   r   r   r^   rU   skip_validationr[   )r@   r   r   ri   r   s        rA   _deserialize_lexer_confzLark._deserialize_lexer_conf  sr    **4+=tD
&66<"
(/u2
&00
#*#8#8
 %)
"$__
rC   r@   r   c                 Z   t        |t              r|}nt        j                  |      }|d   }|d   }|sJ t	        j
                  |t        t        di       }d|v rt        j
                  |d   |      | _	        t        |d         }t        |      t        z
  t        t        j                        z  r*t        dj                  t        |      t        z
              |j!                  |       t        j                  ||      | _        |d   D cg c]  }t        j
                  ||       c}| _        d| _        t)        | j"                  j*                  | j"                  j,                         | j/                  |d	   || j"                        | _        | j0                  j2                  | _        | j5                          | j2                  D 	ci c]  }	|	j6                  |	 c}	| _        t;        |d	   || j0                  | j<                  | j"                        | _        | S c c}w c c}	w )
Nr   r   )r8   r0   r   ri   z6Some options are not allowed when loading a Parser: {}r   z<deserialized>rX   )ro   rl   r   r   r   r   r8   r0   r%   r   r   r   rK   rf   r   formatr   ri   r   rb   r4   rX   rY   r  r   r   r   rt   r   r6   r   )
r@   r   kwargsd	memo_jsonr   r   ri   rr   s
             rA   r   z
Lark._load  s   aAAAfI	yy ,,YVa8bdfg"..tIEDLtI'K//3{7L7L3MM$%]$fS[3H%HIK Kv"..w=9=gGAd&&q$/G
+ 3 3T\\5G5GH66tH~tT\\Z22!37>>Ba	B3NOOOOLL
  H  Cs   H#H(c                 P    | j                  |       } |j                  ||dfi |S )Nr   r   )r   r   r   r  r   s        rA   _load_from_dictzLark._load_from_dict=  s+    {{3tzz46A&AArC   grammar_filenamerel_toc                     |r?t         j                  j                  |      }t         j                  j                  ||      }t	        |d      5 } | |fi |cddd       S # 1 sw Y   yxY w)a&  Create an instance of Lark with the grammar given by its filename

        If ``rel_to`` is provided, the function will find the grammar filename in relation to it.

        Example:

            >>> Lark.open("grammar_file.lark", rel_to=__file__, parser="lalr")
            Lark(...)

        r   )encodingN)ospathdirnamer   r   )r   r  r  ri   basepathr   s         rA   r   z	Lark.openB  s^     wwv.H!ww||H6FG"V4 	%q$G$	% 	% 	%s   	A""A+r   packagegrammar_pathsearch_pathszSequence[str]c                     t        ||      } |d|      \  }}|j                  d|       |j                  dg        |d   j                  |        | |fi |S )ak  Create an instance of Lark with the grammar loaded from within the package `package`.
        This allows grammar loading from zipapps.

        Imports in the grammar will use the `package` and `search_paths` provided, through `FromPackageLoader`

        Example:

            Lark.open_from_package(__name__, "example.lark", ("grammars",), parser=...)
        Nrb   ra   )r$   
setdefaultappend)r   r  r  r  ri   package_loader	full_pathtexts           rA   open_from_packagezLark.open_from_packageT  sc     +7LA(|<	4=)4>2.&&~64#7##rC   c                 ~    d| j                   d| j                  j                  d| j                  j                  dS )Nz
Lark(open(z
), parser=z, lexer=z, ...))rb   ri   rX   rY   r   s    rA   __repr__zLark.__repr__f  s,    =A=M=Mt||ObObdhdpdpdvdvwwrC   r  c                 "   t        | d      r|r| j                  |      }n| j                  }t        j                  ||      }|j                  d      }| j                  j                  r%| j                  j                  j                  |      S |S )a  Only lex (and postlex) the text, without parsing it. Only relevant when lexer='basic'

        When dont_ignore=True, the lexer will return all tokens, even those marked for %ignore.

        :raises UnexpectedCharacters: In case the lexer cannot find a suitable match.
        rY   N)	hasattrr   rY   r1   	from_textlexri   r[   rB   )r@   r  r   rY   lexer_threadr;   s         rA   r"  zLark.lexj  sx     tW%%%k2EJJE",,UD9!!$'<<<<''//77rC   rt   c                      | j                   |   S )z Get information about a terminal)r   )r@   rt   s     rA   get_terminalzLark.get_terminal|  s    ##D))rC   rL   r   c                 <    | j                   j                  ||      S )aR  Start an interactive parsing session. Only works when parser='lalr'.

        Parameters:
            text (LarkInput, optional): Text to be parsed. Required for ``resume_parse()``.
            start (str, optional): Start symbol

        Returns:
            A new InteractiveParser instance.

        See Also: ``Lark.parse()``
        )rL   )rX   parse_interactive)r@   r  rL   s      rA   r'  zLark.parse_interactive  s     {{,,T,??rC   on_errorz+Optional[Callable[[UnexpectedInput], bool]]r   c                     |$| j                   j                  dk7  rt        d      | j                  j                  |||      S )a  Parse the given text, according to the options provided.

        Parameters:
            text (LarkInput): Text to be parsed, as `str` or `bytes`.
                TextSlice may also be used, but only when lexer='basic' or 'contextual'.
                If Lark was created with a custom lexer, this may be an object of any type.
            start (str, optional): Required if Lark was given multiple possible start symbols (using the start option).
            on_error (function, optional): if provided, will be called on UnexpectedInput error,
                with the exception as its argument. Return true to resume parsing, or false to raise the exception.
                LALR only. See examples/advanced/error_handling.py for an example of how to use on_error.

        Returns:
            If a transformer is supplied to ``__init__``, returns whatever is the
            result of the transformation. Otherwise, returns a Tree instance.

        :raises UnexpectedInput: On a parse error, one of these sub-exceptions will rise:
                ``UnexpectedCharacters``, ``UnexpectedToken``, or ``UnexpectedEOF``.
                For convenience, these sub-exceptions also inherit from ``ParserError`` and ``LexerError``.

        rj   z?The on_error option is only implemented for the LALR(1) parser.)rL   r(  )ri   rX   r   parse)r@   r  rL   r(  s       rA   r*  z
Lark.parse  sC    * DLL$7$76$A%&ghh{{  UX FFrC   )r   zUnion[Grammar, str, IO[str]]r<   N)F)r<   N)r<   r   )r?   r>   )NN),rE   rF   rG   r   rH   rI   rK   r.   r   r0   r   rw   r   rp   r/   r   r   r   r   r   r   r   r   r   r   r   r   r8   r*   r  r   r
  r   r   r  r  r!   r	   r2   r"  r%  r"   r'  r*  r?   rC   rA   r   r      s?    L+&&9SB 6K3333& &z &_


Tz# 
T 
T $r( "  DcN $sER]_cRcLdGdBe p{   AJ  B  3  R  D B B %$r( %c %8C= %]_ % %" ikhl $tBx $# $S $Xg $|~ $ $"x $ % $* * *@hy&9 @xPS} @^q @G) GHSM GJw G  BM GrC   )Rabcr   r   r   r   r  r   r   typesr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   parsers.lalr_interactive_parserr   treer   visitorsr   r   parser_frontendsr   
exceptionsr   r   r   utilsr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   commonr*   r+   r,   r-   rY   r.   r/   r0   r1   r2   parse_tree_builderr3   r4   r5   r6   r7   r   r8   rT   r   r   r:   rK   r   r   r   r   r   r?   rC   rA   <module>r6     s    #      	     B%1 J J S S u u  H H E E 0 H  H J&c &B) BN g < D  T gG9 gG{  Js   
D DD