ok
Direktori : /proc/thread-self/root/opt/alt/python36/lib64/python3.6/idlelib/__pycache__/ |
Current File : //proc/thread-self/root/opt/alt/python36/lib64/python3.6/idlelib/__pycache__/pyparse.cpython-36.pyc |
3 � f�N � @ s d Z ddlZed�\ZZZZZejdej ej B �jZejdej �j Zejdej ejB �j Zejdej �j Zejdej �j Zejd ej �j ZG d d� de�Zejed�d �Zejdd� dD �� ejdd� dD �� ejdd� dD �� G dd� d�Zedk�rddlmZ eddd� dS )a� Define partial Python code Parser used by editor and hyperparser. Instances of ParseMap are used with str.translate. The following bound search and match functions are defined: _synchre - start of popular statement; _junkre - whitespace or comment line; _match_stringre: string, possibly without closer; _itemre - line that may have bracket structure start; _closere - line that must be followed by dedent. _chew_ordinaryre - non-special characters. � N� z� ^ [ \t]* (?: while | else | def | return | assert | break | class | continue | elif | try | except | raise | import | yield ) \b z' [ \t]* (?: \# \S .* )? \n aK \""" [^"\\]* (?: (?: \\. | "(?!"") ) [^"\\]* )* (?: \""" )? | " [^"\\\n]* (?: \\. [^"\\\n]* )* "? | ''' [^'\\]* (?: (?: \\. | '(?!'') ) [^'\\]* )* (?: ''' )? | ' [^'\\\n]* (?: \\. [^'\\\n]* )* '? zM [ \t]* [^\s#\\] # if we match, m.end()-1 is the interesting char z_ \s* (?: return | break | continue | raise | pass ) \b z [^[\](){}#'"\\]+ c @ s e Zd ZdZdd� ZdS )�ParseMapap Dict subclass that maps anything not in dict to 'x'. This is designed to be used with str.translate in study1. Anything not specifically mapped otherwise becomes 'x'. Example: replace everything except whitespace with 'x'. >>> keepwhite = ParseMap((ord(c), ord(c)) for c in ' \t\n\r') >>> "a + b\tc\nd".translate(keepwhite) 'x x x\tx\nx' c C s dS )N�x � )�self�keyr r �4/opt/alt/python36/lib64/python3.6/idlelib/pyparse.py�__missing__r s zParseMap.__missing__N)�__name__� __module__�__qualname__�__doc__r r r r r r f s r � r c c s | ]}t |�t d �fV qdS )�(N)�ord)�.0�cr r r � <genexpr>x s r z({[c c s | ]}t |�t d �fV qdS )�)N)r )r r r r r r y s z)}]c c s | ]}t |�t |�fV qd S )N)r )r r r r r r z s z"'\ #c @ s� e Zd Zdd� Zdd� Zdefdd�Zdd � Zd d� Zdd � Z dd� Z dd� Zdd� Zdd� Z dd� Zdd� Zdd� Zdd� ZdS )�Parserc C s || _ || _d S )N)�indentwidth�tabwidth)r r r r r r �__init__ s zParser.__init__c C s, t |�dks|d dkst�|| _d| _d S )Nr � � ���)�len�AssertionError�code�study_level)r �sr r r �set_code� s zParser.set_codeNc C s� | j d }}|sdS t|�}xftd�D ]Z}|jdd|�}|dk rBP |jdd|�d }||||�}|r|||j� � r||j� }P |}q&W |dkr�||�}|r�||j� � r�|j� }|S |d }x.|||�}|r�|j� \} }|| �s�| }q�P q�W |S )a^ Return index of a good place to begin parsing, as close to the end of the string as possible. This will be the start of some popular stmt like "if" or "def". Return None if none found: the caller should pass more prior context then, if possible, or if not (the entire program text up until the point of interest has already been tried) pass 0 to set_lo(). This will be reliable iff given a reliable is_char_in_string() function, meaning that when it says "no", it's absolutely guaranteed that the char is not in a string. Nr z: r r r )r r �range�rfind�start�span) r Zis_char_in_string�_synchrer �pos�limitZtries�i�mr r r r �find_good_parse_start� s8 zParser.find_good_parse_startc C s: |dks| j |d dkst�|dkr6| j |d� | _ dS )zx Throw away the start of the string. Intended to be called with the result of find_good_parse_start(). r r r N)r r )r �lor r r �set_lo� s z Parser.set_loc C s | j dkrdS d| _ | j}|jt�}|jdd�}|jdd�}|jdd�}|jdd�}|jdd�}t}d }}d g | _}|j}d t|� }}�x||k �r�|| } |d }| dkr�q�| dkr�|d }|d kr�||� q�| d kr�|d }q�| dk�r |r�|d }q�| dk�s| d k�r2| } ||d |d � | d k�r>| d } |}t| �d }|| }x�||k �r|| } |d }| dk�r��qX||d || � | k�r�|| }P | dk�r�|d }|d k�rX|d k�r�||� P �qX| dk�rX||k �s�t �|| dk�r|d }|d }�qX�qXW |d |k�r,t }q�t}q�| dk�rV|jd|�}|d ks�t �q�| dk�sdt �||k �srt �|| dk�r�|d }|d |k�r�t }|d }q�W |t k�r�|tk�r�|d k�r�t}|| _|tk|d |kk�s�t �|d |k�r�||� dS )z�Find the line numbers of non-continuation lines. As quickly as humanly possible <wink>, find the line numbers (0- based) of the non-continuation lines. Creates self.{goodlines, continuation}. r NZxxxxxxxx�xZxxxxZxxz xr r r r �"�'� � �\�#r r )r r � translate�trans�replace�C_NONE� goodlines�appendr r �C_STRING_FIRST_LINE�C_STRING_NEXT_LINES�find�C_BACKSLASH� C_BRACKET�continuation) r r r@ �levelZlnor9 Z push_goodr) �n�chZquoteZfirstlno�wr r r �_study1� s� zParser._study1c C s | j � | jS )N)rE r@ )r r r r �get_continuation_typeT s zParser.get_continuation_typec C s� | j dkrdS | j� d| _ | j| j }}t|�d }t|�}x`|r�|sLt�|}x4t||d || �D ]}|jdd|d �d }qhW t||�r�|d }q@P q@W |dkr�|dks�t�|}|| | _ | _ d}g }|j} |dfg} �x�||k �r�t|||�}|�rX|j � }|d }x&||k�r4|| dk�r4|d }�qW ||k�rH|| }|}||k�rXP || } | dk�r�| |� | j|t|�f� | }|d }q�| d k�r�|�r�|d= | }|d }| j|t|�f� q�| d k�s�| dk�r| j|t|�d f� | }t|||�j � }| j|t|�f� q�| dk�rn| j|t|�d f� |jd||�d }|dk�sZt�| j|t|�f� q�| d k�s|t�|d }||k �s�t�|| dk�r�| || }|d }q�W || _|�r�|d nd| _t| �| _dS )am study1 was sufficient to determine the continuation status, but doing more requires looking at every character. study2 does this for the last interesting statement in the block. Creates: self.stmt_start, stmt_end slice indices of last interesting stmt self.stmt_bracketing the bracketing structure of the last interesting stmt; for example, for the statement "say(boo) or die", stmt_bracketing will be ((0, 0), (0, 1), (2, 0), (2, 1), (4, 0)). Strings and comments are treated as brackets, for the matter. self.lastch last interesting character before optional trailing comment self.lastopenbracketpos if continuation is C_BRACKET, index of last open bracket r1 Nr r r � z z([{z)]}r/ r0 r4 r3 r r )r rE r r9 r r r"