
    dd8                         d Z ddlmZ 	 ddlZddlmZ ddlmZ dZg dZ
 G d	 d
e      Z G d d      Z G d d      Zy# e	$ r dZY -w xY w)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y)
LexerErrorN)__name__
__module____qualname__     >/usr/lib/python3/dist-packages/docutils/utils/code_analyzer.pyr
   r
      s    r   r
   c                   $    e Zd ZdZ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__/   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|dd }|r||f yyw)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"6l7" 	5LE5 5 ''',e7	5 D!crlG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)r   r   r   __doc__r   r*   r6   r   r   r   r   r      s    &M6$$!r   r   c                       e Zd ZdZ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                 X    || _         || _        dt        t        |            z  | _        y )Nz%%%dd )r%   	startlinelenr/   fmt_str)r   r%   r<   endlines       r   r   zNumberLines.__init__y   s%    "#c'l"33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    r!      )r<   r>   r%   r1   )r   linenor(   r)   lineslines         r   r6   zNumberLines.__iter__   s     fdllV+++ KK 	#LE5KK%Ecr
 4TD[((!fdllV3334 r""	#s   A<A>N)r   r   r   r8   r   r6   r   r   r   r:   r:   l   s    
$4	#r   r:   )r8   docutilsr   r   pygments.lexersr   pygments.formatters.htmlr   r   ImportErrorr2   r
   r   r:   r   r   r   <module>rJ      sc   
 G %19M
	! 	N! N!b# #  Ms   A   A
	A
