ž ©ÿfB)c@sEdZddlZddlZddlmZGdd„dƒZdS(uk HyperParser =========== This module defines the HyperParser class, which provides advanced parsing abilities for the ParenMatch and other extensions. The HyperParser uses PyParser. PyParser is intended mostly to give information on the proper indentation of code. HyperParser gives some information on the structure of code, used by extensions to help the user. iN(uPyParsecBs•|EeZdZdd„Zdd„Zdd„Zdd„Zd dd d „Zd Z e j e j d Z e j d Zdd„Zdd„ZdS(u HyperParserc sÌ|ˆ_|jˆ_}tj|j|jƒ}dd„}||j|ƒƒ}|jsx|jD]„}t ||dƒ}t |ƒd} d|} |j |j | | ƒdƒ|j |j| ƒƒ} | d k så|dkrePqeqeW|j| püdƒn_|jd|ƒ} | r(| d} nd } d|} |j |j | | ƒdƒ|jdƒ|jd d…ˆ_| ˆ_|jƒˆ_‡fd d †ttˆjƒƒDƒˆ_ˆj|ƒd S(u[Initialize the HyperParser to analyze the surroundings of the given index. cSstt|ƒƒS(N(uintufloat(uindex((u8/opt/alt/python33/lib64/python3.3/idlelib/HyperParser.pyu index2linesu(HyperParser.__init__..index2lineiu.0u%d.endu iuconsoleu1.0NicsBg|]8}|dko;ˆj|dˆj|ddk‘qS(ii(u bracketing(u.0ui(uself(u8/opt/alt/python33/lib64/python3.3/idlelib/HyperParser.pyu Cs u(HyperParser.__init__..iþÿÿÿ(ueditwinutextuPyParseuParseru indentwidthutabwidthuindexucontext_use_ps1unum_context_linesumaxurepruset_strugetufind_good_parse_startu_build_char_in_string_funcuNoneuset_lou tag_prevrangeustrurawtextu stopatindexuget_last_stmt_bracketingu bracketingurangeulenuisopeneru set_index( uselfueditwinuindexutextuparseru index2lineulnoucontextustartatu startatindexu stopatindexubodur((uselfu8/opt/alt/python33/lib64/python3.3/idlelib/HyperParser.pyu__init__s:        uHyperParser.__init__cCst|jƒt|jj||jƒƒ}|dkrFtdƒ‚n||_d|_xP|jt|jƒdkrª|j|jdd|jkrª|jd7_q[W|jt|jƒdkr|j|jdd|jkr|j |jd r|jd7_ndS(uiSet the index to which the functions relate. Note that it must be in the same statement. iu0The index given is before the analyzed statementiN( ulenurawtextutextugetu stopatindexu ValueErroruindexinrawtextu indexbracketu bracketinguisopener(uselfuindexuindexinrawtext((u8/opt/alt/python33/lib64/python3.3/idlelib/HyperParser.pyu set_indexHs+   !!uHyperParser.set_indexcCs/|j|jo.|j|j|jddkS(u5Is the index given to the HyperParser is in a string?iu"u'(u"u'(uisopeneru indexbracketurawtextu bracketing(uself((u8/opt/alt/python33/lib64/python3.3/idlelib/HyperParser.pyu is_in_string[suHyperParser.is_in_stringcCs0|j|j p/|j|j|jddkS(u:Is the index given to the HyperParser is in a normal code?iu#u"u'(u#u"u'(uisopeneru indexbracketurawtextu bracketing(uself((u8/opt/alt/python33/lib64/python3.3/idlelib/HyperParser.pyu is_in_codebsuHyperParser.is_in_codeu([{c Cs¬|j|jd}|j}x{|j| sc|j|j|d|ksc|j|d|krš|d8}|dkr}dSt||j|dƒ}q W|jd}x:|t|jƒkrä|j|d|krä|d7}q«W|jjd|j t|jƒ|j|dfƒ}|t|jƒksQ|j|dt|jƒkrg|r[dS|j }n;|jjd|j t|jƒ|j|ddfƒ}||fS(u’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. iiu%s-%dcN( u bracketingu indexbracketuisopenerurawtextuNoneuminulenutextuindexu stopatindex(uselfuopenersu mustcloseubracketinglevelubeforeuafteru beforeindexu afterindex((u8/opt/alt/python33/lib64/python3.3/idlelib/HyperParser.pyuget_surrounding_bracketshs0     +   )u$HyperParser.get_surrounding_bracketsu \u_cCsƒ|}x1||kr9||d|jkr9|d8}q W||kr{|||jksrtj|||…ƒr{|}n||S(Ni(u _id_charsu_id_first_charsukeywordu iskeyword(uselfustrulimituposui((u8/opt/alt/python33/lib64/python3.3/idlelib/HyperParser.pyu_eat_identifier˜s& uHyperParser._eat_identifierc Csu|jƒstdƒ‚n|j}|j}|j}||d}|j}|}d }xxÏ||kr||d|jkr|d8}q_| rÉ||krÉ||ddkrÉ|d8}d }q_||kr*|dkr*|||dddkr*|d8}||d}||dd}q_Pq_|s8Pn|j|||ƒ}|rl||}|}d }q\||kr`||d} x2|dkrº||dd| krº|d8}q‰W||d|krÓPn||d}|d8}||d}|}||dkrqa||dkr\x.|dkrR||dd krR|d8}q%W|}nPq\Pq\|||j…S( u‚Return a string with the Python expression which ends at the given index, which is empty if there is no real one. u?get_expression should only be called if index is inside a code.iiu.u#iu([u'"urRbBuUTF( u is_in_codeu ValueErrorurawtextu bracketingu indexbracketuindexinrawtextuTrueu_whitespace_charsu_eat_identifieruFalse( uselfurawtextu bracketingu brck_indexu brck_limituposulast_identifier_posu postdot_phaseuretulevel((u8/opt/alt/python33/lib64/python3.3/idlelib/HyperParser.pyuget_expression¡sb     #        ' # uHyperParser.get_expressionNF(u__name__u __module__u __qualname__u__init__u set_indexu is_in_stringu is_in_codeuFalseuget_surrounding_bracketsu_whitespace_charsustringu ascii_lettersudigitsu _id_charsu_id_first_charsu_eat_identifieruget_expression(u __locals__((u8/opt/alt/python33/lib64/python3.3/idlelib/HyperParser.pyu HyperParsers 7   '  u HyperParser(u__doc__ustringukeyworduidlelibuPyParseu HyperParser(((u8/opt/alt/python33/lib64/python3.3/idlelib/HyperParser.pyu s