
    [l                     J   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r4ddlmZ ddlmZ ddlmZ ej@                  dk\  rd d	l
m!Z! n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. ddl/m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4 ddlm5Z5 ddl6m7Z7m8Z8m9Z9m:Z: ddl;m<Z<m=Z=m>Z>m?Z?m@Z@ ddlAmBZB ddl#mCZCmDZDmEZEmFZF ddlGmHZH 	 d dlIZIdZJ G d de      ZL G d de*      ZMh dZNdZOdZP edd      ZQ G d  de*      ZRy# eK$ r dZJY =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isasciilogger)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     lib/third_party/lark/lark.pyprocesszPostLex.process,   s        r@   always_acceptN)__name__
__module____qualname__r   r	   r3   rC   rE   r   str__annotations__r@   rD   rB   r;   r;   +   s:    huo (5/   $&M8C=%rD   r;   c            	       d   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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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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d/d%eee
f   fd+Zed,eee
f   d-ee	eeef   f   d%d fd.       Zy)0LarkOptionsz$Specifies the options for Lark

    startdebugstrictzOptional[Transformer]transformerpropagate_positionsmaybe_placeholderscache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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 (line, column, end_line, end_column) attributes into all tree branches.
            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
    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``.
    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   )rU   r^   r`   ra   _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      |rt        d|j                         z        y )N)rS   r^   rQ   rM   options)rb   lalrcykNrb   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)zUnknown options: %s)dictre   itemspop
isinstanceboolrI   __dict__r   rX   rP   r   keys)rA   rf   orh   namedefaultvalues          rB   __init__zLarkOptions.__init__   s    !^^113MD'qydgt,=j1j KE!GDM 4 gg&, ' 01GG#*i  	dkk#BC;;("t'7'7$ &A B B $%:QVVX%EFF rD   rs   c                 `    	 | j                   d   |   S # t        $ r}t        |      d }~ww xY w)Nrh   )rp   KeyErrorAttributeError)rA   rs   es      rB   __getattr__zLarkOptions.__getattr__   s6    	$==+D11 	$ ##	$s    	-(-ru   c                 l    t        || j                  j                         d       || j                  |<   y )Nz,%r isn't a valid option. Expected one of: %s)r   rh   rq   )rA   rs   ru   s      rB   __setattr__zLarkOptions.__setattr__   s*    dDLL--/1_`"TrD   c                     | j                   S r?   rh   )rA   memos     rB   	serializezLarkOptions.serialize   s    ||rD   datar   c                      | |      S r?   r@   )clsr   r   s      rB   deserializezLarkOptions.deserialize   s    4yrD   r?   )rF   rG   rH   __doc__r   rI   rJ   ro   r   intr   r-   r.   r   r;   r   r
   r3   r1   OPTIONS_DOCre   rv   r{   r}   r   classmethodr9   r   r@   rD   rB   rL   rL   2   sy    9KL((tSy))sKOAAg==#x7788OX{m[&@ABBii#HKR ;!!%! 	5! 	d	!
 	! 	4! 	(! 	! 	t! 	! 	F! 	V! 	! 	u! 	2!  	d!!" 	$#!$ -!ItCH~ 2GT#s(^ G G:$ $ $# #C #D #S#X  tCH~ T#u[RVEV?W:W5X ]j  rD   rL   >
   rN   rT   r[   rd   r^   rW   rP   rU   r]   rQ   )rc   normalinvertN)rc   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
<   d4dZ
eredej                  z   z  Zd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(...)
    ra   source_grammarr&   grammarrh   rY   r   rX   	terminalsr=   Nc           
         t        |      | _        | 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t        |      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        t,        j.                  d d       z   }
t1        |
      }t        | j                  j                   t              r| j                  j                   }nh| j                  j                   durt        d      	 t3        j4                         }t9        j:                         d||gt,        j.                  d d z  z   }| j                  }	 t=        j>                  |d      5 }tA        jB                  d|       tE        |      tF        z
  D ]  }||=  |jI                         jK                  d      }tM        jN                  |      }||jQ                  d      k(  r=tS        |      r2tM        jN                  |      } | jT                  |fi | 	 d d d        y d d d        t[        || j                  | j                  j\                  | j                  j^                        \  | _0        }nt        |tb              sJ || _0        | j                  jd                  dk(  r| j                  j"                  dk(  rd| j                  _2        n| j                  j"                  dk(  rO| j                  jf                  'tA        jh                  d       d| j                  _2        nXd| j                  _2        nF| j                  j"                  dk(  rd| j                  _2        nJ | j                  j"                         | j                  jd                  }t        |tj              rtm        |tn              s3J tq        |d       | j                  jf                  d|v rt        d      | j                  jr                  dk(  r+| j                  j"                  dk(  r3d| j                  _9        n!tq        | j                  j"                  dd        | j                  jt                  dk(  rd!| j                  _:        | j                  jt                  tv        vr)t        d"| j                  jt                  d#tv              | j                  jr                  tx        vr)t        d$| j                  jr                  d#tx              | j                  j"                  d%}nJ| j                  jf                  *tE        | j                  jf                  jz                        }n
tE               }| j`                  j}                  | j                  j~                  |      \  | _@        | _A        | _B        | j                  j                  r,| j                  D ]  }| j                  j                  |        | j                  D ci c]  }|j                  | c}| _D        | j                  jt                  d&k(  rr| j                  D ]?  }|j                  jt                  |j                  jt                   |j                  _:        A | j                  D ]  }|jt                   |_:         ng| j                  jt                  Q| j                  D ]*  }|j                  jt                  d |j                  _:        , | j                  D ]	  }d'|_:         t        | j                  || j                  | j                  jf                  | j                  j                  | j                  j                  | j                  j                  | j                  j                  (      | _I        | j                  j"                  r| j                         | _        n|r| j                         | _2        |rtA        jB                  d)|       	 t=        j>                  |d*      5 }|J |j                  |jQ                  d      dz          tM        j                  |       | j                  |tF               d d d        y y # t        $ r d| _        Y w xY w# t        $ r Y w xY w# t6        $ r d}Y w xY w# 1 sw Y   }xY w# tV        $ r Y t6        $ r! tA        jX                  d|       || _        Y w xY wc c}w # 1 sw Y   y xY w# t        $ r!}tA        jX                  d+||       Y d }~y d }~ww xY w),Nz?`regex` module must be installed if calling `Lark(regex=True)`.z<string>z/Grammar must be ascii only, when use_bytes=Trueri   z+cache only works with parser='lalr' for now)rP   r[   r]   r_   rd    c              3   J   K   | ]  \  }}|vs|t        |      z     y wr?   )rI   ).0kv
unhashables      rB   	<genexpr>z Lark.__init__.<locals>.<genexpr>4  s&     %b?41aaWaNaaAh?s   ##r   )__version__   Tz"cache argument must be bool or strunknownz/.lark_cache_%s_%s_%s_%s.tmprbzLoading grammar from cache: %s   
utf8z<Failed to load Lark from cache: %r. We will try to carry on.rc   
contextualrb   z~postlex can't be used with the dynamic lexer, so we use 'basic' instead. Consider using lalr with contextual instead of earleybasicdynamicrj   )r   r   r   dynamic_completezGCan't use postlex with a dynamic lexer. Use basic or contextual insteadr   )rb   rj   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^   rO   zSaving grammar to cache: %swbz!Failed to save Lark to cache: %r.)PrL   rh   rT   
_has_regexImportErrorrera   rs   ry   readrn   rI   r   r^   r"   r   rS   rX   joinrl   r   r   sysversion_infor)   getpassgetuser	Exceptiontempfile
gettempdirr!   openr#   rN   set_LOAD_ALLOWED_OPTIONSreadlinerstrippickleloadencoder'   _loadFileNotFoundError	exceptionr$   r`   rV   r   r&   rY   r[   infotype
issubclassr/   r   rZ   r\   _VALID_PRIORITY_OPTIONS_VALID_AMBIGUITY_OPTIONSrE   compilerM   r   rulesignore_tokensr_   _terminals_dictr+   r]   rU   rO   
lexer_conf_build_parser_build_lexerwritedumpsaveIOError)rA   r   rh   	use_regex	re_moduler   cache_fncache_sha256options_strr   susernameold_optionsfrs   file_sha256cached_used_filescached_parser_data
used_filesrY   terminals_to_keeptruletermrz   r   s                            @rB   rv   zLark.__init__  sL   "7+ LL&&	!	!"cddI <<##+.#*<<   $||77D	<<D fGgs#")D||%%w',-^__||!!<<&&&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47UYaco  YHru  sC  sC  DF  EF  sG  YH  8H   HH"ll/40A%ExP%(\4I%ID ' &J&'jjl&9&9%&@,2KKN)&,*=*=f*EEJ[\mJn17Q.&DJJ'9EWE" 100. (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>>B>a	>B <<  H,

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

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

)rX   r   rh   dont_ignorec                 ^    | j                   }|rddlm}  ||      }d|_        t        |      S )Nr   )copyr@   )r   r   ignorer0   )rA   r   r   r   s       rB   r   zLark._build_lexer  s.    __
!j)J "J*%%rD   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   ri   r   )
_callbacksrh   rZ   r4   r   rW   r*   rQ   rX   rR   _parse_tree_buildercreate_callbackrP   updater6   r   rA   s    rB   _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]^rD   c                    | j                          t        | j                  j                  | j                  j                         t        | j                  | j                  | j                  j                        }t        | j                  j                  | j                  j                  | j                  || j                        S )Nr   )r   r5   rh   rX   rY   r,   r   r   rM   r8   r   )rA   parser_confs     rB   r   zLark._build_parser  s    ! 3 3T\\5G5GH T__dll>P>PQ*LLLLOOLL
 	
rD   exclude_optionsc                     | 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.
        rh   r   r   )protocolN)memo_serializer1   r9   rl   r   r   HIGHEST_PROTOCOL)rA   r   r   r   mnr   s          rB   r   z	Lark.save  sx    
 %%{D&9:a04Y0E0E0Gd0G11TcKcq!t0GdDOT1-q6;R;RS es   A:A:r   c                 F    | j                  |       }|j                  |      S )zfLoads an instance from the given file object

        Useful for caching and multiprocessing.
        __new__r   )r   r   insts      rB   r   z	Lark.load  s      {{3zz!}rD   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[   )rA   r   r   rh   r   s        rB   _deserialize_lexer_confzLark._deserialize_lexer_conf  sr    **4+=tD
&66<"
(/u2
&00
#*#8#8
 %)
"$__
rD   rA   r   c                    t        |t              r|}nt        j                  |      }|d   }|d   }|sJ t	        j
                  |t        t        di       }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                        | _        | j,                  j.                  | _        | j1                          | j.                  D 	ci c]  }	|	j2                  |	 c}	| _        t7        |d   || j,                  | j8                  | j                        | _        | S c c}w c c}	w )	Nr   r   )r9   r1   rh   z6Some options are not allowed when loading a Parser: {}r   z<deserialized>rX   )rn   rk   r   r   r    r   r9   r1   r   r   rL   re   r   formatr   rh   r   ra   r5   rX   rY   r   r   r   r   rs   r   r7   r   )
rA   r   kwargsd	memo_jsonr   r   rh   rr   s
             rB   r   z
Lark._load  s   aAAAfI	yy ,,YVa8bdfgtI'K//3{7L7L3MM$%]$fS[3H%HIK Kv"..w=9=gGAd&&q$/G
+ 3 3T\\5G5GH66tH~tT\\Z22!37>>B>a	>B3NOOOOLL
  H  Cs   0H.Hc                 P    | j                  |       } |j                  ||dfi |S )Nr   r   )r   r   r   r  r   s        rB   _load_from_dictzLark._load_from_dict'  s+    {{3tzz46A&AArD   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  rh   basepathr   s         rB   r   z	Lark.open,  sU     wwv.H!ww||H6FG"V4q$G$ 544s   	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=...)
        Nra   r`   )r%   
setdefaultappend)r   r  r  r  rh   package_loader	full_pathtexts           rB   open_from_packagezLark.open_from_package>  sc     +7LA(|<	4=)4>2.&&~64#7##rD   c                 ~    d| j                   d| j                  j                  d| j                  j                  dS )Nz
Lark(open(z
), parser=z, lexer=z, ...))ra   rh   rX   rY   r   s    rB   __repr__zLark.__repr__P  s,    =A=M=Mt||ObObdhdpdpdvdvwwrD   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   r2   	from_textlexrh   r[   rC   )rA   r  r   rY   lexer_threadr<   s         rB   r  zLark.lexT  sx     tW%%%k2EJJE",,UD9!!$'<<<<''//77rD   rs   c                      | j                   |   S )z Get information about a terminal)r   )rA   rs   s     rB   get_terminalzLark.get_terminalf  s    ##D))rD   rM   r   c                 <    | j                   j                  ||      S )a-  Start an interactive parsing session.

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

        Returns:
            A new InteractiveParser instance.

        See Also: ``Lark.parse()``
        )rM   )rX   parse_interactive)rA   r  rM   s      rB   r#  zLark.parse_interactivej  s     {{,,T,??rD   on_errorz+Optional[Callable[[UnexpectedInput], bool]]r   c                 >    | j                   j                  |||      S )a  Parse the given text, according to the options provided.

        Parameters:
            text (str): Text to be parsed.
            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 UnexpectedToken error. Return true to resume parsing.
                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``.

        )rM   r$  )rX   parse)rA   r  rM   r$  s       rB   r&  z
Lark.parsex  s     $ {{  UX FFrD   )r   zUnion[Grammar, str, IO[str]]r=   N)F)r=   N)r=   r   )r@   r?   )NN)*rF   rG   rH   r   rI   rJ   rL   r/   r   r1   rv   r   __serialize_fields__ro   r0   r   r   r   r   r   r   r   r   r   r   r   r   r9   r+   r   r   r  r   r   r  r  r	   r3   r  r!  r#  r&  r@   rD   rB   r   r      s=    L+&&ySv 6K33337& &z &_

Tz# T T $r( "  DcN $sER]_cRcLdGdBe p{   AJ B 3 R @ B B %$r( %c %8C= %]_ % %" ikhl $tBx $# $S $Xg $|~ $ $"x $ % $* * *@hsm @# @Xk @G# Ghsm GDq G  |G GrD   )S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   r   typing_extensionsparser_frontendsr   
exceptionsr   r   r   utilsr   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   commonr+   r,   r-   r.   rY   r/   r0   r1   r2   r3   parse_tree_builderr4   r5   r6   r7   r8   r   r9   rT   r   r   r;   rL   r   r   r   r   r   r@   rD   rB   <module>r4     s    #      	     B%
6!"-1 J J D D u u  H H E E 0 H  H J&c &s) sp g < D  T XG9 XG]  Js   D D"!D"