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 ú