Your IP : 3.145.44.46
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 || _ d| _d S )Nr )�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 �len�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 |dkr| j |d� | _ dS )zx Throw away the start of the string.
Intended to be called with the result of find_good_parse_start().
r N)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 �rn|| } |d }| dkr�q�| dkr�|d }|d kr�||� q�| d
kr�|d }q�| dk�r |r�|d }q�| dk�s| d
k�r$| }
||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|| dk�r�|d }|d }�qX�qXW |d |k�rt }q�t
}q�| dk�r<|jd|�}q�|| dk�rd|d }|d |k�rdt}|d }q�W |t k�r�|t
k�r�|d k�r�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 � translate�trans�replace�C_NONE� goodlines�appendr �C_STRING_FIRST_LINE�C_STRING_NEXT_LINES�find�C_BACKSLASH� C_BRACKET�continuation)
r r r? �levelZlnor8 Z push_goodr'