string-to-code 0.2.15__tar.gz → 0.3.0__tar.gz
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-0.2.15 → string_to_code-0.3.0}/PKG-INFO +1 -1
- {string_to_code-0.2.15 → string_to_code-0.3.0}/pyproject.toml +2 -2
- string_to_code-0.3.0/string_to_code/to_lua.py +74 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/utils.py +3 -3
- {string_to_code-0.2.15 → string_to_code-0.3.0}/LICENSE +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/README.md +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/__init__.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/c_like_utils.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/core.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/string_to_code.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/to_ada.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/to_algol68.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/to_ballerina.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/to_bash.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/to_c.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/to_cobol.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/to_cpp.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/to_haskell.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/to_java.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/to_lisp.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/to_nim.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/to_pascal.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/to_python3.py +0 -0
- {string_to_code-0.2.15 → string_to_code-0.3.0}/string_to_code/to_rust.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "string-to-code"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
4
4
|
description = "Generates a piece of messy code in a given language displaying a given string "
|
|
5
5
|
authors = ["piotr.idzik <vil02@o2.pl>"]
|
|
6
6
|
readme = "./string_to_code/README.md"
|
|
@@ -24,7 +24,7 @@ flake8-pytest-style = "2.0.0"
|
|
|
24
24
|
ruff = "0.8.4"
|
|
25
25
|
coverage = "7.6.10"
|
|
26
26
|
black = "24.10.0"
|
|
27
|
-
mypy = "1.14.
|
|
27
|
+
mypy = "1.14.1"
|
|
28
28
|
bandit = "1.8.0"
|
|
29
29
|
|
|
30
30
|
[build-system]
|
|
@@ -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
|
+
)
|
|
@@ -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,7 +110,7 @@ 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
115
|
assert res[-1] == "\n" # nosec B101
|
|
116
116
|
return res
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|