
    -Ph8                         d Z ddlm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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.    )ApplicationErrorN)get_lexer_by_name)_get_ttype_classTF)tokentext c                       e Zd ZdS )
LexerErrorN)__name__
__module____qualname__     \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/docutils/utils/code_analyzer.pyr
   r
      s        Dr   r
   c                   &    e Zd ZdZ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.
    shortc                 
   || _         || _        || _        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__/   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
|d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endswith)r   tokenslasttypelastvalttypevalues         r   mergezLexer.mergeJ   s      
 f"6ll7" 	5 	5LE5  5 ''''',e7D!! 	#crclG 	$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>h   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   __doc__r   r+   r:   r   r   r   r   r      sT         &M M M M6$ $ $$! ! ! ! !r   r   c                       e Zd ZdZ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.c                 j    || _         || _        dt          t          |                    z  | _        d S )Nz%%%dd )r&   	startlinelenr5   fmt_str)r   r&   r?   endlines       r   r   zNumberLines.__init__y   s.    "#c'll"3"33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!   r"      )r?   rA   r&   r7   )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   N)r   r   r   r;   r   r:   r   r   r   r=   r=   l   s<        
$ 
$4 4 4	# 	# 	# 	# 	#r   r=   )r;   docutilsr   r   pygments.lexersr   pygments.formatters.htmlr   r   ImportErrorr0   r
   r   r=   r   r   r   <module>rM      s  
 G F % % % % % %OOO111111999999MM   MMM  	 	 	 	 	! 	 	 	N! N! N! N! N! N! N! N!b# # # # # # # # # #s    ''