<s> """<STR_LIT>""" <EOL> import coretypes as T <EOL> import pyast <EOL> import re <EOL> class _TypeConversion ( pyast . _astVisitor ) : <EOL> "<STR_LIT>" <EOL> def _Expression ( self , tree ) : return self . visit ( tree . body ) <EOL> def _Name ( self , tree ) : <EOL> id = tree . id <EOL> if ( id in T . __dict__ ) and isinstance ( T . __dict__ [ id ] , T . Monotype ) : <EOL> return T . __dict__ [ id ] <EOL> else : <EOL> return tree . id <EOL> def _BinOp ( self , tree ) : <EOL> if type ( tree . op ) != pyast . ast . RShift : <EOL> raise SyntaxError , "<STR_LIT>" % tree . op <EOL> L = self . visit ( tree . left ) <EOL> R = self . visit ( tree . right ) <EOL> return T . Fn ( L , R ) <EOL> def _Lambda ( self , tree ) : <EOL> args = self . visit ( tree . args . args ) <EOL> body = self . visit ( tree . body ) <EOL> print "<STR_LIT>" , repr ( body ) <EOL> return T . Polytype ( args , body ) <EOL> def _Call ( self , tree ) : <EOL> conx = self . visit ( tree . func ) <EOL> args = self . visit ( tree . args ) <EOL> if ( id in T . __dict__ ) and isinstance ( T . __dict__ [ id ] , T . Monotype ) : <EOL> return T . __dict__ [ id ] ( * args ) <EOL> else : <EOL> return T . Monotype ( conx , * args ) <EOL> def _Tuple ( self , tree ) : return T . Tuple ( * self . visit ( tree . elts ) ) <EOL> def _List ( self , tree ) : return T . Seq ( * self . visit ( tree . elts ) ) <EOL> def _pythonify_type ( text ) : <EOL> """<STR_LIT>""" <EOL> text = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , text ) <EOL> text = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , text ) <EOL> return text . strip ( ) <EOL> _convert_type = _TypeConversion ( ) <EOL> def type_from_text ( text ) : <EOL> past = pyast . ast . parse ( _pythonify_type ( text ) , "<STR_LIT>" , mode = '<STR_LIT>' ) <EOL> return T . quantify_type ( _convert_type ( past ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> def trial ( text ) : <EOL> t = type_from_text ( text ) <EOL> print <EOL> print text , "<STR_LIT>" , str ( t ) <EOL> print "<STR_LIT:U+0020>" , repr ( t ) <EOL> trial ( "<STR_LIT>" ) <EOL> trial ( "<STR_LIT>" ) <EOL> trial ( "<STR_LIT>" ) <EOL> trial ( "<STR_LIT>" ) <EOL> trial ( "<STR_LIT>" ) </s>
