Ë
    iKêjÉ)  ã                   ó  — d Z ddlZddlmZ ddlZddlmZmZmZ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 dd
lmZ ddlmZ ddlmZ ddlmZmZ dgZdee   dee   dee    de!e    fd„Z" G d„ dejF                  «      Z$d„ Z%e ed¬«      dd ejL                  d¬«      dœdej                  j                  de dz  de'e ejF                  e    f   dz  dejF                  e    dejF                  e    f
d „«       «       Z(y)!a  
This extra can be used to generate strings matching any context-free grammar,
using the `Lark parser library <https://github.com/lark-parser/lark>`_.

It currently only supports Lark's native EBNF syntax, but we plan to extend
this to support other common syntaxes such as ANTLR and :rfc:`5234` ABNF.
Lark already `supports loading grammars
<https://lark-parser.readthedocs.io/en/stable/tools.html#importing-grammars-from-nearley-js>`_
from `nearley.js <https://nearley.js.org/>`_, so you may not have to write
your own at all.
é    N)Ú	signature)ÚNonTerminalÚRuleÚSymbolÚTerminal)ÚLark)ÚTerminalDef)Ú
strategies)ÚInvalidArgument)ÚConjectureData)Úcalc_label_from_name)Ú
check_type)ÚIncompatibleWithAlphabet)Ú	cacheableÚdefines_strategyÚ	from_larkÚ	terminalsÚrulesÚignore_namesÚreturnc           	      óä   — | D �ch c]  }|j                   ’Œ c}t        |«      z  }|D ]:  }||j                  D �ch c]  }t        |t        «      sŒ|j                   ’Œ! c}z  }Œ< |S c c}w c c}w )aC  Get names of all terminals in the grammar.

    The arguments are the results of calling ``Lark.grammar.compile()``,
    so you would think that the ``terminals`` and ``ignore_names`` would
    have it all... but they omit terminals created with ``@declare``,
    which appear only in the expansion(s) of nonterminals.
    )ÚnameÚsetÚ	expansionÚ
isinstancer   )r   r   r   ÚtÚnamesÚrules         úZ/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/hypothesis/extra/lark.pyÚget_terminal_namesr    *   sf   € ð 'Ö'˜ˆQ�V‹VÒ'¬#¨lÓ*;Ñ;€EØò MˆØ $§.¡.ÖL˜Q´J¸qÄ(Õ4K�!—&“&ÒLÑL‰ðMà€Lùò (ùâLs   …A(»A-ÁA-c            
       óÚ   ‡ — e Zd ZdZdededz  deeej                  e   f   dej                  e   ddf
ˆ fd„Z	d	e
defd
„Zdedefd„Zd	e
dedee   ddfd„Zd	e
dee   ddfd„Zd„ Zˆ xZS )ÚLarkStrategyzcLow-level strategy implementation wrapping a Lark grammar.

    See ``from_lark`` for details.
    ÚgrammarÚstartNÚexplicitÚalphabetr   c                 ój
  •‡ ‡— t         ‰‰ �  «        t        |t        j                  j                  «      sJ ‚|€|j
                  j                  n|g}t        |j                  j                  «      j                  }d|v r!|j                  j                  |d«      \  }}}	nBd|v r |j                  j                  |«      \  }}}	n|j                  j                  «       \  }}}	i ‰ _        |D ]/  }
|
j                  ‰ j                  |
j                  j                  <   Œ1 t        «       }i ‰ _        |D ]Õ  }t!        |j                  «      ‰ j                  |j                  <   t#        j                  |j$                  j'                  «       «      }|fdt(        dt"        j*                  t(           dt,        fd„}t/        j0                  |d|¬	«      j3                  |«      }	 |j5                  «        |‰ j                  |j                  <   Œ× t;        ˆ fd
„|	D «       «      ‰ _        t?        |||	«      }tA        t        |«      |z
  «      x}rtC        d|› d�«      ‚tA        ||D �ch c]  }|j                  ’Œ c}z
  t        |«      z
  «      x}r0tC        ddtE        |«      dkD  z  › dtA        |«      ›d|d   ›d�«      ‚‰ j                  jG                  |«       i }|D ]m  }|jI                  d„ |jJ                  D «       «      sŒ&|jM                  |j                  j                  g «      jO                  t;        |jJ                  «      «       Œo h ‰ j                  £|£ŠtQ        |«      |jS                  «       D ���ci c]/  \  }}|D �cg c]  }tU        ˆfd„|D «       «      sŒ|‘Œ c}x}r||“Œ1 c}}}x}k7  rlh ‰ j                  £|£ŠtQ        |«      |jS                  «       D ���ci c]/  \  }}|D �cg c]  }tU        ˆfd„|D «       «      sŒ|‘Œ c}x}r||“Œ1 c}}}x}k7  rŒlt        |«      jI                  ‰«      rtC        dt;        |«      › d|›�«      ‚t/        jV                  |D �cg c]  }|‰v sŒ‰ j                  |   ‘Œ c}«      ‰ _        |jS                  «       D ��ci c]*  \  }}|t/        jV                  tA        |tD        ¬«      «      “Œ, c}}‰ _,        i ‰ _-        y # t6        $ r |j9                  |j                  «       Y �ŒØw xY wc c}w c c}w c c}}}w c c}w c c}}}w c c}w c c}}w )NÚterminals_to_keep© r$   ÚstringÚpatternr   c                 ód   — |j                  | «      }|€J ‚|j                  «       t        | «      k(  S ©N)ÚmatchÚendÚlen)r*   r+   r.   s      r   Úlexes_entirelyz-LarkStrategy.__init__.<locals>.lexes_entirelyc   s1   € ØŸ™ fÓ-�ØÐ(Ð(Ð(Ø—y‘y“{¤c¨&£kÑ1Ð1ó    T)Ú	fullmatchr&   c              3   ó<   •K  — | ]  }‰j                   |   –— Œ y ­wr-   )Únames_to_symbols)Ú.0ÚnÚselfs     €r   ú	<genexpr>z(LarkStrategy.__init__.<locals>.<genexpr>w   s   øè ø€ Ò$TÀ! T×%:Ñ%:¸1Õ%=Ñ$Tùs   ƒzLThe following arguments were passed as explicit_strategies, but there is no z% terminal production in this grammar.zUndefined terminalÚsé   ú z}. Generation does not currently support use of %declare unless you pass `explicit`, a dict of names-to-strategies, such as `{r   z: st.just("")}}`c              3   ó4   K  — | ]  }|j                   –— Œ y ­wr-   ©r   )r6   Úrs     r   r9   z(LarkStrategy.__init__.<locals>.<genexpr>�   s   è ø€ Ò$D° Q§V¥VÑ$Dùs   ‚c              3   ó:   •K  — | ]  }|j                   ‰v –— Œ y ­wr-   r>   )r6   r?   Úallowed_ruless     €r   r9   z(LarkStrategy.__init__.<locals>.<genexpr>™   s   øè ø€ Ò1UÈa°!·&±&¸MÔ2IÑ1Uùs   ƒzNo start rule z is allowed by alphabet=)Úkey).ÚsuperÚ__init__r   Úlarkr   Úoptionsr$   r   r#   ÚcompileÚ
parametersr5   Úoriginr   r   Úterminal_strategiesr   Úrer+   Ú	to_regexpÚstrÚPatternÚboolÚstÚ
from_regexÚfilterÚvalidater   ÚaddÚtupleÚignored_symbolsr    Úsortedr   r0   ÚupdateÚ
isdisjointr   Ú
setdefaultÚappendÚdictÚitemsÚallÚsampled_fromÚnonterminal_strategiesÚ_LarkStrategy__rule_labels)r8   r#   r$   r%   r&   ÚstartsÚcompile_argsr   r   r   r?   Ú
disallowedr   r+   r1   r:   Úall_terminalsÚunknown_explicitÚmissing_declaredÚnonterminalsr   ÚkÚvÚxÚcleanrA   Ú	__class__s   `                        @€r   rD   zLarkStrategy.__init__@   s  ú€ ô 	‰ÑÔÜ˜'¤4§9¡9§>¡>Ô2Ð2Ð2Ø*/¨-�—‘×&Ò&¸e¸Wˆô
 ! §¡×!8Ñ!8Ó9×DÑDˆØ ,Ñ.Ø-4¯_©_×-DÑ-DÀVÈRÓ-PÑ*ˆI�u™lØ˜Ñ$à-4¯_©_×-DÑ-DÀVÓ-LÑ*ˆI�u™lð .5¯_©_×-DÑ-DÓ-FÑ*ˆI�u˜là35ˆÔàò 	<ˆAØ34·8±8ˆD×!Ñ! !§(¡(§-¡-Ò0ð	<ô “Uˆ
ØFHˆÔ Øò 	5ˆAÜ,4°Q·V±VÓ,<ˆD×!Ñ! !§&¡&Ñ)Ü—j‘j §¡×!4Ñ!4Ó!6Ó7ˆGàGNñ 2¤sð 2´R·Z±ZÄ±_ð 2ÔSWó 2ô )+¯©Ø 4°(ô)ç‰f�^Ó$ð ð5Ø—
‘
”ð 45�×(Ñ(¨¯©Ò0ð-	5ô0  %Ó$TÀ|Ô$TÓTˆÔä*¨9°e¸\ÓJˆÜ%¤c¨(£m°mÑ&CÓDÐDÐÐDÜ!ðØ/Ð0Ð0UðWóð ô  &Ø¨YÖ7¨˜QŸV›VÒ7Ñ7¼#¸h»-ÑGó 
ð 
Ðð 
ô "Ø$ S¬CÐ0@Ó,AÀAÑ,EÑ%FÐ$GÀqÜÐ*Ó+Ð.ð /3à3CÀAÑ3FÐ2Ið J!ð!óð ð 	× Ñ ×'Ñ'¨Ô1ð =?ˆàò 	ˆDØ×$Ñ$Ñ$D°T·^±^Ô$DÕDØ×'Ñ'¨¯©×(8Ñ(8¸"Ó=×DÑDÜ˜$Ÿ.™.Ó)õð	ð C˜$×2Ñ2ÐB°\ÐBˆÜ�<Ó ð )×.Ñ.Ó0÷ð á�A�qØ)*ÖV A¬cÓ1UÐSTÔ1UÕ.UšaÒVÐV�EÐVð �5‘ôð ˆLò
ð G˜d×6Ñ6ÐF¸ÐFˆMô �<Ó ð )×.Ñ.Ó0÷ð á�A�qØ)*ÖV A¬cÓ1UÐSTÔ1UÕ.UšaÒVÐV�EÐVð �5‘ôð ˆLó
ô ˆv‹;×!Ñ! -Ô0Ü!Ø ¤ v£ Ð/H¸x¸kÐJóð ô —_‘_Ø/5ÖL¨!¸¸mÒ9KˆT×"Ñ" 1Ó%ÒLó
ˆŒ
ð
 @L×?QÑ?QÓ?S÷'
Ù7;°q¸!ˆAŒr�‰œv a¬SÔ1Ó2Ñ2ó'
ˆÔ#ð .0ˆÕøôq ,ò 'Ø—‘˜qŸv™v×&ð'üò 8ùò2 Wùôùò Wùôùò Mùó'
sf   ÇS"É!T
Í8T
ÎTÎTÎ"
T
Ï#T#
Ï/TÐ	TÐ
T#
Ñ(	T*Ñ2T*Ò"/T/Ó"$T
Ô	T
ÔT
ÔT#
Údatac                 ó„   — g }|j                  | j                  «      }| j                  |||«       dj                  |«      S )NÚ )Údrawr$   Údraw_symbolÚjoin)r8   rn   Ústater$   s       r   Údo_drawzLarkStrategy.do_draw¬   s9   € ØˆØ—	‘	˜$Ÿ*™*Ó%ˆØ×Ñ˜˜u eÔ,Ø�w‰w�u‹~Ðr2   r   c                 ó�   — 	 | j                   |   S # t        $ r+ | j                   j                  |t        d|› �«      «      cY S w xY w)NzLARK:)ra   ÚKeyErrorrZ   r   )r8   r   s     r   Ú
rule_labelzLarkStrategy.rule_label²   sQ   € ð	Ø×%Ñ% dÑ+Ð+øÜò 	Ø×%Ñ%×0Ñ0ØÔ*¨U°4°&¨>Ó:óò ð	ús   ‚ ‘1AÁAÚsymbolÚ
draw_statec                 ó  — t        |t        «      r:| j                  |j                     }|j	                  |j                  |«      «       y t        |t        «      sJ ‚|j                  | j                  |j                  «      «       	 |j                  | j                  |j                     «      }|D ]'  }| j                  |||«       | j                  ||«       Œ) 	 |j                  «        y # |j                  «        w xY wr-   )r   r   rJ   r   r[   rq   r   Ú
start_spanrx   r`   rr   Ú
gen_ignoreÚ	stop_span)r8   rn   ry   rz   Ústrategyr   Úes          r   rr   zLarkStrategy.draw_symbolº   sÊ   € ô �fœhÔ'Ø×/Ñ/°·±Ñ<ˆHØ×Ñ˜dŸi™i¨Ó1Õ2ä˜f¤kÔ2Ð2Ð2Ø�O‰O˜DŸO™O¨F¯K©KÓ8Ô9ð!Ø ŸI™I d×&AÑ&AÀ&Ç+Á+Ñ&NÓO�	Ø"ò 6�AØ×$Ñ$ T¨1¨jÔ9Ø—O‘O D¨*Õ5ñ6ð —‘Õ ø�—‘Õ ús   ÂAC. Ã.D c                 óÄ   — | j                   rT|j                  d«      rB|j                  t        j                  | j                   «      «      }| j                  |||«       y y y )Ng      Ð?)rV   Údraw_booleanrq   rP   r_   rr   )r8   rn   rz   Úemits       r   r}   zLarkStrategy.gen_ignoreÎ   sO   € Ø×Ò D×$5Ñ$5°eÔ$<Ø—9‘9œRŸ_™_¨T×-AÑ-AÓBÓCˆDØ×Ñ˜T 4¨Õ4ð %=Ðr2   c                  ó   — y)NTr)   )r8   Úrecurs     r   Úcalc_has_reusable_valuesz%LarkStrategy.calc_has_reusable_valuesÓ   s   € Ør2   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rM   r\   rP   ÚSearchStrategyrD   r   ru   Úintrx   r   Úlistrr   r}   r†   Ú__classcell__)rm   s   @r   r"   r"   :   sà   ø„ ñð
j0àðj0ð �T‰zðj0ð �s˜B×-Ñ-¨cÑ2Ð2Ñ3ð	j0ð
 ×#Ñ# CÑ(ðj0ð 
õj0ðX˜Nð ¨só ð˜sð  só ð!àð!ð ð!ð ˜‘Ið	!ð
 
ó!ð(5˜~ð 5¸4À¹9ð 5Èó 5ö
r2   r"   c                 ó   ‡ — ˆ fd„}|S )Nc                 ó0   •— t        t        | d‰z   «       | S )Nzvalue drawn from )r   rM   )Úvaluer   s    €r   Úinnerzcheck_explicit.<locals>.innerØ   s   ø€ Ü”3˜Ð2°TÑ9Ô:Øˆr2   r)   )r   r’   s   ` r   Úcheck_explicitr“   ×   s   ø€ ôð €Lr2   T)Úforce_reusable_valueszutf-8)Úcodec)r$   r%   r&   r#   r$   r%   r&   c                ó"  — t        t        j                  j                  | d«       |€i }nRt        t        |d«       |j	                  «       D ��ci c]&  \  }}||j                  t        d|›d|›�«      «      “Œ( }}}t        | |||«      S c c}}w )aÓ  A strategy for strings accepted by the given context-free grammar.

    ``grammar`` must be a ``Lark`` object, which wraps an EBNF specification.
    The Lark EBNF grammar reference can be found
    `here <https://lark-parser.readthedocs.io/en/latest/grammar.html>`_.

    ``from_lark`` will automatically generate strings matching the
    nonterminal ``start`` symbol in the grammar, which was supplied as an
    argument to the Lark class.  To generate strings matching a different
    symbol, including terminals, you can override this by passing the
    ``start`` argument to ``from_lark``.  Note that Lark may remove unreachable
    productions when the grammar is compiled, so you should probably pass the
    same value for ``start`` to both.

    Currently ``from_lark`` does not support grammars that need custom lexing.
    Any lexers will be ignored, and any undefined terminals from the use of
    ``%declare`` will result in generation errors.  To define strategies for
    such terminals, pass a dictionary mapping their name to a corresponding
    strategy as the ``explicit`` argument.

    The :pypi:`hypothesmith` project includes a strategy for Python source,
    based on a grammar and careful post-processing.
    r#   r%   z	explicit[z]=)r   rE   r   r\   r]   Úmapr“   r"   )r#   r$   r%   r&   ri   rj   s         r   r   r   ß   s’   € ô@ Œt�y‰y�~‰~˜w¨	Ô2ØÐØ‰ä”4˜ :Ô.ð !Ÿ™Ó(÷
á��1ð ˆq�u‰u”^ i°¨u°B°q°eÐ$<Ó=Ó>Ñ>ð
ˆñ 
ô ˜ ¨°(Ó;Ð;ùó	
s   Á+B))rŠ   rK   Úinspectr   rE   Úlark.grammarr   r   r   r   Ú	lark.larkr   Ú
lark.lexerr	   Ú
hypothesisr
   rP   Úhypothesis.errorsr   Ú#hypothesis.internal.conjecture.datar   Ú$hypothesis.internal.conjecture.utilsr   Úhypothesis.internal.validationr   Ú%hypothesis.strategies._internal.regexr   Ú%hypothesis.strategies._internal.utilsr   r   Ú__all__r�   rM   r   r    r‹   r"   r“   Ú
charactersr\   r   r)   r2   r   ú<module>r¥      s0  ðñ
ó 
Ý ã ß <Ó <Ý Ý "å 'Ý -Ý >Ý EÝ 5Ý Jß Màˆ-€ðØ�KÑ ðØ)-¨d©ðØCGÈÁ9ðàˆ�Xóô Z�2×$Ñ$ô Zòzð Ù¨Ô-ð Ø9=Ø'4 r§}¡}¸7Ô'Cò'<Ø�Y‰Y�^‰^ð'<ð �‰:ð'<ð �3˜×)Ñ)¨#Ñ.Ð.Ñ/°$Ñ6ð	'<ð
 ×Ñ Ñ$ð'<ð ×Ñ�sÑò'<ó .ó ñ'<r2   