
    f2iu                        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	dd	lmZ g d
Z G d de      Z G d d      Z G d d      Zy# e
$ r dZ	Y 3w xY w)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y)
LexerErrorN)__name__
__module____qualname__     f/mnt/e/genesis-system/.venvs/voice-bridge/lib/python3.12/site-packages/docutils/utils/code_analyzer.pyr   r      s    r   r   c                  &    e Zd ZdZdddZd Zd Zy)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.
    c                   || _         || _        || _        d| _        |dv s|dk(  ryt        st        d      	 t        | j                        | _        y# 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'; ; < <	M*4==9DJ}}** 	M ACKL M M	Ms   A ,B c              #     K   t        |      }t        |      \  }}|D ]  \  }}||u r||z  }||f ||}} |j                  d      }|r||f yyw)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"6l7" 	5LE5 5 ''',e7	5 &&t,G## s   AAc              #    K   | j                   g | j                  f yt        j                  | j                  | j                         }| j	                  |      D ]g  \  }}| j
                  dk(  r)t        |      j                         j                  d      }nt        |      g}|D cg c]  }|t        vs| }}||f i yc c}w w)z7Parse self.code and yield "classified" tokens.
        Nlong.)r   r   r   lexr+   r   strlowersplitr   unstyled_tokens)r   r&   	tokentyper*   classesclss         r   __iter__zLexer.__iter__`   s      ::dii-dii4 $

6 2 	!Iu&(i...066s;+I67&-LsO1KsLGL5. 	!
 Ms   B'C)C7C;CN)shortreturnNone)r   r   r   __doc__r    r+   r7   r   r   r   r   r       s    &M6$"!r   r   c                      e Zd ZdZddZd Zy)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                Z    || _         || _        dt        t        |             d| _        y )N%zd )r&   	startlinelenr0   fmt_str)r   r&   rA   endlines       r   r    zNumberLines.__init__}   s*    "3s7|,-R0r   c              #     K   | j                   }dg| j                  |z  f | j                  D ]K  \  }}|j                  d      }|d d D ]$  }||dz   f |dz  }dg| j                  |z  f & ||d   f M y w)Nlnr"      )rA   rC   r&   r2   )r   linenor)   r*   lineslines         r   r7   zNumberLines.__iter__   s     fdllV+++ KK 	#LE5KK%Ecr
 4TD[((!fdllV3334 r""	#s   A<A>Nr9   )r   r   r   r<   r    r7   r   r   r   r>   r>   p   s    
$1	#r   r>   )r<   
__future__r   __docformat__r   pygments.lexersr   pygments.formatters.htmlr   r   ImportErrordocutilsr   r3   r   r   r>   r   r   r   <module>rR      sm   
 G ""19M &	! 	M! M!`# #A  Ms   A AA