+
    Ki  c                  sV    ^ RI Ht ^ RIHtHtHtHt R R ltR R lt ! R R4      t	R	# )
    )annotations)CallableIterableListOptionalc                    V ^8  d   QhRRRR/# )   to_cleanOptional[str]returnstr Zformat   "=/usr/lib/python3.14/site-packages/lutris/util/tokenization.py__annotate__r      s     	 	- 	C 	    c                s    V f   R# V P                  R4      '       d&   V P                  R4      '       d   V ^R # V R,          # V P                  4       # )zhRemoves quotes from a token, if they are present; if they are not, this strips whitespace
off the token. ":i   NN)
startswithZendswithZstrip)r      &r   clean_tokenr      sP     3!)!2!23!7!7x"~IXb\I>>r   c               s$    V ^8  d   QhRRRRRR/# )r   textr   isolated_tokenszIterable[str]r
   	List[str]r   r   r   r   r   r      s&     F( F(# F( F() F(r   c                s   a aa \        R S 4       4      o\        SR R7      oV 3R lpR VV3R llpV! 4       pV! V4       V Uu. uF  p\        V4      '       g   K  VNK  	  up# u upi )a}  Iterates through a text and breaks in into tokens. Every character of the text is present
in exactly one token returned, all in order, so the original text can be reconstructed by concatenating the
tokens.

Tokens are separated by whitespace, but also certain characters (isolated_characters) are kept as separate tokens.
Double-quoted text are protected from further tokenization.c              3  s4   "   T F  q F  q"x  K  	  K  	  R # 5iNr   )Z.0tokch   &  r   Z	<genexpr>Z"tokenize_search.<locals>.<genexpr>   s     F#B"#"s   c                s    \        V 4      ) # r   )len)r   r   r   Z<lambda>Z!tokenize_search.<locals>.<lambda>   s
    s3xir   )Zkeyc                 s  < . p R p\        S4      p \        VR4      pVf   MVP                  4       VP                  4       8w  d   V P                  V4       R pVR8X  dM   V P                  V4       Tp \        VR4      pVf   MW,          pVR8X  g   K#   V P                  V4       R pK  W,          pK  V P                  V4       V # )r   Nr   )ZiterZnextisspaceappend)tokensbufferZitr   r   s       r   basic_tokenizeZ'tokenize_search.<locals>.basic_tokenize   s    $Zb$Bzzz|v~~//f%Syf%b$BzLFSyf%LFfr   c               r   r   r"   r   r
   ZNoner   r   r   r   r   Z%tokenize_search.<locals>.__annotate__@   s      i D r   c                s  < ^ pV\        V 4      8  d   W,          pVP                  R4      '       g   ^ pV\        V4      8  d   W#,          S9   dv   S Fo  pW#R P                  V4      '       g   K  VRV W&   V^,          pV P                  W4       W#\        V4      ,           R pV^,          pV P                  W4       Rp M	  V^,          pK  V^,          pK  R# )r    r   Nr   )r   r   Zinsert)r"   Ztoken_indextokenZ
char_index	candidater   isolating_charss   &    r   split_isolated_tokensZ.tokenize_search.<locals>.split_isolated_tokens@   s    CK''E##C((
 3u:-(O;)8I$[1<<YGG6;KZ6H 3 +q 0 &k E(-C	N/J.M(N +q 0 &k A-/
 % *9 !OJ1K# (r   )ZsetZsortedr   )r   r   r$   r)   ZbasicZtr(   s   ff    @r   tokenize_searchr*      sd     FFFO_2GHO!F , E% 'u!AAAu'''s   A(A(c                  sx    ] tR t^[tRtR R ltR tRR R lltR R ltR	 R
 lt	R R lt
R R ltR R ltRtR# )TokenReaderzTokenReader reads through a list of tokens, like an iterator. But it can also peek ahead, and you
can save and store your 'place' in the token list via the 'index' member.c               r   r%   r   r   r   r   r   TokenReader.__annotate___   s      y T r   c                	s     Wn         ^ V n        R# )r    N)r"   index)selfr"   s   &&r   __init__ZTokenReader.__init___   s    
r   c                sF    V P                   \        V P                  4      8  # )z6True if get_token() and peek_token() will return None.)r-   r   r"   )r.   r   r   is_end_of_tokensZTokenReader.is_end_of_tokensc   s    zzS---r   c               r   )r   
skip_spaceboolr
   r	   r   r   r   r   r   r,   g   s      D M r   c                s   V'       dq   V P                   \        V P                  4      8  dM   V P                  V P                   ,          P                  4       '       d   V ;P                   ^,          un         Kp  V P                   \        V P                  4      8  d   R# V P                  V P                   ,          pV ;P                   ^,          un         V# )zReturns the next token, and advances one token in the list. Returns None if
the end of tokens has been reached. If 'skip_space' is true, this skips over
whitespace tokens first (which means it can consume multiple tokens!)N)r-   r   r"   r    )r.   r1   r&   s   && r   	get_tokenZTokenReader.get_tokeng   s    
 **s4;;//DKK

4K4S4S4U4U

a
::T[[))DJJ'

a
r   c                   V ^8  d   QhRR/# r   r
   r	   r   r   r   r   r   r,   w   s      = r   c                sL    V P                  4       pV'       d   \        V4      # R# )zvReturns the next token, skipping whitespace tokens. This method cleans the token
with clean_token() if it is not None.N)r3   r   )r.   r&   s   & r   get_cleaned_tokenZTokenReader.get_cleaned_tokenw   s!      u%%r   c               r   )r   stop_functionzCallable[[TokenReader], bool]r
   r	   r   r   r   r   r   r,      s     7 78U 7Zg 7r   c                s"   Rp V P                  4       pVf   McVP                  R4      '       d   V'       g   V P                  4       pM3V! V 4      '       d   M$Y P                  RR7      ;'       g    R,          pKy  V'       d   \        V4      # R# )aA  This reads token until the end of tokens, or until a stop token is reached;
that stop token is not consumed. The tokens are concatenated, including white-space
between them, and returns. Whitespace around the tokens is stripped.

Returns None if we reach the end of tokens before any non-whitespace token.

If this first non-whitespace token is quoted, then this token is cleaned and returned,
and we stop with that.

Thus, if the token reader starts before quoted text, we return that text unquoted, and if
not we return all text up to but not including a 'stop_tokens' token.r   Nr   F)r1   )
peek_tokenr   r3   r   )r.   r7   r#   peeked   &&  r   get_cleaned_token_sequenceZ&TokenReader.get_cleaned_token_sequence   s~     __&F~  %%!^^-FT""nnn6<<"<F&,{6"6$6r   c               r4   r5   r   r   r   r   r   r,      s      M r   c                sJ    V P                   pV P                  4       pWn         V# )zReturns the next token, or None if the end of tokens has been reached. However,
will not advance - repeated calls return the same token.r-   r3   )r.   saved_indexr&   r   r   r8   ZTokenReader.peek_token   s#     jj  
r   c               r   )r   countZintr
   r   r   r   r   r   r   r,      s        r   c                s    . pV P                   p\        ^ V4       F.  pV P                  4       pV'       g    MVP                  V4       K0  	  W0n         V# )zReturns the next 'count' tokens, or as many as are present before
the end of tokens has been reached. However, this will not advance - repeated calls
return the same tokens.)r-   Zranger3   r!   )r.   r>   r9   r=   Z_ir&   s   &&    r   peek_tokensZTokenReader.peek_tokens   sL    
 jj5/BNN$EMM% 	 "
 !
r   c               r   )r   r'   r   r
   r2   r   r   r   r   r   r,      s     
 
 
 
r   c                sj    V P                   pV P                  4       pV'       d	   W18X  d   R# W n         R# )z{If the next token is 'candidate', consumes it and returns True;
if not returns False and leaves the token reader as it was.TFr<   )r.   r'   r=   r&   r:   r   consumeZTokenReader.consume   s,     jj + 
r   )r-   r"   N)T)Z__name__Z
__module__Z__qualname__Z__firstlineno__Z__doc__r/   r0   r3   r6   r;   r8   r?   r@   Z__static_attributes__r   r   r   r+   r+   [   s5    Q. 7< 
 
r   r+   N)
Z
__future__r   Ztypingr   r   r   r   r   r*   r+   r   r   r   <module>rA      s&    " 5 5	F(Rg gr   