<s> from pseudo . code_generator import CodeGenerator , switch <EOL> from pseudo . middlewares import DeclarationMiddleware , NameMiddleware , TupleMiddleware <EOL> from pseudo . pseudo_tree import Node , local <EOL> OPS = { '<STR_LIT>' : '<STR_LIT:!>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> def index_switch ( s ) : <EOL> if isinstance ( s . sequence . pseudo_type , list ) and s . sequence . pseudo_type [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> elif s . index . type != '<STR_LIT:int>' or s . index . value >= <NUM_LIT:0> : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT:z>' <EOL> class CSharpGenerator ( CodeGenerator ) : <EOL> '''<STR_LIT>''' <EOL> indent = <NUM_LIT:4> <EOL> use_spaces = True <EOL> middlewares = [ TupleMiddleware ( all = False ) , <EOL> DeclarationMiddleware , <EOL> NameMiddleware ( <EOL> normal_name = '<STR_LIT>' , <EOL> method_name = '<STR_LIT>' , <EOL> function_name = '<STR_LIT>' ) ] <EOL> types = { <EOL> '<STR_LIT>' : '<STR_LIT:int>' , <EOL> '<STR_LIT>' : '<STR_LIT:float>' , <EOL> '<STR_LIT>' : '<STR_LIT:bool>' , <EOL> '<STR_LIT>' : '<STR_LIT:string>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : lambda x : '<STR_LIT>' . format ( '<STR_LIT:U+002CU+0020>' . join ( x ) ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> templates = dict ( <EOL> module = '''<STR_LIT>''' , <EOL> function_definition = '''<STR_LIT>''' , <EOL> method_definition = '''<STR_LIT>''' , <EOL> method_definition_is_public = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> class_definition = '''<STR_LIT>''' , <EOL> class_definition_base = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> class_definition_constructor = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> class_attr = "<STR_LIT>" , <EOL> class_attr_is_public = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> immutable_class_attr = '''<STR_LIT>''' , <EOL> anonymous_function = "<STR_LIT>" , <EOL> constructor = '''<STR_LIT>''' , <EOL> dependency = '<STR_LIT>' , <EOL> local = '<STR_LIT>' , <EOL> typename = '<STR_LIT>' , <EOL> int = '<STR_LIT>' , <EOL> float = '<STR_LIT>' , <EOL> string = '<STR_LIT>' , <EOL> boolean = '<STR_LIT>' , <EOL> null = '<STR_LIT:null>' , <EOL> simple_initializer = "<STR_LIT>" , <EOL> list = switch ( lambda l : len ( l . elements ) > <NUM_LIT:0> , <EOL> true = "<STR_LIT>" , <EOL> _otherwise = "<STR_LIT>" <EOL> ) , <EOL> dictionary = switch ( lambda d : len ( d . pairs ) > <NUM_LIT:0> , <EOL> true = "<STR_LIT>" , <EOL> _otherwise = "<STR_LIT>" <EOL> ) , <EOL> pair = "<STR_LIT>" , <EOL> attr = "<STR_LIT>" , <EOL> new_instance = "<STR_LIT>" , <EOL> assignment = switch ( '<STR_LIT>' , <EOL> true = '<STR_LIT>' , <EOL> _otherwise = '<STR_LIT>' <EOL> ) , <EOL> tuple = switch ( lambda e : len ( e . elements ) <= <NUM_LIT:2> , <EOL> true = "<STR_LIT>" , <EOL> _otherwise = '''<STR_LIT>''' ) , <EOL> array = "<STR_LIT>" , <EOL> set = switch ( lambda s : len ( s . elements ) > <NUM_LIT:0> , <EOL> true = "<STR_LIT>" , <EOL> _otherwise = "<STR_LIT>" <EOL> ) , <EOL> char = "<STR_LIT>" , <EOL> binary_op = '<STR_LIT>' , <EOL> unary_op = '<STR_LIT>' , <EOL> comparison = '<STR_LIT>' , <EOL> static_call = "<STR_LIT>" , <EOL> call = "<STR_LIT>" , <EOL> method_call = "<STR_LIT>" , <EOL> this_method_call = "<STR_LIT>" , <EOL> this = '<STR_LIT>' , <EOL> instance_variable = '<STR_LIT>' , <EOL> throw_statement = '<STR_LIT>' , <EOL> if_statement = '''<STR_LIT>''' , <EOL> if_statement_otherwise = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> elseif_statement = '''<STR_LIT>''' , <EOL> elseif_statement_otherwise = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> else_statement = '''<STR_LIT>''' , <EOL> while_statement = '''<STR_LIT>''' , <EOL> try_statement = '''<STR_LIT>''' , <EOL> exception_handler = '''<STR_LIT>''' , <EOL> exception_handler_exception = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> for_each_statement = '''<STR_LIT>''' , <EOL> for_each_with_index_statement = '''<STR_LIT>''' , <EOL> for_each_with_index_statement_sequence = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> for_each_in_zip_statement = '''<STR_LIT>''' , <EOL> implicit_return = '<STR_LIT>' , <EOL> explicit_return = '<STR_LIT>' , <EOL> index = switch ( index_switch , <EOL> tuple = '<STR_LIT>' , <EOL> normal = '<STR_LIT>' , <EOL> _otherwise = '<STR_LIT>' <EOL> ) , <EOL> interpolation = "<STR_LIT>" , <EOL> interpolation_placeholder = "<STR_LIT>" , <EOL> interpolation_literal = "<STR_LIT>" , <EOL> index_assignment = '<STR_LIT>' , <EOL> not_null_check = '<STR_LIT>' , <EOL> constant = '<STR_LIT>' , <EOL> for_statement = switch ( lambda f : f . iterators . type , <EOL> for_iterator_with_index = '''<STR_LIT>''' , <EOL> for_iterator_zip = '''<STR_LIT>''' , <EOL> for_iterator_with_items = '''<STR_LIT>''' , <EOL> _otherwise = '''<STR_LIT>''' <EOL> ) , <EOL> for_range_statement = '''<STR_LIT>''' , <EOL> for_range_statement_first = ( '<STR_LIT>' , '<STR_LIT:0>' ) , <EOL> for_range_statement_step = ( '<STR_LIT>' , '<STR_LIT:1>' ) , <EOL> for_iterator = '<STR_LIT>' , <EOL> for_iterator_zip = "<STR_LIT>" , <EOL> for_iterator_with_index = '<STR_LIT>' , <EOL> for_iterator_with_items = '<STR_LIT>' , <EOL> for_sequence = '<STR_LIT>' , <EOL> custom_exception = '''<STR_LIT>''' , <EOL> standard_iterable_call = '''<STR_LIT>''' , <EOL> aug_assignment = '<STR_LIT>' , <EOL> block = '<STR_LIT>' , <EOL> regex = '<STR_LIT>' <EOL> ) <EOL> def params ( self , node , indent ) : <EOL> return '<STR_LIT:U+002CU+0020>' . join ( <EOL> '<STR_LIT>' % ( <EOL> self . render_type ( node . pseudo_type [ j + <NUM_LIT:1> ] ) , <EOL> self . _generate_node ( k ) ) for j , k in enumerate ( node . params ) ) <EOL> def anon_params ( self , node , indent ) : <EOL> if len ( node . params ) == <NUM_LIT:0> : <EOL> return '<STR_LIT>' <EOL> else : <EOL> l , r = ( '<STR_LIT:(>' , '<STR_LIT:)>' ) if len ( node . params ) > <NUM_LIT:1> else ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return '<STR_LIT>' % ( l , '<STR_LIT:U+002CU+0020>' . join ( param if isinstance ( param , str ) else self . _generate_node ( param ) for param in node . params ) , r ) <EOL> def anon_block ( self , node , indent ) : <EOL> if indent < <NUM_LIT:2> : <EOL> indent = <NUM_LIT:2> <EOL> if len ( node . block ) == <NUM_LIT:1> : <EOL> if node . block [ <NUM_LIT:0> ] . type == '<STR_LIT>' or node . block [ <NUM_LIT:0> ] . type == '<STR_LIT>' : <EOL> e = node . block [ <NUM_LIT:0> ] . value <EOL> else : <EOL> e = node . block [ <NUM_LIT:0> ] <EOL> b = self . _generate_node ( e ) <EOL> return '<STR_LIT:U+0020>' + b <EOL> else : <EOL> b = '<STR_LIT>' . join ( self . offset ( indent + <NUM_LIT:1> ) + self . _generate_node ( e , indent + <NUM_LIT:1> ) for e in node . block ) + '<STR_LIT>' <EOL> return '<STR_LIT>' % ( b , self . offset ( indent ) ) <EOL> def class_definitions ( self , node , depth ) : <EOL> result = '<STR_LIT:\n>' . join ( self . _generate_node ( k ) for k in node . definitions if k . type == '<STR_LIT>' ) <EOL> if result : <EOL> return result + '<STR_LIT:\n>' <EOL> else : <EOL> return '<STR_LIT>' <EOL> def function_definitions ( self , node , depth ) : <EOL> result = '<STR_LIT:\n>' . join ( self . offset ( <NUM_LIT:1> ) + self . _generate_node ( f , <NUM_LIT:1> ) for f in node . definitions if f . type == '<STR_LIT>' ) <EOL> if result : <EOL> return result + '<STR_LIT:\n>' <EOL> else : <EOL> return '<STR_LIT>' <EOL> def base ( self , node , depth ) : <EOL> if node . base : <EOL> return '<STR_LIT>' % node . base <EOL> else : <EOL> return '<STR_LIT>' <EOL> def first_sequence ( self , node , depth ) : <EOL> return self . _generate_node ( node . sequences . sequences [ <NUM_LIT:0> ] ) <EOL> def zip_iterators ( self , node , depth ) : <EOL> return '<STR_LIT:\n>' . join ( <EOL> '<STR_LIT>' % ( <EOL> self . offset ( depth ) if j else '<STR_LIT>' , <EOL> q . name , <EOL> self . _generate_node ( <EOL> Node ( '<STR_LIT:index>' , <EOL> sequence = node . sequences . sequences [ j ] , <EOL> index = local ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> pseudo_type = node . sequences . sequences [ j ] . pseudo_type [ <NUM_LIT:1> ] ) ) ) <EOL> for j , q <EOL> in enumerate ( node . iterators . iterators ) ) <EOL> def tuple_index ( self , node , depth ) : <EOL> return str ( node . index . value + <NUM_LIT:1> ) <EOL> def op ( self , node , depth ) : <EOL> return OPS . get ( node . op , node . op ) <EOL> def char ( self , node , depth ) : <EOL> if node . value == "<STR_LIT:'>" : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" % node . value <EOL> def comparison ( self , node , depth ) : <EOL> if node . left . type != '<STR_LIT>' or node . left . op != '<STR_LIT:+>' or node . left . right . type != '<STR_LIT:int>' or node . right . type != '<STR_LIT:int>' : <EOL> pass <EOL> else : <EOL> node . right . value -= node . left . right . value <EOL> node . left = node . left . left <EOL> return '<STR_LIT>' % ( self . binary_left ( node , depth ) , node . op , self . binary_right ( node , depth ) ) <EOL> def z ( self , node , depth ) : <EOL> print ( node . y ) <EOL> input ( ) <EOL> return '<STR_LIT>' <EOL> def index ( self , node , depth ) : <EOL> return str ( - node . index . value ) <EOL> def placeholders ( self , node , depth ) : <EOL> return '<STR_LIT:U+002CU+0020>' . join ( self . _generate_node ( child . value ) for child in node . args [ <NUM_LIT:1> : : <NUM_LIT:2> ] ) </s>
