+
    j,i4                        R t ^ RIHt ^ RIt. ROt ! R R4      t ! R	 R
]4      t ! R R]4      t ! R R]4      t ! R R]4      t	 ! R R]4      t
 ! R R]4      tR R ltR R ltR# )a  
Parser for parsing a regular expression.
Take a string representing a regular expression and return the root node of its
parse tree.

usage::

    root_node = parse_regex('(hello|world)')

Remarks:
- The regex parser processes multiline, it ignores all whitespace and supports
  multiple named groups with the same name and #-style comments.

Limitations:
- Lookahead is not supported.
)annotationsNRepeatVariableRegex	Lookaheadc                  2    ] tR t^ tRtR R ltR R ltRtR# )NodezH
Base class for all the grammar nodes.
(You don't initialize this one.)
c                    V ^8  d   QhRRRR/#    
other_noder   returnNodeSequence )formats   "W/usr/lib/python3/dist-packages/prompt_toolkit/contrib/regular_languages/regex_parser.py__annotate__Node.__annotate__&   s     0 0$ 0< 0    c                	    \        W.4      # N)r   selfr   s   &&r   __add__Node.__add__&   s    T.//r   c                    V ^8  d   QhRRRR/# r   r   r   r   AnyNoder   )r   s   "r   r   r   )   s     + + +' +r   c                	    \        W.4      # r   )r   r   s   &&r   __or__Node.__or__)   s    )**r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes__r   r   r   r   r       s    
0+ +r   r   c                  >    ] tR t^-tRtR R ltR R ltR R ltRtR	# )
r   z
Union operation (OR operation) between several grammars. You don't
initialize this yourself, but it's a result of a "Grammar1 | Grammar2"
operation.
c                    V ^8  d   QhRRRR/# r   children
list[Node]r   Noner   )r   s   "r   r   AnyNode.__annotate__4        ! ! ! !r   c                	    Wn         R # r   r*   r   r*   s   &&r   __init__AnyNode.__init__4        r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   r-   7   s     5 5 5' 5r   c                	<    \        V P                  V.,           4      # r   )r   r*   r   s   &&r   r   AnyNode.__or__7   s    t}}
|344r   c                   V ^8  d   QhRR/# r   r   strr   )r   s   "r   r   r-   :        ? ?# ?r   c                	P    V P                   P                   R V P                  : R2# ()	__class__r!   r*   r   s   &r   __repr__AnyNode.__repr__:   %    ..))*!DMM+<A>>r   r0   N)	r!   r"   r#   r$   r%   r2   r   rC   r&   r   r   r   r   r   -   s    !5? ?r   r   c                  >    ] tR t^>tRtR R ltR R ltR R ltRtR	# )
r   z
Concatenation operation of several grammars. You don't initialize this
yourself, but it's a result of a "Grammar1 + Grammar2" operation.
c                    V ^8  d   QhRRRR/# r)   r   )r   s   "r   r   NodeSequence.__annotate__D   r.   r   c                	    Wn         R # r   r0   r1   s   &&r   r2   NodeSequence.__init__D   r4   r   c                    V ^8  d   QhRRRR/# r
   r   )r   s   "r   r   rH   G   s     : :$ :< :r   c                	<    \        V P                  V.,           4      # r   )r   r*   r   s   &&r   r   NodeSequence.__add__G   s    DMMZL899r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   rH   J   r;   r   c                	P    V P                   P                   R V P                  : R2# r=   r@   rB   s   &r   rC   NodeSequence.__repr__J   rE   r   r0   N)	r!   r"   r#   r$   r%   r2   r   rC   r&   r   r   r   r   r   >   s    
!:? ?r   r   c                  2    ] tR t^NtRtR R ltR R ltRtR# )r   z
Regular expression.
c                    V ^8  d   QhRRRR/# )r   regexr:   r   r,   r   )r   s   "r   r   Regex.__annotate__S   s      c d r   c                	>    \         P                  ! V4       Wn        R # r   )recompilerS   )r   rS   s   &&r   r2   Regex.__init__S   s    


5
r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   rT   X   s     < <# <r   c                	N    V P                   P                   R V P                   R2# )z(/z/))rA   r!   rS   rB   s   &r   rC   Regex.__repr__X   s$    ..))*"TZZL;;r   )rS   Nr!   r"   r#   r$   r%   r2   rC   r&   r   r   r   r   r   N   s    
< <r   c                  6    ] tR t^\tRtRR R lltR R ltRtR# )	r   z
Lookahead expression.
c               $    V ^8  d   QhRRRRRR/# )r   	childnoder   negativeboolr   r,   r   )r   s   "r   r   Lookahead.__annotate__a   s!     ! !$ !$ !4 !r   c                	    Wn         W n        R # r   r_   r`   )r   r_   r`   s   &&&r   r2   Lookahead.__init__a   s    " r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   rb   e   s     @ @# @r   c                	P    V P                   P                   R V P                  : R2# r=   rA   r!   r_   rB   s   &r   rC   Lookahead.__repr__e   s%    ..))*!DNN+=Q??r   rd   N)Fr\   r   r   r   r   r   \   s    !@ @r   c                  6    ] tR t^itRtRR R lltR R ltRtR# )	r   z
Mark a variable in the regular grammar. This will be translated into a
named group. Each variable can have his own completer, validator, etc..

:param childnode: The grammar which is wrapped inside this variable.
:param varname: String.
c               $    V ^8  d   QhRRRRRR/# )r   r_   r   varnamer:   r   r,   r   )r   s   "r   r   Variable.__annotate__r   s!      $  d r   c                	    Wn         W n        R # r   r_   rl   )r   r_   rl   s   &&&r   r2   Variable.__init__r   s    "r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   rm   v   s     d d# dr   c                	l    V P                   P                   R V P                  : RV P                  : R2# )(childnode=z
, varname=r?   )rA   r!   r_   rl   rB   s   &r   rC   Variable.__repr__v   s4    ..))*+dnn5GzRVR^R^Qaabccr   ro   N) r\   r   r   r   r   r   i   s    d dr   c                  2    ] tR t^ztRR R lltR R ltRtR# )r   Nc          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )r   r_   r   
min_repeatint
max_repeatz
int | Nonegreedyra   r   r,   r   )r   s   "r   r   Repeat.__annotate__{   s<     
 

 
 	

 
 

r   c                	6    Wn         W n        W0n        W@n        R # r   )r_   rx   rz   r{   )r   r_   rx   rz   r{   s   &&&&&r   r2   Repeat.__init__{   s     #$$r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r|      s     J J# Jr   c                	P    V P                   P                   R V P                  : R2# )rs   r?   rh   rB   s   &r   rC   Repeat.__repr__   s%    ..))*+dnn5GqIIr   )r_   r{   rz   rx   )    NT)r!   r"   r#   r$   r2   rC   r&   r   r   r   r   r   z   s    
J Jr   c                    V ^8  d   QhRRRR/# )r   inputr:   r   	list[str]r   )r   s   "r   r   r      s     2 2# 2) 2r   c                J   \         P                  ! R\         P                  4      p. pV '       dt   VP                  V 4      pV'       dP   V RVP	                  4        WP	                  4       R rVP                  4       '       g   VP                  V4       Kn  Kp  \        R4      hV# )z
Takes a string, representing a regular expression as input, and tokenizes
it.

:param input: string, representing a regular expression.
:returns: List of tokens.
a  ^(
        \(\?P\<[a-zA-Z0-9_-]+\>  | # Start of named group.
        \(\?#[^)]*\)             | # Comment
        \(\?=                    | # Start of lookahead assertion
        \(\?!                    | # Start of negative lookahead assertion
        \(\?<=                   | # If preceded by.
        \(\?<                    | # If not preceded by.
        \(?:                     | # Start of group. (non capturing.)
        \(                       | # Start of group.
        \(?[iLmsux]              | # Flags.
        \(?P=[a-zA-Z]+\)         | # Back reference to named group
        \)                       | # End of group.
        \{[^{}]*\}               | # Repetition
        \*\? | \+\? | \?\?\      | # Non greedy repetition.
        \* | \+ | \?             | # Repetition
        \#.*\n                   | # Comment
        \\. |

        # Character group.
        \[
            ( [^\]\\]  |  \\.)*
        \]                  |

        [^(){}]             |
        .
    )NzCould not tokenize input regex.)rV   rW   VERBOSEmatchendisspaceappend	Exception)r   ptokensmtokens   &    r   tokenize_regexr      s     	

		4 	

7	A< F
GGEN 1557+U5579-=5==??e$ # =>>Mr   c                    V ^8  d   QhRRRR/# )r   regex_tokensr   r   r   r   )r   s   "r   r   r      s     W Wi WD Wr   c                   aaa R.V RRR1,          ,           oR R loR VVV3R lloS! 4       p\        S4      ^ 8w  d   \        R4      hV# )	zF
Takes a list of tokens from the tokenizer, and returns a parse tree.
r?   Nc                    V ^8  d   QhRRRR/# )r   lstr+   r   r   r   )r   s   "r   r   !parse_regex.<locals>.__annotate__   s     % %* % %r   c                J    \        V 4      ^8X  d
   V ^ ,          # \        V 4      # )z7Turn list into sequence when it contains several items.)lenr   )r   s   &r   wrapparse_regex.<locals>.wrap   s!    s8q=q6M$$r   c                   V ^8  d   QhRR/# r   r   r   r   )r   s   "r   r   r      s     B/ B/D B/r   c                   <aa . o. oR  VVV3R llp S'       Ed    SP                  4       pVP                  R4      '       d)   \        S! 4       V^R R7      pSP                  V4       KX  VR9   d   VR8H  p\	        SR,          VR7      SR&   K}  VR9   d    VR8H  p\	        SR,          ^VR7      SR&   K  VR9   dC   S. 8X  d   \        R	\        S4      ,           4      hVR8H  p\	        SR,          ^ ^VR
7      SR&   K  VR8X  d   SP                  S4       . oEK	  VR9   d   SP                  S! 4       4       EK)  VR8X  d%   SP                  \        S! 4       RR7      4       EKT  VR8X  d%   SP                  \        S! 4       RR7      4       EK  VR8X  d   V ! 4       # VP                  R4      '       d   EK  VP                  R4      '       d   \        V R24      hVP                  R4      '       d   \        V: R24      hVP                  4       '       d   EK  SP                  \        V4      4       EK(  \        R4      h)c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   1parse_regex.<locals>._parse.<locals>.__annotate__   s     	; 	; 	;r   c                    < S. 8X  d	   S! S4      # SP                  S4       \        S U u. uF  p S! V 4      NK  	  up 4      # u up i r   )r   r   )ior_listresultr   s    r   wrapped_result3parse_regex.<locals>._parse.<locals>.wrapped_result   sA    "}F|#v&9AQ9::9s   Az(?P<)rl   *)r{   +)rx   r{   ?zNothing to repeat.)rx   rz   r{   |z(?!T)r`   z(?=Fr?   #{z#-style repetition not yet supportedz(?z not supportedzExpecting ')' token)r   z*?)r   z+?)r   z??)r>   z(?:)
pop
startswithr   r   r   r   reprr   r   r   )	r   tvariabler{   r   r   _parser   r   s	       @@r   r   parse_regex.<locals>._parse   s   $&	; 	; f

A||F###FHa"g>h'k!c#F2Jv>r
k!c#F2J1VLr
k!R<#$84<$GHH#XF!'r
qQv"F2J cv&l"fh'ei4@Aei5ABc%''c""c""1#%H IJJd##1%~ 677eAh'-..r   zUnmatched parentheses.r   )r   r   )r   r   r   r   r   s   & @@@r   parse_regexr      sR    
 TrT 22F%B/ B/H XF
6{a011r   )r   r   r   r   r   r   )r%   
__future__r   rV   __all__r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s}   " # 	
+ 
+?d ?"?4 ? <D <
@ 
@dt d"JT J"2jWr   