1212def _atom_to_code (in_atom : core .Atom ) -> str :
1313 if in_atom .atom_char == "\n " :
1414 return "write (*, *)"
15- res = 'write (*, "(A)", advance="no") '
16- if in_atom . atom_char == '"' :
17- return res + "' \" '"
18- if in_atom . atom_char == " \t " :
19- return res + "char(9)"
20-
21- return res + f'" { in_atom . atom_char } "'
15+ special_chars = {
16+ '"' : "' \" '" ,
17+ " \t " : "char(9)" ,
18+ }
19+ return 'write (*, "(A)", advance="no") ' + special_chars . get (
20+ in_atom . atom_char , f'" { in_atom . atom_char } "'
21+ )
2222
2323
2424_function_call_str = utils .get_function_call_str_fun (_get_function_name , "call " , "()" )
@@ -32,9 +32,7 @@ def _atom_to_code(in_atom: core.Atom) -> str:
3232
3333
3434def _merge_to_full_function (in_function_name : str , in_function_body : str ) -> str :
35- body_str = ""
36- if in_function_body :
37- body_str = in_function_body + "\n "
35+ body_str = in_function_body + "\n " if in_function_body else ""
3836 return f""" subroutine { in_function_name } ()
3937{ body_str } end subroutine { in_function_name }
4038"""
@@ -46,18 +44,20 @@ def _merge_to_full_function(in_function_name: str, in_function_body: str) -> str
4644
4745
4846def _main_call_to_code (in_initial_call : core .InitialCall , ** kwargs ) -> str :
49- if in_initial_call is None :
50- return ""
51- return _call_function_or_atom (in_initial_call , ** kwargs )
47+ return (
48+ ""
49+ if in_initial_call is None
50+ else _call_function_or_atom (in_initial_call , ** kwargs )
51+ )
5252
5353
5454def _join_to_final (main_call : str , function_definitions : list [str ], ** _kwargs ) -> str :
55- main_call_str = ""
56- if main_call :
57- main_call_str = " \n " + main_call
58- contains_str = " \n "
59- if function_definitions :
60- contains_str = " \n contains \n " + " \n " . join ( function_definitions )
55+ main_call_str = "\n " + main_call if main_call else " "
56+ contains_str = (
57+ " \n contains \n " + " \n " . join ( function_definitions )
58+ if function_definitions
59+ else " \n "
60+ )
6161 return f"""program main
6262 implicit none{ main_call_str } { contains_str } end program main
6363"""
0 commit comments