
    Iib                     |   S SK Jr  S SKJrJr  S SKrS SKrS SKrS SKrS SK	J
r
  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  SSKJrJrJrJr  SS	KJr  SS
KJrJr  SSK J!r!J"r"J#r#J$r$  SSK%J&r&  SSK'J(r(J)r)  SSK*J+r+  S SK,r, S SK-r- " S S\5      r/1 Skr0Sr1Sr2 " S S\5      r3 " S S\5      r4g! \. a    Sr- N4f = f)    )absolute_import)ConfigurationErrorassert_configN)open)warn   )STRING_TYPE	SerializeSerializeMemoizerFSisasciiloggerABCabstractmethod)load_grammarFromPackageLoaderGrammarverify_used_files)Tree)	LexerConf
ParserConf)LexerTraditionalLexerTerminalDefLexerThread)ParseTreeBuilder)get_frontend_get_lexer_callbacks)Rulec                       \ rS rSrSrSr\(       a  \\-  r0 SS_SS_SS_S	S_S
S_SS_SS_SS_SS_SS_SS_SS_SS_S0 _SS_SS_SS_S/ SS.ErS rS rS r	S r
\S 5       rS rg)!LarkOptions   z$Specifies the options for Lark

    a  
    **===  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.
    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= ``False``. Recommended to set to ``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
            - "standard": Use a standard 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 standard 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`` (Python 3 only).
    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 ===**
    debugFkeep_all_tokens
tree_classNcachepostlexparserearleylexerautotransformerstartpriority	ambiguityregexpropagate_positionslexer_callbacksmaybe_placeholdersedit_terminalsg_regex_flagsr   )	use_bytesimport_pathssource_pathc                    [        U5      n0 nU R                  R                  5        HH  u  pEXB;   a8  UR                  U5      n[	        U[
        5      (       a  US;  a  [        U5      nOUnXcU'   MJ     [	        US   [        5      (       a	  US   /US'   X0R                  S'   [        U R                  S5        U R                  S:X  a  U R                  (       a  [        S5      eU(       a  [        SUR                  5       -  5      eg )N)r&   r6   r1   r-   options)r)   lalrcykNr)   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)dict	_defaultsitemspop
isinstanceboolr	   __dict__r   r(   r,   r   keys)selfoptions_dictor:   namedefaultvalues          //venv/lib/python3.13/site-packages/lark/lark.py__init__LarkOptions.__init__   s    !^^113MDydgt,,=j1j KE!DM 4 gg&44 ' 01GG#*i  	dkk#BC;;("t'7'7$ &A B B $%:QVVX%EFF     c                 b     U R                   S   U   $ ! [         a  n[        U5      eS nAff = f)Nr:   )rC   KeyErrorAttributeError)rE   rH   es      rK   __getattr__LarkOptions.__getattr__   s6    	$==+D11 	$ ##	$s    
.).c                 h    [        XR                  R                  5       S5        X R                  U'   g )Nz,%r isn't a valid option. Expected one of: %s)r   r:   rD   )rE   rH   rJ   s      rK   __setattr__LarkOptions.__setattr__   s&    dLL--/1_`"TrN   c                     U R                   $ Nr:   )rE   memos     rK   	serializeLarkOptions.serialize   s    ||rN   c                     U " U5      $ rY    )clsdatar[   s      rK   deserializeLarkOptions.deserialize   s    4yrN   r_   )__name__
__module____qualname____firstlineno____doc__OPTIONS_DOCr>   rL   rS   rV   r\   classmethodrb   __static_attributes__r_   rN   rK   r!   r!      s'   GKP ;5 	d 		
 	4 	( 	 	t 	 	F 	V 	 	u 	2 	e  	$!" 	#$ )I.G:$#  rN   r!   >	   r#   r0   r'   r6   r%   r,   r5   r2   r1   )r+   normalinvertN)r+   resolveexplicitforestc                   (    \ rS rSr\S 5       rSrSrg)PostLex   c                     U$ rY   r_   )rE   streams     rK   processPostLex.process   s    rN   r_   N)rd   re   rf   rg   r   rv   always_acceptrk   r_   rN   rK   rr   rr      s      MrN   rr   c                   V   \ rS rSrSrS r\(       a  \S\R                  -   -  rSrSS jr	S r
S rS	 r\S
 5       rS rS r\S 5       r\SS j5       r\SS j5       rS rSS jrS rSS jrSS jr\S 5       r\R6                  S 5       r\S 5       r\R6                  S 5       rSrg)Lark   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(...)
c           
        ^ [        U5      U l        U R                  R                  nU(       a  [        (       a  [        nO[        S5      e[        nU R                  R
                  c   UR                  U l        OU R                  R
                  U l         UR                  nU" 5       nS nS n[        U[        5      (       Ga#  Xl        U R                  R                  (       aW  [        U5      (       d  [        S5      e[        R                   S   S:X  a%  U R                  R                  S:w  a  [        S5      eU R                  R"                  (       GaG  U R                  R$                  S:w  a  [        S	5      eS
mSR'                  U4S jUR)                  5        5       5      nSSKJn	  X-   U	-   [/        [        R                   S S 5      -   n
[0        R2                  " U
R5                  S5      5      R7                  5       n[        U R                  R"                  [        5      (       a  U R                  R"                  nOTU R                  R"                  SLa  [        S5      e[8        R:                  " 5       SU4[        R                   S S -   -  -   n[<        R>                  " U5      (       a  [@        RB                  " SU5        [E        U5      [F        -
   H  nX+	 M     [<        RH                  " US5       nU R                  n URK                  5       RM                  S5      n[N        RP                  " U5      nXR5                  S5      :X  aC  [S        U5      (       a3  [N        RP                  " U5      nU RT                  " U40 UD6   S S S 5        g S S S 5        [[        XR
                  U R                  R\                  U R                  R^                  5      u  U l0        nO[        U[b        5      (       d   eXl0        U R                  Rd                  S:X  a  U R                  R$                  S:X  a  SU R                  l2        OU R                  R$                  S:X  aQ  U R                  Rf                  b(  [@        Rh                  " S5        SU R                  l2        OYSU R                  l2        OGU R                  R$                  S:X  a  SU R                  l2        O U R                  R$                  5       eU R                  Rd                  n[        U[j        5      (       a  [m        U[n        5      (       d   eO4[q        US5        U R                  Rf                  b  SU;   a  [        S5      eU R                  Rr                  S:X  a,  U R                  R$                  S:X  a  S U R                  l9        O![q        U R                  R$                  S!S"5        U R                  Rt                  S:X  a  S#U R                  l:        U R                  Rt                  [v        ;  a+  [        S$U R                  Rt                  < S%[v        < 35      eU R                  Rr                  S&;  d   S'5       eU R                  Rr                  [x        ;  a+  [        S(U R                  Rr                  < S%[x        < 35      eU R                  R$                  c  S)nOKU R                  Rf                  b*  [E        U R                  Rf                  Rz                  5      nO
[E        5       nU R`                  R}                  U R                  R~                  U5      u  U l@        U lA        U lB        U R                  R                  (       a.  U R                   H  nU R                  R                  U5        M      U R                   Vs0 s H  nUR                  U_M     snU lD        U R                  Rt                  S*:X  aS  U R                   HB  nUR                  Rt                  c  M  UR                  Rt                  * UR                  l:        MD     OTU R                  Rt                  c=  U R                   H-  nUR                  Rt                  c  M  S UR                  l:        M/     [        U R                  X@R                  U R                  Rf                  U R                  R                  U R                  R                  U R                  R                  S+9U lH        U R                  R$                  (       a  U R                  5       U l        OU(       a  U R                  5       U l2        U(       a  [@        RB                  " S,U5        [<        RH                  " US-5       nUR                  UR5                  S5      S-   5        [N        R                  " WU5        U R                  U5        S S S 5        g g ! [         a    SU l         G	Ndf = f! [         a     G	Naf = f! [V         a#    [@        RX                  " SU-  5        Xl         GNf = f! , (       d  f       GN= fs  snf ! , (       d  f       g = f).Nz?`regex` module must be installed if calling `Lark(regex=True)`.z<string>z/Grammar must be ascii only, when use_bytes=Truer      forcez_`use_bytes=True` may have issues on python2.Use `use_bytes='force'` to use it at your own risk.r;   z+cache only works with parser='lalr' for now)r,   r'   r2   r4    c              3   T   >#    U  H  u  pUT;  d  M  U[        U5      -   v   M     g 7frY   )str).0kv
unhashables      rK   	<genexpr> Lark.__init__.<locals>.<genexpr>  s%     %b?41aWaNahaAh?s   ((r   )__version__utf8Tz"cache argument must be bool or strz/.lark_cache_%s_%s_%s.tmpzLoading grammar from cache: %srb   
z<Failed to load Lark from cache: %r. We will try to carry on.r+   
contextualr)   zpostlex can't be used with the dynamic lexer, so we use standard instead. Consider using lalr with contextual instead of earleystandarddynamicr<   )r   r   r   dynamic_completezJCan't use postlex with a dynamic lexer. Use standard or contextual insteadrn   )r)   r<   zG%r doesn't support disambiguation. Use one of these parsers instead: %srl   zinvalid priority option: z. Must be one of )resolve__antiscore_sumzJresolve__antiscore_sum has been replaced with the option priority="invert"zinvalid ambiguity option: *rm   )r6   zSaving grammar to cache: %swb)Nr!   r:   r0   ImportErrorrer8   rH   rQ   readrA   r	   source_grammarr6   r   r   sysversion_infor&   r(   joinr?   r   r   r   hashlibmd5encode	hexdigesttempfile
gettempdirr   existsr   r#   set_LOAD_ALLOWED_OPTIONSr   readlinerstrippickleloadr   _load	Exception	exceptionr   r7   r$   grammarr   r*   r'   infotype
issubclassr   r   r/   r.   _VALID_PRIORITY_OPTIONS_VALID_AMBIGUITY_OPTIONSrx   compiler-   	terminalsrulesignore_tokensr4   _terminals_dictr   r2   r5   
lexer_conf_build_parser_build_lexerwritedumpsave)rE   r   r:   	use_regex	re_moduler   cache_fn	cache_md5options_strr   srH   fold_optionsfile_md5cached_used_filescached_parser_data
used_filesr*   terminals_to_keeptruler   s                         @rK   rL   Lark.__init__   s   "7+ LL&&	u!	!"cddI <<##+.#*<<   $||77D	<<D fG	g{++")||%%w'',-^__##A&!+0F0F'0Q, .d e e ||!!!<<&&&0,-Z[[\
 gg%b7==?%bb))K7#c>N>NrPQ>R:SS#KK(89CCE	dll00+>>#||11H||))501UVV'2247RW`VbeheueuvxwxeyVy7zzH99X&&LL!A8L!$W0E!E#M "F40A&*ll7'(zz|':':5'AH06A-'+;+;F+CCHYZkHlHl5;[[^ 2 $

+= I I & 100$ (4G=M=Mt||OhOhjnjvjv  kG  kG  (H$DL*gw////"L <<'||""f,%1"$$0<<''3KK !X Y)3DLL&)2DLL&$$-%/"1dll111u""eT""eU++++%!Z[||##/I4F()uvv<<!!V+||""h.)2&$,,--/@  CL  M<<  F*$,DLL!<<  (??$Y]YeYeYnYn  qH  &I  J  J||%%-II  	X  LX  	XI<<!!)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) #
 $	+=+=t||?S?S,,dll.H.HTXT`T`TjTj
 <<,,.DK**,DJLL6A4(A	((0589J*		! )( k " .#- .  		`  ) 7",,-knv-vw ,7L7 10V  C: )(sb   *g' g? >i Bh8iAi'g<;g<?
hh)h=9i <h==i  
i
i%z

)r(   r   r:   c                 h    U R                   nU(       a  SSKJn  U" U5      nSUl        [        U5      $ )Nr   )copyr_   )r   r   ignorer   )rE   dont_ignorer   r   s       rK   r   Lark._build_lexer  s.    __
!j)J "J
++rN   c                 p   0 U l         U R                  R                  S:w  a  [        U R                  U R                  R
                  =(       d    [        U R                  R                  U R                  R                  S:g  =(       a    U R                  R                  S:H  U R                  R                  5      U l
        U R                  R                  U R                  R                  5      U l         U R                   R                  [        U R                  R                  U R                  5      5        g )Nrp   r;   ro   )
_callbacksr:   r/   r   r   r%   r   r1   r(   r3   _parse_tree_buildercreate_callbackr,   updater   r   rE   s    rK   _prepare_callbacks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]^rN   c                 *   U R                  5         [        U R                  R                  U R                  R                  5      n[        U R                  U R                  U R                  R                  5      nU" U R                  X R                  S9$ )NrZ   )
r   r   r:   r(   r*   r   r   r   r-   r   )rE   parser_classparser_confs      rK   r   Lark._build_parser  sc    !#DLL$7$79K9KL T__dll>P>PQDOO[,,OOrN   c                     U R                  [        [        /5      u  p#[        R                  " X#S.U[        R
                  S9  g)zWSaves the instance into the given file object

Useful for caching and multiprocessing.
ra   r[   )protocolN)memo_serializer   r   r   r   HIGHEST_PROTOCOL)rE   r   ra   ms       rK   r   	Lark.save  s4    
 %%{D&9:T-q6;R;RSrN   c                 F    U R                  U 5      nUR                  U5      $ )zVLoads an instance from the given file object

Useful for caching and multiprocessing.
__new__r   )r`   r   insts      rK   r   	Lark.load  s      {{3zz!}rN   c                 &   [         R                  " US   U5      nUR                  =(       d    0 Ul        UR                  (       a  [        O[
        Ul        UR                  Ul        UR                  Ul        SUl	        UR                  Ul
        U$ )Nr   T)r   rb   r2   	callbacksr0   r   r   r6   r5   skip_validationr'   )rE   ra   r[   r:   r   s        rK   _deserialize_lexer_confLark._deserialize_lexer_conf  sr    **4+=tD
&66<"
(/u2
&00
#*#8#8
 %)
"$__
rN   c                 J   [        U[        5      (       a  UnO[        R                  " U5      nUS   nUS   nU(       d   e[        R
                  " U[        [        S.0 5      n[        US   5      n[        U5      [        -
  [        [        R                  5      -  (       a*  [        SR                  [        U5      [        -
  5      5      eUR                  U5        [        R                  Xv5      U l        US    Vs/ s H  n[        R
                  " X5      PM     snU l        SU l        [%        U R                  R&                  U R                  R(                  5      n	U R+                  US   X`R                  5      U l        U R,                  R.                  U l        U R1                  5         U R.                   V
s0 s H  oR2                  U
_M     sn
U l        U	R                  US   UU R,                  U R6                  U R                  5      U l        U $ s  snf s  sn
f )	Nr[   ra   )r   r   r:   z6Some options are not allowed when loading a Parser: {}r   z<deserialized>r(   )rA   r=   r   r   r   rb   r   r   r   r   r!   r>   r   formatr   r:   r   r8   r   r(   r*   r   r   r   r   rH   r   r   )rE   r   kwargsd	memo_jsonra   r[   r:   rr   r   s              rK   r   
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
+#DLL$7$79K9KL66tH~t\\Z22!37>>B>a	>B"..NOOOOLL
  H  Cs     H H c                 N    U R                  U 5      nUR                  " XS.40 UD6$ )Nr   r   )r`   ra   r[   r   r   s        rK   _load_from_dictLark._load_from_dict  s'    {{3zz46A&AArN   Nc                     U(       a>  [         R                  R                  U5      n[         R                  R                  XA5      n[	        USS9 nU " U40 UD6sSSS5        $ ! , (       d  f       g= f)zCreate 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`   grammar_filenamerel_tor:   basepathr   s         rK   r   	Lark.open  sR     wwv.H!ww||HG"V4q$G$ 544s   	A##
A1c                     [        X5      nU" SU5      u  pgUR                  SU5        UR                  S/ 5        US   R                  U5        U " U40 UD6$ )aC  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=...)
Nr8   r7   )r   
setdefaultappend)r`   packagegrammar_pathsearch_pathsr:   package_loader	full_pathtexts           rK   open_from_packageLark.open_from_package  s_     +7A(|<	=)4>2.&&~64#7##rN   c                     SU R                   < SU R                  R                  < SU R                  R                  < S3$ )Nz
Lark(open(z
), parser=z, lexer=z, ...))r8   r:   r(   r*   r   s    rK   __repr__Lark.__repr__  s,    =A=M=Mt||ObObdhdpdpdvdvwwrN   c                 *   [        U S5      (       a  U(       a  U R                  U5      nOU R                  n[        X15      nUR	                  S5      nU R
                  R                  (       a%  U R
                  R                  R                  U5      $ U$ )a  Only lex (and postlex) the text, without parsing it. Only relevant when lexer='standard'

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.
r*   N)hasattrr   r*   r   lexr:   r'   rv   )rE   r  r   r*   lexer_threadru   s         rK   r  Lark.lex  ss     tW%%%%k2EJJE"5/!!$'<<<<''//77rN   c                      U R                   U   $ )z Get information about a terminal)r   )rE   rH   s     rK   get_terminalLark.get_terminal!  s    ##D))rN   c                 4    U R                   R                  XS9$ )zStart 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()``
)r-   )r(   parse_interactive)rE   r  r-   s      rK   r  Lark.parse_interactive%  s     {{,,T,??rN   c                 6    U R                   R                  XUS9$ )aR  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``.

)r-   on_error)r(   parse)rE   r  r-   r  s       rK   r  
Lark.parse3  s    $ {{  X FFrN   c                 :    [        S[        5        U R                  $ )Nz5Attribute Lark.source was renamed to Lark.source_path)r   DeprecationWarningr8   r   s    rK   sourceLark.sourceG  s    DFXYrN   c                     Xl         g rY   )r8   rE   rJ   s     rK   r  r   L  s     rN   c                 :    [        S[        5        U R                  $ )Nz@Attribute Lark.grammar_source was renamed to Lark.source_grammar)r   r  r   r   s    rK   grammar_sourceLark.grammar_sourceP  s    OQcd"""rN   c                     Xl         g rY   )r   r"  s     rK   r$  r%  U  s    #rN   )r   r   r   r   r   r*   r   r:   r(   r   r   r8   r   )FrY   ))r   )NN)rd   re   rf   rg   rh   rL   r!   ri   __serialize_fields__r   r   r   r   rj   r   r   r   r   r   r	  r  r  r  r  r  propertyr  setterr$  rk   r_   rN   rK   rz   rz      s   kZ 6K33337,_PT  @ B B % %" $ $"x"*@G(     ]]! ! # # $ $rN   rz   )5
__future__r   lark.exceptionsr   r   r   r   r   r   ior   r   warningsr   utilsr	   r
   r   r   r   r   r   r   r   r   r   r   treer   commonr   r   r*   r   r   r   r   parse_tree_builderr   parser_frontendsr   r   r   r   r   r0   r   r!   r   r   r   rr   rz   r_   rN   rK   <module>r3     s    & >      f f f U U  ) D D 0 @  	[) [@ [ < D c J$9 J$k  Es   B0 0B;:B;