string-to-code 0.2.14__py3-none-any.whl → 0.3.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/core.py +12 -10
- string_to_code/string_to_code.py +1 -1
- string_to_code/to_ada.py +1 -1
- string_to_code/to_algol68.py +3 -3
- string_to_code/to_haskell.py +2 -2
- string_to_code/to_lua.py +74 -0
- string_to_code/to_pascal.py +1 -1
- string_to_code/utils.py +6 -6
- {string_to_code-0.2.14.dist-info → string_to_code-0.3.0.dist-info}/METADATA +1 -1
- {string_to_code-0.2.14.dist-info → string_to_code-0.3.0.dist-info}/RECORD +12 -11
- {string_to_code-0.2.14.dist-info → string_to_code-0.3.0.dist-info}/LICENSE +0 -0
- {string_to_code-0.2.14.dist-info → string_to_code-0.3.0.dist-info}/WHEEL +0 -0
string_to_code/core.py
CHANGED
|
@@ -33,14 +33,14 @@ SimpleFunctions: typing.TypeAlias = list[SimpleFunction]
|
|
|
33
33
|
|
|
34
34
|
def str_pieces(in_str: str, in_pieces_len: list[int]) -> Strings:
|
|
35
35
|
"""returns in_str split into pieces of lengths as in in_pieces_len"""
|
|
36
|
-
assert all(_ > 0 for _ in in_pieces_len)
|
|
37
|
-
assert sum(in_pieces_len) == len(in_str)
|
|
36
|
+
assert all(_ > 0 for _ in in_pieces_len) # nosec B101
|
|
37
|
+
assert sum(in_pieces_len) == len(in_str) # nosec B101
|
|
38
38
|
cur_str = in_str
|
|
39
39
|
res = []
|
|
40
40
|
for _ in in_pieces_len:
|
|
41
41
|
res.append(cur_str[:_])
|
|
42
42
|
cur_str = cur_str[_:]
|
|
43
|
-
assert "".join(res) == in_str
|
|
43
|
+
assert "".join(res) == in_str # nosec B101
|
|
44
44
|
return res
|
|
45
45
|
|
|
46
46
|
|
|
@@ -49,11 +49,11 @@ def random_pieces_len(in_total_len: int) -> list[int]:
|
|
|
49
49
|
cur_num = in_total_len
|
|
50
50
|
res = []
|
|
51
51
|
while cur_num > 0:
|
|
52
|
-
tmp_len = random.randint(1, max(cur_num, 1))
|
|
52
|
+
tmp_len = random.randint(1, max(cur_num, 1)) # nosec B311
|
|
53
53
|
res.append(tmp_len)
|
|
54
54
|
cur_num -= tmp_len
|
|
55
55
|
random.shuffle(res)
|
|
56
|
-
assert sum(res) == in_total_len
|
|
56
|
+
assert sum(res) == in_total_len # nosec B101
|
|
57
57
|
return res
|
|
58
58
|
|
|
59
59
|
|
|
@@ -63,7 +63,7 @@ def random_split(in_str: str) -> Strings:
|
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
def _interesting_random_split(in_str: str) -> Strings:
|
|
66
|
-
assert len(in_str) > 1
|
|
66
|
+
assert len(in_str) > 1 # nosec B101
|
|
67
67
|
res = random_split(in_str)
|
|
68
68
|
while len(res) == 1:
|
|
69
69
|
res = random_split(in_str)
|
|
@@ -114,12 +114,14 @@ class PrinterProgram:
|
|
|
114
114
|
|
|
115
115
|
def _check_data(self) -> None:
|
|
116
116
|
if self.initial_call is not None and not isinstance(self.initial_call, Atom):
|
|
117
|
-
assert self.needed_functions
|
|
117
|
+
assert self.needed_functions # nosec B101
|
|
118
118
|
if self.needed_functions:
|
|
119
|
-
assert isinstance(self.initial_call, int)
|
|
120
|
-
assert self.initial_call + 1 == len(self.needed_functions)
|
|
119
|
+
assert isinstance(self.initial_call, int) # nosec B101
|
|
120
|
+
assert self.initial_call + 1 == len(self.needed_functions) # nosec B101
|
|
121
121
|
for fun_id, fun in enumerate(self.needed_functions):
|
|
122
|
-
assert all(
|
|
122
|
+
assert all(
|
|
123
|
+
_ < fun_id for _ in fun.called_list if not isinstance(_, Atom)
|
|
124
|
+
) # nosec B101
|
|
123
125
|
|
|
124
126
|
def needed_function_definitions_str_list(
|
|
125
127
|
self, in_function_to_str, **kwargs
|
string_to_code/string_to_code.py
CHANGED
string_to_code/to_ada.py
CHANGED
|
@@ -79,7 +79,7 @@ def _join_to_final(main_call: str, function_definitions: list[str], **kwargs) ->
|
|
|
79
79
|
]
|
|
80
80
|
)
|
|
81
81
|
if function_definitions or main_call != _MAIN_NULL_CALL:
|
|
82
|
-
assert "Ada.Text_IO." in res
|
|
82
|
+
assert "Ada.Text_IO." in res # nosec B101
|
|
83
83
|
res = "with Ada.Text_IO;\n\n" + res
|
|
84
84
|
return res
|
|
85
85
|
|
string_to_code/to_algol68.py
CHANGED
|
@@ -32,7 +32,7 @@ _body_to_str = utils.get_body_to_str("\n", " ", _call_function_or_atom, "", "")
|
|
|
32
32
|
def _merge_to_full_function(in_function_name: str, in_function_body: str) -> str:
|
|
33
33
|
body_str = ""
|
|
34
34
|
if in_function_body:
|
|
35
|
-
assert in_function_body[-1] == ";"
|
|
35
|
+
assert in_function_body[-1] == ";" # nosec B101
|
|
36
36
|
body_str = "\n" + in_function_body[:-1] + "\n"
|
|
37
37
|
return f"PROC {in_function_name} = VOID :({body_str});\n"
|
|
38
38
|
|
|
@@ -46,12 +46,12 @@ def _main_call_to_code(in_initial_call: core.InitialCall, **kwargs) -> str:
|
|
|
46
46
|
if in_initial_call is None:
|
|
47
47
|
return 'print("")'
|
|
48
48
|
res = _call_function_or_atom(in_initial_call, **kwargs)
|
|
49
|
-
assert res[-1] == ";"
|
|
49
|
+
assert res[-1] == ";" # nosec B101
|
|
50
50
|
return res[:-1]
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
def _join_to_final(main_call: str, function_definitions: list[str], **_kwargs) -> str:
|
|
54
|
-
assert main_call[-1] != "\n"
|
|
54
|
+
assert main_call[-1] != "\n" # nosec B101
|
|
55
55
|
return "\n\n".join(function_definitions + [main_call + "\n"])
|
|
56
56
|
|
|
57
57
|
|
string_to_code/to_haskell.py
CHANGED
|
@@ -59,9 +59,9 @@ def _join_to_final(main_call, function_definitions, **_kwargs):
|
|
|
59
59
|
|
|
60
60
|
import_list = ["IO", "putStr"]
|
|
61
61
|
if function_definitions:
|
|
62
|
-
assert "String" in res
|
|
62
|
+
assert "String" in res # nosec B101
|
|
63
63
|
import_list.append("String")
|
|
64
|
-
assert "++" in res
|
|
64
|
+
assert "++" in res # nosec B101
|
|
65
65
|
import_list.append("(++)")
|
|
66
66
|
res = f'import Prelude ({", ".join(import_list)})\n' + res
|
|
67
67
|
|
string_to_code/to_lua.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""
|
|
2
|
+
provides string_to_lua utilities
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from . import core
|
|
6
|
+
from . import utils
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _get_table_name(**kwargs) -> str:
|
|
10
|
+
return kwargs.get("table_name", "main")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _get_function_name(in_function_id: int, **kwargs) -> str:
|
|
14
|
+
prefix = _get_table_name(**kwargs) + "."
|
|
15
|
+
return prefix + kwargs.get("function_id_to_name", core.get_function_namer("fun_"))(
|
|
16
|
+
in_function_id
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def atom_to_code(in_atom: core.Atom) -> str:
|
|
21
|
+
"""
|
|
22
|
+
returns a string/piece of lua code resulting in printing the
|
|
23
|
+
in_atom.atom_char to the standard output
|
|
24
|
+
"""
|
|
25
|
+
if in_atom.atom_char == "\n":
|
|
26
|
+
return "print()"
|
|
27
|
+
if in_atom.atom_char == '"':
|
|
28
|
+
return "io.write('\"')"
|
|
29
|
+
special_chars = {"\\": "\\\\", "\t": "\\t"}
|
|
30
|
+
res_char = special_chars.get(in_atom.atom_char, in_atom.atom_char)
|
|
31
|
+
write_arg = f'"{res_char}"'
|
|
32
|
+
return f"io.write({write_arg})"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
_function_call_str = utils.get_function_call_str_fun(_get_function_name, "", "()")
|
|
36
|
+
|
|
37
|
+
_call_function_or_atom = utils.get_call_function_or_atom(
|
|
38
|
+
atom_to_code, _function_call_str
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
_body_to_str = utils.get_body_to_str("\n", "\t", _call_function_or_atom, "", "")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _merge_to_full_function(in_function_name, in_function_body):
|
|
46
|
+
function_body = " "
|
|
47
|
+
if in_function_body:
|
|
48
|
+
function_body = "\n" + in_function_body + "\n"
|
|
49
|
+
return f"function {in_function_name}()" + function_body + "end\n"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
_function_to_code = utils.get_function_to_code(
|
|
53
|
+
_get_function_name, _body_to_str, _merge_to_full_function
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _main_call_to_code(in_initial_call, **kwargs):
|
|
58
|
+
return (
|
|
59
|
+
_call_function_or_atom(in_initial_call, **kwargs) + "\n"
|
|
60
|
+
if in_initial_call is not None
|
|
61
|
+
else ""
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _join_to_final(main_call, function_definitions, **kwargs):
|
|
66
|
+
res = "\n".join(function_definitions + [main_call])
|
|
67
|
+
if function_definitions:
|
|
68
|
+
res = "local " + _get_table_name(**kwargs) + " = {}\n\n" + res
|
|
69
|
+
return res
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
proc_printer_program, proc = utils.get_all_proc_functions(
|
|
73
|
+
_main_call_to_code, _function_to_code, _join_to_final
|
|
74
|
+
)
|
string_to_code/to_pascal.py
CHANGED
|
@@ -37,7 +37,7 @@ _body_to_str = utils.get_body_to_str("\n", " ", _call_function_or_atom, "", "")
|
|
|
37
37
|
def _merge_to_full_function(in_function_name, in_function_body):
|
|
38
38
|
body_str = ""
|
|
39
39
|
if in_function_body:
|
|
40
|
-
assert in_function_body[-1] == ";"
|
|
40
|
+
assert in_function_body[-1] == ";" # nosec B101
|
|
41
41
|
body_str = in_function_body[:-1] + "\n"
|
|
42
42
|
return "".join(
|
|
43
43
|
[
|
string_to_code/utils.py
CHANGED
|
@@ -36,10 +36,10 @@ def get_call_function_or_atom(
|
|
|
36
36
|
"""
|
|
37
37
|
|
|
38
38
|
def _inner(in_data: core.CalledListEntry, **kwargs) -> str:
|
|
39
|
-
assert in_data is not None
|
|
39
|
+
assert in_data is not None # nosec B101
|
|
40
40
|
if isinstance(in_data, core.Atom):
|
|
41
41
|
return in_atom_to_code(in_data)
|
|
42
|
-
assert isinstance(in_data, int)
|
|
42
|
+
assert isinstance(in_data, int) # nosec B101
|
|
43
43
|
return in_function_call_str(in_data, **kwargs)
|
|
44
44
|
|
|
45
45
|
return _inner
|
|
@@ -88,10 +88,10 @@ def get_body_to_str(
|
|
|
88
88
|
) -> typing.Callable[[core.SimpleFunction], str]:
|
|
89
89
|
"""returns body_to_str-like function"""
|
|
90
90
|
|
|
91
|
-
def _body_to_str(in_function: core.SimpleFunction) -> str:
|
|
91
|
+
def _body_to_str(in_function: core.SimpleFunction, **kwargs) -> str:
|
|
92
92
|
if in_function.called_list:
|
|
93
93
|
return in_separator.join(
|
|
94
|
-
in_prefix + in_call_function_or_atom(_) + in_postfix
|
|
94
|
+
in_prefix + in_call_function_or_atom(_, **kwargs) + in_postfix
|
|
95
95
|
for _ in in_function.called_list
|
|
96
96
|
)
|
|
97
97
|
return in_empty_result
|
|
@@ -110,9 +110,9 @@ def get_function_to_code(
|
|
|
110
110
|
in_function_id: int, in_function: core.SimpleFunction, **kwargs
|
|
111
111
|
) -> str:
|
|
112
112
|
function_name = in_get_function_name(in_function_id, **kwargs)
|
|
113
|
-
function_body = in_body_to_str(in_function)
|
|
113
|
+
function_body = in_body_to_str(in_function, **kwargs)
|
|
114
114
|
res = in_merge_to_full_function(function_name, function_body)
|
|
115
|
-
assert res[-1] == "\n"
|
|
115
|
+
assert res[-1] == "\n" # nosec B101
|
|
116
116
|
return res
|
|
117
117
|
|
|
118
118
|
return _function_to_code
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
string_to_code/README.md,sha256=A8BkDQpr-Os630YfGnaU-i_kigyVB8bNLhvLfIyzQR8,1225
|
|
2
2
|
string_to_code/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
string_to_code/c_like_utils.py,sha256=C_mEQbq8fy-pbsPrnLOTGrWFG6UpA8G2yE2LytFTQR0,2378
|
|
4
|
-
string_to_code/core.py,sha256=
|
|
5
|
-
string_to_code/string_to_code.py,sha256=
|
|
6
|
-
string_to_code/to_ada.py,sha256=
|
|
7
|
-
string_to_code/to_algol68.py,sha256=
|
|
4
|
+
string_to_code/core.py,sha256=IlDiX7LzDe2Vbq_NvHTBc0M3-Jnu5st6gs3ptlF3pW0,4439
|
|
5
|
+
string_to_code/string_to_code.py,sha256=rwgMKr33ljgGXO4TCOFUeX_UuEyWM8wXTKz4RKGx8pE,1304
|
|
6
|
+
string_to_code/to_ada.py,sha256=BFyJzve3-jewks73WVuicuMWIbWJ7FbrMBugXZFnji0,2351
|
|
7
|
+
string_to_code/to_algol68.py,sha256=IfDTxAW52o3oBHJ25GTaDOLQU_ZQ9NvCd37tsHIGrwg,1749
|
|
8
8
|
string_to_code/to_ballerina.py,sha256=Z8F8r9hLZ5mvHzsjT5XDx_2cDlojBzva7UZcrMIQca0,1876
|
|
9
9
|
string_to_code/to_bash.py,sha256=FJI2WTYO0gDDFSyRwHwERuLFKqOBX79y4xsXa_K_5D4,1634
|
|
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_haskell.py,sha256=
|
|
13
|
+
string_to_code/to_haskell.py,sha256=WvNznkqmYXSsfrl5LkoDedB_uyJIgvqBz_YMM065PD0,1977
|
|
14
14
|
string_to_code/to_java.py,sha256=63LPDTrMqnukXMW0XHVX6aXHq-63NckQLiG3YmdaAYg,1865
|
|
15
15
|
string_to_code/to_lisp.py,sha256=BKkJorzyAbSmmOUt3otqHAapjOR6GblMM-ymekga1wY,1605
|
|
16
|
+
string_to_code/to_lua.py,sha256=DeRnBH3PFmyABqFVqmXNSN4c79awYkZJ9ZTmeabIAKI,2045
|
|
16
17
|
string_to_code/to_nim.py,sha256=W74i6MRjQ5eYeatGyMwE-wYNEzN06l5oOXBv3lfbXgM,1534
|
|
17
|
-
string_to_code/to_pascal.py,sha256=
|
|
18
|
+
string_to_code/to_pascal.py,sha256=OE2qefRgYhvx8AOn83m3q2gQh_Haoo3fqo12IfxKT28,1936
|
|
18
19
|
string_to_code/to_python3.py,sha256=BJwjyhRB2IBOE3-xwkkMV3vZU-e2xreppYBKQeA1whg,1589
|
|
19
20
|
string_to_code/to_rust.py,sha256=hTCjlortLhR7FwsBgbrFRcwXpKWA6ed2UYnz1OK8R7I,1926
|
|
20
|
-
string_to_code/utils.py,sha256
|
|
21
|
-
string_to_code-0.
|
|
22
|
-
string_to_code-0.
|
|
23
|
-
string_to_code-0.
|
|
24
|
-
string_to_code-0.
|
|
21
|
+
string_to_code/utils.py,sha256=0On1KjJ0dMHyS4xp1f8RIJcfcT5-CfocHTx3kDVRi5I,3847
|
|
22
|
+
string_to_code-0.3.0.dist-info/LICENSE,sha256=LQrcSkcUyN1FtFYDxWK05puxNN9o2q8PV-_2SwFDTWc,1068
|
|
23
|
+
string_to_code-0.3.0.dist-info/METADATA,sha256=A8FfETkjp6HVwT1ZtnzEJPbMqwwFLI3wKQIjXXY-AA8,1958
|
|
24
|
+
string_to_code-0.3.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
25
|
+
string_to_code-0.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|