File: //lib/python3.6/site-packages/docutils/utils/__pycache__/code_analyzer.cpython-36.opt-1.pyc
3
w2�e- � @ s� d Z ddlmZ y(ddlZddlmZ ddlmZ dZW n e e
fk
rT dZY nX dd d
gZG dd� de�ZG d
d� de
�ZG dd� de
�ZdS )z@Lexical analysis of formal languages (i.e. code) using Pygments.� )�ApplicationErrorN)�get_lexer_by_name)�_get_ttype_classTF�token�text� c @ s e Zd ZdS )�
LexerErrorN)�__name__�
__module__�__qualname__� r r �#/usr/lib/python3.6/code_analyzer.pyr s r c @ s* e Zd ZdZd
dd�Zdd� Zdd� Zd 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 '' (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 C sr || _ || _|| _d| _|dks(|dkr,dS ts8td��yt| j�| _W n$ tjj k
rl td| ��Y nX dS )zE
Set up a lexical analyzer for `code` in `language`.
Nr r Znonez0Cannot analyze code. Pygments package not found.z6Cannot analyze code. No Pygments lexer found for "%s".)r r )
�code�language�
tokennames�lexer�
with_pygmentsr r �pygments�utilZ
ClassNotFound)�selfr r r r r r
�__init__/ s zLexer.__init__c c st t |�}t|�\}}x6|D ].\}}||kr4||7 }q||fV || }}qW |jd�rb|dd� }|rp||fV dS )zrMerge subsequent tokens of same token-type.
Also strip the final newline (added by pygments).
�
N� ���)�iter�next�endswith)r �tokensZlasttypeZlastval�ttype�valuer r r
�mergeG s
zLexer.mergec c s� | j dkrg | jfV dS tj| j| j �}xV| j|�D ]H\}}| jdkr\t|�j� jd�}n
t |�g}dd� |D �}||fV q6W dS )z7Parse self.code and yield "classified" tokens.
NZlong�.c S s g | ]}|t kr|�qS r )�unstyled_tokens)�.0�clsr r r
�
<listcomp>e s z"Lexer.__iter__.<locals>.<listcomp>)
r r r Zlexr"