e fM2 @ s d Z d d l Z d d l m Z d d l m Z e e j e j d Z e e j d Z
d d e d D Z d d e d D Z
Gd
d d Z e d k r d d l Z e j d
d d n d S)zProvide advanced parsing abilities for ParenMatch and other extensions.
HyperParser uses PyParser. PyParser mostly gives information on the
proper indentation of code. HyperParser gives additional information on
the structure of code.
N) iskeyword)PyParse_c C s" g | ] } t | t k q S )chr_ASCII_ID_CHARS).0xr r 8/opt/alt/python34/lib64/python3.4/idlelib/HyperParser.py
s r c C s" g | ] } t | t k q Sr )r _ASCII_ID_FIRST_CHARS)r r r r r
r s c @ s e Z d Z d d Z d d Z d d Z d d Z d d
d d Z e d
d d h Z e
d d Z d Z d d Z
d S)HyperParserc
s | _ | j _ } t j | j | j } d d } | | j | } | j sx | j D] } t | | d } t
| d } d | }
| j | j | |
d | j
| j | } | d k s | d k re Pqe qe W| j | p d n_ | j d | } | r(| d } n d
} d | }
| j | j | |
d | j d | j d d _ |
_ | j _ f d d
t t j D _ j | d S)z;To initialize, analyze the surroundings of the given index.c S s t t | S)N)intfloat)indexr r r
index2line# s z(HyperParser.__init__..index2line z.0z%d.endz
Nr Zconsolez1.0 c sB g | ]8 } | d k o; j | d j | d d k q S)r r )
bracketing)r i)selfr r
r L s z(HyperParser.__init__..)editwintextr ZParserZindentwidthZtabwidthr Zcontext_use_ps1Znum_context_linesmaxreprZset_strgetZfind_good_parse_startZ_build_char_in_string_funcZset_loZ
tag_prevrangestrrawtextstopatindexZget_last_stmt_bracketingr rangelenisopener set_index)
r r r r parserr ZlnocontextZstartatZstartatindexr Zbodrr )r r
__init__ s:
zHyperParser.__init__c C s t | j t | j j | | j } | d k rJ t d | n | | _ d | _ xP | j t | j d k r | j | j d d | j k r | j d 7_ q_ W| j t | j d k r| j | j d d | j k r| j | j d r| j d 7_ n d S)zgSet the index to which the functions relate.
The index must be in the same statement.
r z(Index %s precedes the analyzed statementr N)
r" r r r r
ValueErrorindexinrawtextindexbracketr r# )r r r* r r r
r$ R s
!!zHyperParser.set_indexc C s/ | j | j o. | j | j | j d d k S)z2Is the index given to the HyperParser in a string?r "')r, r- )r# r+ r r )r r r r
is_in_stringg s zHyperParser.is_in_stringc C s0 | j | j p/ | j | j | j d d k S)z5Is the index given to the HyperParser in normal code?r #r, r- )r/ r, r- )r# r+ r r )r r r r
is_in_codeo s zHyperParser.is_in_codez([{Fc C s | j | j d } | j } x{ | j | sc | j | j | d | k sc | j | d | k r | d 8} | d k r} d St | | j | d } q W| j d } x: | t | j k r | j | d | k r | d 7} q W| j j d | j t | j | j | d f } | t | j k sQ| j | d t | j k rg| r[d S| j } n; | j j d | j t | j | j | d d f } | | f S)a Return bracket indexes or None.
If the index given to the HyperParser is surrounded by a
bracket defined in openers (or at least has one before it),
return the indices of the opening bracket and the closing
bracket (or the end of line, whichever comes first).
If it is not surrounded by brackets, or the end of line comes
before the closing bracket and mustclose is True, returns None.
r r Nz%s-%dc) r r+ r# r minr" r r r )r ZopenersZ mustcloseZbracketinglevelZbeforeafterZbeforeindexZ
afterindexr r r
get_surrounding_bracketsu s0
+ )z$HyperParser.get_surrounding_bracketsTrueFalseNonec C s t } | } xL | | k rZ t | | d d k rZ | t | | d rZ | d 8} q W| | k rSt | | d d k rSx<