-
Notifications
You must be signed in to change notification settings - Fork 0
/
to_lisp.py
62 lines (41 loc) · 1.57 KB
/
to_lisp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
provides string_to_lisp utilities
"""
from . import core
from . import utils
_get_function_name = utils.get_function_name_fun()
def atom_to_code(in_atom: core.Atom) -> str:
"""
returns a string/piece of lisp code resulting in printing the
in_atom.atom_char to the standard output
"""
def proc_char(in_char):
special_char_dict = {
"\n": "#\\Newline",
"\t": "#\\Tab",
" ": "#\\Space",
}
return special_char_dict.get(in_char, "#\\" + in_char)
return f'(format T "~c" {proc_char(in_atom.atom_char)})'
_function_call_str = utils.get_function_call_str_fun(_get_function_name, "(", ")")
_call_function_or_atom = utils.get_call_function_or_atom(
atom_to_code, _function_call_str
)
_body_to_str = utils.get_body_to_str("", "\n ", _call_function_or_atom, "", "")
def _merge_to_full_function(in_function_name, in_function_body):
return f"(defun {in_function_name} (){in_function_body})\n"
_function_to_code = utils.get_function_to_code(
_get_function_name, _body_to_str, _merge_to_full_function
)
def _main_call_to_code(in_initial_call, **kwargs):
return (
""
if in_initial_call is None
else _call_function_or_atom(in_initial_call, **kwargs)
)
def _join_to_final(main_call, function_definitions, **_kwargs):
main_call_with_ending = main_call + "\n" if main_call else ""
return "\n".join(function_definitions + [main_call_with_ending])
proc_printer_program, proc = utils.get_all_proc_functions(
_main_call_to_code, _function_to_code, _join_to_final
)