ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python36/lib64/python3.6/idlelib/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python36/lib64/python3.6/idlelib/__pycache__/pyparse.cpython-36.pyc

3

� f�N�@sdZddlZed�\ZZZZZejdej	ej
B�jZejdej	�j
Zejdej	ejB�j
Zejdej	�j
Zejdej	�j
Zejd	ej	�j
ZGd
d�de�Zejed�d
�Zejdd�dD��ejdd�dD��ejdd�dD��Gdd�d�Zedk�rddlmZeddd�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@seZdZdZdd�ZdS)�ParseMapapDict 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'
    cCsdS)N�x�)�self�keyrr�4/opt/alt/python36/lib64/python3.6/idlelib/pyparse.py�__missing__rszParseMap.__missing__N)�__name__�
__module__�__qualname__�__doc__r	rrrrrfs
r�rccs|]}t|�td�fVqdS)�(N)�ord)�.0�crrr�	<genexpr>xsrz({[ccs|]}t|�td�fVqdS)�)N)r)rrrrrrysz)}]ccs|]}t|�t|�fVqdS)N)r)rrrrrrzsz"'\
#c@s�eZdZdd�Zdd�Zdefdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�ParsercCs||_||_dS)N)�indentwidth�tabwidth)rrrrrr�__init__szParser.__init__cCs,t|�dks|ddkst�||_d|_dS)Nr��
���)�len�AssertionError�code�study_level)r�srrr�set_code�szParser.set_codeNc
Cs�|jd}}|sdSt|�}xftd�D]Z}|jdd|�}|dkrBP|jdd|�d}||||�}|r|||j��r||j�}P|}q&W|dkr�||�}|r�||j��r�|j�}|S|d}x.|||�}|r�|j�\}	}||	�s�|	}q�Pq�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.
        Nrz:
rrr)rr�range�rfind�start�span)
rZis_char_in_string�_synchrer�pos�limitZtries�i�mr rrr�find_good_parse_start�s8	
zParser.find_good_parse_startcCs:|dks|j|ddkst�|dkr6|j|d�|_dS)zx Throw away the start of the string.

        Intended to be called with the result of find_good_parse_start().
        rrrN)rr)r�lorrr�set_lo�sz
Parser.set_loc
Cs|jdkrdSd|_|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�|	dk�s|	d
k�r2|	}
||d|d�|
dk�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|jd|�}|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}.
        rNZxxxxxxxx�xZxxxxZxxz
xrrrr�"�'���\�#rr)rr�	translate�trans�replace�C_NONE�	goodlines�appendrr�C_STRING_FIRST_LINE�C_STRING_NEXT_LINES�find�C_BACKSLASH�	C_BRACKET�continuation)
rrr@�levelZlnor9Z	push_goodr)�n�chZquoteZfirstlno�wrrr�_study1�s�










zParser._study1cCs|j�|jS)N)rEr@)rrrr�get_continuation_typeTszParser.get_continuation_typecCs�|jdkrdS|j�d|_|j|j}}t|�d}t|�}x`|r�|sLt�|}x4t||d||�D]}|jdd|d�d}qhWt||�r�|d}q@Pq@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|�df�|
}t|||�j
�}|
j|t|�f�q�|
dk�rn|
j|t|�df�|jd||�d}|dk�sZt�|
j|t|�f�q�|
d
k�s|t�|d}||k�s�t�||dk�r�|
||}|d}q�W||_|�r�|dnd|_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
        r1Nrrr�z 	
z([{z)]}r/r0r4r3rr)rrErr9rrr"r#�_junkre�
stmt_start�stmt_endr:�_chew_ordinaryre�end�_match_stringrer=�lastch�lastopenbracketpos�tuple�stmt_bracketing)rrr9r)�p�qZnothingrN�stackZ
push_stackZ
bracketingr*ZnewprCrrr�_study2Xs�








zParser._study2cCs�|j�|jtkst�|j}|j}t|�}|jdd|�d}}|d}xj||kr�t||�}|rt|j	�d}d}PqJ|j
d|�d}}qJW|}}x||dkr�|d}q�W|j}t|||�j|j
��|S)zpReturn number of spaces the next line should be indented.

        Line continuation must be C_BRACKET.
        rrrz 	)rUr@r?rrOrrr#�_itemrerLr=r�
expandtabsr)r�jrrBZorigir)r*Zextrarrr�compute_bracket_indent�s&

zParser.compute_bracket_indentcCs|j�|j}|d|dS)z�Return number of physical lines in last stmt.

        The statement doesn't have to be an interesting statement.  This is
        intended to be called when continuation is C_BACKSLASH.
        rr1r���)rEr9)rr9rrr�get_num_lines_in_stmt�szParser.get_num_lines_in_stmtcCs�|j�|jtkst�|j}|j}x||dkr:|d}q$W|}|jd|�d}d}}x�||k�r$||}|dkr�|d}|d}qZ|dkr�|r�|d}|d}qZ|dks�|dkr�t|||�j�}qZ|d	kr�PqZ|dk�r|d
k�r|dkp�||ddk�r||dd
k�rd}PqZ|d}qZW|�rL|d}t	j
d|||��d
k}|�st|}x||dk�rr|d}�qXWt||j|�j|j
��dS)z�Return number of spaces the next line should be indented.

        Line continuation must be C_BACKSLASH.  Also assume that the new
        line is the first one following the initial line of the stmt.
        z 	rrrz([{z)]}r/r0r4�=z=<>!z\s*\\Nz 	
)rUr@r>rrrIr=rMrL�re�matchrrWr)rrr)�startpos�endpos�foundrArCrrr�compute_backslash_indent�sJ

zParser.compute_backslash_indentcCsN|j�|j|j}}|}|j}x ||kr@||dkr@|d}q"W|||�S)z`Return the leading whitespace on the initial line of the last
        interesting stmt.
        z 	r)rUrIrJr)rr)rBrXrrrr�get_base_indent_string5szParser.get_base_indent_stringcCs|j�|jdkS)z=Return True if the last interesting statemtent opens a block.�:)rUrN)rrrr�is_block_openerAszParser.is_block_openercCs|j�t|j|j�dk	S)z=Return True if the last interesting statement closes a block.N)rU�_closererrI)rrrr�is_block_closerFszParser.is_block_closercCs|j�|jS)z�Return bracketing structure of the last interesting statement.

        The returned tuple is in the format defined in _study2().
        )rUrQ)rrrr�get_last_stmt_bracketingKszParser.get_last_stmt_bracketing)r
rrrr!r&r+r-rErFrUrYr[rbrcrergrhrrrrr}s <	{
9r�__main__)�mainzidlelib.idle_test.test_pyparser1)�	verbosity)r
r]r"r8r>r;r<r?�compile�VERBOSE�	MULTILINE�searchr&r^rH�DOTALLrMrVrfrK�dictr�fromkeysr6�updaterr
Zunittestrjrrrr�<module>s4	Z


Zerion Mini Shell 1.0