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"""
@@ -52,12 +50,12 @@ def _main_call_to_code(in_initial_call: core.InitialCall, **kwargs) -> str:
5250
5351
5452def _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 )
53+ main_call_str = "\n " + main_call if main_call else " "
54+ contains_str = (
55+ " \n contains \n " + " \n " . join ( function_definitions )
56+ if function_definitions
57+ else " \n "
58+ )
6159 return f"""program main
6260 implicit none{ main_call_str } { contains_str } end program main
6361"""
0 commit comments