string-to-code 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- string_to_code/to_fortran90.py +14 -16
- string_to_code/to_kotlin.py +71 -0
- {string_to_code-0.4.0.dist-info → string_to_code-0.5.0.dist-info}/METADATA +1 -2
- {string_to_code-0.4.0.dist-info → string_to_code-0.5.0.dist-info}/RECORD +6 -5
- {string_to_code-0.4.0.dist-info → string_to_code-0.5.0.dist-info}/WHEEL +1 -1
- {string_to_code-0.4.0.dist-info → string_to_code-0.5.0.dist-info}/LICENSE +0 -0
string_to_code/to_fortran90.py
CHANGED
|
@@ -12,13 +12,13 @@ _get_function_name = utils.get_function_name_fun("fun_")
|
|
|
12
12
|
def _atom_to_code(in_atom: core.Atom) -> str:
|
|
13
13
|
if in_atom.atom_char == "\n":
|
|
14
14
|
return "write (*, *)"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
+
)
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
_function_call_str = utils.get_function_call_str_fun(_get_function_name, "call ", "()")
|
|
@@ -32,9 +32,7 @@ _body_to_str = utils.get_body_to_str("\n", " ", _call_function_or_atom, "
|
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
def _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 ""
|
|
38
36
|
return f""" subroutine {in_function_name}()
|
|
39
37
|
{body_str} end subroutine {in_function_name}
|
|
40
38
|
"""
|
|
@@ -52,12 +50,12 @@ def _main_call_to_code(in_initial_call: core.InitialCall, **kwargs) -> str:
|
|
|
52
50
|
|
|
53
51
|
|
|
54
52
|
def _join_to_final(main_call: str, function_definitions: list[str], **_kwargs) -> str:
|
|
55
|
-
main_call_str = ""
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
main_call_str = "\n " + main_call if main_call else ""
|
|
54
|
+
contains_str = (
|
|
55
|
+
"\ncontains\n" + "\n".join(function_definitions)
|
|
56
|
+
if function_definitions
|
|
57
|
+
else "\n"
|
|
58
|
+
)
|
|
61
59
|
return f"""program main
|
|
62
60
|
implicit none{main_call_str}{contains_str}end program main
|
|
63
61
|
"""
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""
|
|
2
|
+
provides string_to_kotlin utilities
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from . import core
|
|
6
|
+
from . import utils
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
_get_function_name = utils.get_function_name_fun("fun")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _atom_to_code(in_atom: core.Atom) -> str:
|
|
13
|
+
if in_atom.atom_char == "\n":
|
|
14
|
+
return "println()"
|
|
15
|
+
special_chars = {
|
|
16
|
+
'"': '\\"',
|
|
17
|
+
"'": "\\'",
|
|
18
|
+
"\\": "\\\\",
|
|
19
|
+
"\t": "\\t",
|
|
20
|
+
"{": "{",
|
|
21
|
+
"}": "}",
|
|
22
|
+
}
|
|
23
|
+
res_char = special_chars.get(in_atom.atom_char, in_atom.atom_char)
|
|
24
|
+
return f"print('{res_char}')"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
_function_call_str = utils.get_function_call_str_fun(_get_function_name, "", "()")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
_call_function_or_atom = utils.get_call_function_or_atom(
|
|
31
|
+
_atom_to_code, _function_call_str
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
_EMPTY_BODY = " // No code needed"
|
|
35
|
+
|
|
36
|
+
_body_to_str = utils.get_body_to_str(
|
|
37
|
+
"\n", " ", _call_function_or_atom, "", _EMPTY_BODY
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _merge_to_full_function(in_function_name, in_function_body):
|
|
42
|
+
body_str = "\n" + in_function_body + "\n"
|
|
43
|
+
return f"fun {in_function_name}() {{{body_str}}}\n"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
_function_to_code = utils.get_function_to_code(
|
|
47
|
+
_get_function_name, _body_to_str, _merge_to_full_function
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _main_call_to_code(in_initial_call, **kwargs):
|
|
52
|
+
call_in_main = (
|
|
53
|
+
"\n" + _EMPTY_BODY
|
|
54
|
+
if in_initial_call is None
|
|
55
|
+
else "\n " + _call_function_or_atom(in_initial_call, **kwargs)
|
|
56
|
+
)
|
|
57
|
+
return "fun main() {" + call_in_main + "\n}\n"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _join_to_final(main_call, function_definitions, **_kwargs):
|
|
61
|
+
function_definitions_str = (
|
|
62
|
+
"\n".join(function_definitions) if function_definitions else ""
|
|
63
|
+
)
|
|
64
|
+
if function_definitions_str:
|
|
65
|
+
function_definitions_str = function_definitions_str + "\n"
|
|
66
|
+
return function_definitions_str + main_call
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
proc_printer_program, proc = utils.get_all_proc_functions(
|
|
70
|
+
_main_call_to_code, _function_to_code, _join_to_final
|
|
71
|
+
)
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: string-to-code
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Generates a piece of messy code in a given language displaying a given string
|
|
5
|
-
Home-page: https://github.com/vil02/string_to_code_proj
|
|
6
5
|
License: MIT
|
|
7
6
|
Keywords: code-generation
|
|
8
7
|
Author: piotr.idzik
|
|
@@ -10,9 +10,10 @@ string_to_code/to_bash.py,sha256=FJI2WTYO0gDDFSyRwHwERuLFKqOBX79y4xsXa_K_5D4,163
|
|
|
10
10
|
string_to_code/to_c.py,sha256=CeCzih5WoNABUg4dgps82wG783H8nW3FHj-69HZ5iOU,1008
|
|
11
11
|
string_to_code/to_cobol.py,sha256=eOWf6I5paH4eBpwUxmgrNN9AoBPFr0weYmeJe2CkEzk,2130
|
|
12
12
|
string_to_code/to_cpp.py,sha256=PJYScszyoSToyHmVbWvrNFtZsRkDWFaPg49Ug0xlnzk,1026
|
|
13
|
-
string_to_code/to_fortran90.py,sha256=
|
|
13
|
+
string_to_code/to_fortran90.py,sha256=wyMxeaW68l9AqMjvkosEpbarUnGWw4aZTX3sOzhWc5E,1792
|
|
14
14
|
string_to_code/to_haskell.py,sha256=WvNznkqmYXSsfrl5LkoDedB_uyJIgvqBz_YMM065PD0,1977
|
|
15
15
|
string_to_code/to_java.py,sha256=63LPDTrMqnukXMW0XHVX6aXHq-63NckQLiG3YmdaAYg,1865
|
|
16
|
+
string_to_code/to_kotlin.py,sha256=iBTof4UHAqIOzUEf5IyJ4CQicM8KGFtMLhSzbBgVnVM,1822
|
|
16
17
|
string_to_code/to_lisp.py,sha256=BKkJorzyAbSmmOUt3otqHAapjOR6GblMM-ymekga1wY,1605
|
|
17
18
|
string_to_code/to_lua.py,sha256=DeRnBH3PFmyABqFVqmXNSN4c79awYkZJ9ZTmeabIAKI,2045
|
|
18
19
|
string_to_code/to_nim.py,sha256=W74i6MRjQ5eYeatGyMwE-wYNEzN06l5oOXBv3lfbXgM,1534
|
|
@@ -20,7 +21,7 @@ string_to_code/to_pascal.py,sha256=OE2qefRgYhvx8AOn83m3q2gQh_Haoo3fqo12IfxKT28,1
|
|
|
20
21
|
string_to_code/to_python3.py,sha256=BJwjyhRB2IBOE3-xwkkMV3vZU-e2xreppYBKQeA1whg,1589
|
|
21
22
|
string_to_code/to_rust.py,sha256=hTCjlortLhR7FwsBgbrFRcwXpKWA6ed2UYnz1OK8R7I,1926
|
|
22
23
|
string_to_code/utils.py,sha256=0On1KjJ0dMHyS4xp1f8RIJcfcT5-CfocHTx3kDVRi5I,3847
|
|
23
|
-
string_to_code-0.
|
|
24
|
-
string_to_code-0.
|
|
25
|
-
string_to_code-0.
|
|
26
|
-
string_to_code-0.
|
|
24
|
+
string_to_code-0.5.0.dist-info/LICENSE,sha256=LQrcSkcUyN1FtFYDxWK05puxNN9o2q8PV-_2SwFDTWc,1068
|
|
25
|
+
string_to_code-0.5.0.dist-info/METADATA,sha256=UCVciizgeHif8Dv8L8CClO8umBAv0gUGWrThlUQq50g,1902
|
|
26
|
+
string_to_code-0.5.0.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
|
27
|
+
string_to_code-0.5.0.dist-info/RECORD,,
|
|
File without changes
|