
    k7iu                        S r SSKJr  Sr SSKrSSKJr  SSKJr  Sr	SS	KJr  / S
Qr " S S\5      r " S S5      r " S S5      rg! \
 a    Sr	 N4f = f)z@Lexical analysis of formal languages (i.e. code) using Pygments.    )annotationsreStructuredTextN)get_lexer_by_name)_get_ttype_classTF)ApplicationError)tokentext c                      \ rS rSrSrg)
LexerError    N)__name__
__module____qualname____firstlineno____static_attributes__r       V/home/james-whalen/.local/lib/python3.13/site-packages/docutils/utils/code_analyzer.pyr   r      s    r   r   c                  2    \ rS rSrSrSS	S jjrS rS rSrg)
Lexer    aq  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                   Xl         X l        X0l        SU l        US;   d  US:X  a  g[        (       d  [        S5      e [        U R                  5      U l        g! [        R                  R                   a    [        SU-  5      ef = f)z5
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__Lexer.__init__4   s     	 $
|#zV';} ; < <	M*4==9DJ}}** 	M ACKL M M	Ms   A -Bc              #     #    [        U5      n[        U5      u  p#U H  u  pEXBL a  X5-  nM  X#4v   XEp2M     UR                  S5      nU(       a  X#4v   gg7f)z_Merge 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   mergeLexer.mergeO   sg     
 f"6l"LE  ''',7 # &&t,## s   AAc              #    #    U R                   c  / U R                  4v   g[        R                  " U R                  U R                   5      nU R	                  U5       Hl  u  p#U R
                  S:X  a)  [        U5      R                  5       R                  S5      nO[        U5      /nU Vs/ s H  oU[        ;  d  M  UPM     nnXC4v   Mn     gs  snf 7f)z7Parse self.code and yield "classified" tokens.
        Nlong.)r   r   r    lexr0   r   strlowersplitr   unstyled_tokens)r#   r+   	tokentyper/   classesclss         r   __iter__Lexer.__iter__`   s      ::dii-dii4 $

6 2I&(i...066s;+I67&-LgsO1KsgGL.  !3
 Ms   B)C+C<CC)r   r   r   r   N)shortreturnNone)	r   r   r   r   __doc__r$   r0   r=   r   r   r   r   r   r       s    &M6$"!r   r   c                  (    \ rS rSrSrSS jrS rSrg)NumberLinesp   aU  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                V    Xl         X l        S[        [        U5      5       S3U l        g )N%zd )r+   	startlinelenr6   fmt_str)r#   r+   rI   endlines       r   r$   NumberLines.__init__}   s&    "3s7|,-R0r   c              #    #    U R                   nS/U R                  U-  4v   U R                   HK  u  p#UR                  S5      nUS S  H$  nX%S-   4v   US-  nS/U R                  U-  4v   M&     X$S   4v   MM     g 7f)Nlnr'      )rI   rK   r+   r8   )r#   linenor.   r/   lineslines         r   r=   NumberLines.__iter__   s     fdllV+++ KKLEKK%Ecr
D[((!fdllV333 # r"" (s   A=A?)rK   rI   r+   Nr@   )r   r   r   r   rC   r$   r=   r   r   r   r   rE   rE   p   s    
$1	#r   rE   )rC   
__future__r   __docformat__r    pygments.lexersr   pygments.formatters.htmlr   r   ImportErrordocutilsr   r9   r   r   rE   r   r   r   <module>r\      sm   
 G ""19M &	! 	M! M!`# #A  Ms   A AA