
    <iu                        d Z ddlmZ dZ	 ddlZddlmZ ddlmZ dZ	n# e
$ r dZ	Y nw xY wdd	lmZ g d
Z G d de          Z G d d          Z G d d          ZdS )z@Lexical analysis of formal languages (i.e. code) using Pygments.    )annotationsreStructuredTextN)get_lexer_by_name)_get_ttype_classTF)ApplicationError)tokentext c                      e Zd ZdS )
LexerErrorN)__name__
__module____qualname__     /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/docutils/utils/code_analyzer.pyr   r      s        Dr   r   c                  (    e Zd ZdZd	d
dZd Zd ZdS )Lexera  Parse `code` lines and yield "classified" tokens.

    Arguments

      code       -- string of source code to parse,
      language   -- formal language the code is written in,
      tokennames -- either 'long', 'short', or 'none' (see below).

    Merge subsequent tokens of the same token-type.

    Iterating over an instance yields the tokens as ``(tokentype, value)``
    tuples. The value of `tokennames` configures the naming of the tokentype:

      'long':  downcased full token type name,
      'short': short name defined by pygments.token.STANDARD_TYPES
               (= class argument used in pygments html output),
      'none':  skip lexical analysis.
    shortreturnNonec                
   || _         || _        || _        d| _        |dv s|dk    rdS t          st          d          	 t          | j                  | _        dS # t          j        j	        $ r t          d|z            w xY w)zE
        Set up a lexical analyzer for `code` in `language`.
        N)r
   r	   nonez0Cannot analyze code. Pygments package not found.z6Cannot analyze code. No Pygments lexer found for "%s".)
codelanguage
tokennameslexerwith_pygmentsr   r   pygmentsutilClassNotFound)selfr   r   r   s       r   __init__zLexer.__init__4   s     	 $
|##zV';';F 	< ; < < <	M*4=99DJJJ}* 	M 	M 	M ACKL M M M	Ms    A 'Bc              #     K   t          |          }t          |          \  }}|D ]\  }}||u r||z  }||fV  ||}}|                    d          }|r||fV  dS dS )zrMerge subsequent tokens of same token-type.

           Also strip the final newline (added by pygments).
        
N)iternextremovesuffix)r"   tokenslasttypelastvalttypevalues         r   mergezLexer.mergeO   s      
 f"6ll7" 	5 	5LE5  5 ''''',e7&&t,, 	$G######	$ 	$r   c              #  j  K   | j         g | j        fV  dS t          j        | j        | j                   }|                     |          D ]g\  }}| j        dk    r5t          |                                                              d          }nt          |          g}d |D             }||fV  hdS )z7Parse self.code and yield "classified" tokens.
        Nlong.c                $    g | ]}|t           v|S r   )unstyled_tokens).0clss     r   
<listcomp>z"Lexer.__iter__.<locals>.<listcomp>l   s"    LLLsO1K1Ks1K1K1Kr   )
r   r   r   lexr.   r   strlowersplitr   )r"   r)   	tokentyper-   classess        r   __iter__zLexer.__iter__`   s       :di-Fdi44 $

6 2 2 	! 	!Iu&((i....0066s;;+I667LLgLLLG5.    	! 	!r   N)r   r   r   )r   r   r   __doc__r#   r.   r=   r   r   r   r   r       sZ         &M M M M M6$ $ $"! ! ! ! !r   r   c                       e Zd ZdZddZd ZdS )NumberLinesaq  Insert linenumber-tokens at the start of every code line.

    Arguments

       tokens    -- iterable of ``(classes, value)`` tuples
       startline -- first line number
       endline   -- last line number

    Iterating over an instance yields the tokens with a
    ``(['ln'], '<the line number>')`` token added for every code line.
    Multi-line tokens are split.r   r   c                l    || _         || _        dt          t          |                     d| _        d S )N%zd )r)   	startlinelenr8   fmt_str)r"   r)   rD   endlines       r   r#   zNumberLines.__init__}   s4    "03s7||,,000r   c              #     K   | j         }dg| j        |z  fV  | j        D ]P\  }}|                    d          }|d d         D ]}||dz   fV  |dz  }dg| j        |z  fV   ||d         fV  Qd S )Nlnr%      )rD   rF   r)   r:   )r"   linenor,   r-   lineslines         r   r=   zNumberLines.__iter__   s      fdlV+++++ K 	# 	#LE5KK%%Ecrc
 4 4TD[((((!fdlV333333r"""""	# 	#r   Nr>   )r   r   r   r?   r#   r=   r   r   r   rA   rA   p   sA        
$ 
$1 1 1 1	# 	# 	# 	# 	#r   rA   )r?   
__future__r   __docformat__r   pygments.lexersr   pygments.formatters.htmlr   r   ImportErrordocutilsr   r3   r   r   rA   r   r   r   <module>rU      s5  
 G F " " " " " ""OOO111111999999MM   MMM & % % % % %  	 	 	 	 	! 	 	 	M! M! M! M! M! M! M! M!`# # # # # # # # # #s    ))