python (3.12.0)
̑eM J d Z ddlZ ed \ ZZZZZ ej dej ej z j Z ej dej j Z ej dej ej z j Z ej dej j Z ej dej j Z ej d ej j Z G d
de Zej- ed d
Zej1 d dD ej1 d dD ej1 d dD G d d Zedk( rddlmZ edd yy)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 e Zd ZdZd Zy)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 y)Nx )selfkeys C/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/idlelib/pyparse.py__missing__zParseMap.__missing__r s N)__name__
__module____qualname____doc__r r r
r r r f s r
r r c # H K | ] }t | t d f yw)(Nord.0cs r <genexpr>r x /Ac!fc#h
/ "z({[c # H K | ] }t | t d f yw))Nr r s r r r y r r z)}]c # H K | ] }t | t | f y wNr r s r r r z s 2!c!fc!f
2r z"'\
#c ` e Zd Zd Zd Zd Zd Zd Zd Zd Z d Z
d Zd
Zd Z
d Zd
Zd Zy)Parserc || _ || _ y r )indentwidthtabwidth)r r$ r% s r __init__zParser.__init__ s &
r
c P t | dk( s
|d dk( sJ || _ d| _ y )Nr
)lencodestudy_level)r ss r set_codezParser.set_code s) 1v{aetm+ r
c | j d}}t | }t d D ]k }|j dd| }|dk r nQ|j dd| dz }t ||| }|r( ||j s|j } n|}m |5t | }|r& ||j s|j }|S |dz }t || x}r,|j
\ }} || s|}t || x}r,|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* rangerfind_synchrestartspan) r is_char_in_stringr+ poslimittriesimr- s r find_good_parse_startzParser.find_good_parse_start s IItc
D 1X E
5!U+A1u
4A&*Aq%(A*17795ggiE ; A*17795ggiJ
!GD!$$a$668DAq$Q' D!$$a$
r
c p |dk( s| j |dz
dk( sJ |dkD r| j |d | _ yy)zx Throw away the start of the string.
Intended to be called with the result of find_good_parse_start().
r r0 r) N)r+ )r los r set_loz
Parser.set_lo s>