string-to-code 0.2.10__tar.gz → 0.2.12__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.10 → string_to_code-0.2.12}/PKG-INFO +2 -2
- {string_to_code-0.2.10 → string_to_code-0.2.12}/pyproject.toml +4 -2
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/c_like_utils.py +15 -6
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/core.py +2 -3
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/to_ada.py +4 -4
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/to_algol68.py +3 -3
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/utils.py +10 -4
- {string_to_code-0.2.10 → string_to_code-0.2.12}/LICENSE +0 -0
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/README.md +0 -0
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/__init__.py +0 -0
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/string_to_code.py +0 -0
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/to_ballerina.py +0 -0
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/to_bash.py +0 -0
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/to_c.py +0 -0
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/to_cobol.py +0 -0
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/to_cpp.py +0 -0
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/to_haskell.py +0 -0
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/to_java.py +0 -0
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/to_lisp.py +0 -0
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/to_nim.py +0 -0
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/to_pascal.py +0 -0
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/to_python3.py +0 -0
- {string_to_code-0.2.10 → string_to_code-0.2.12}/string_to_code/to_rust.py +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: string-to-code
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.12
|
|
4
4
|
Summary: Generates a piece of messy code in a given language displaying a given string
|
|
5
5
|
Home-page: https://github.com/vil02/string_to_code_proj
|
|
6
6
|
License: MIT
|
|
7
7
|
Keywords: code-generation
|
|
8
8
|
Author: piotr.idzik
|
|
9
9
|
Author-email: vil02@o2.pl
|
|
10
|
-
Requires-Python: >=3.10
|
|
10
|
+
Requires-Python: >=3.10,<4.0.0
|
|
11
11
|
Classifier: License :: OSI Approved :: MIT License
|
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.10
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "string-to-code"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.12"
|
|
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"
|
|
@@ -10,7 +10,7 @@ repository = "https://github.com/vil02/string_to_code_proj"
|
|
|
10
10
|
keywords = ["code-generation"]
|
|
11
11
|
|
|
12
12
|
[tool.poetry.dependencies]
|
|
13
|
-
python = ">=3.10"
|
|
13
|
+
python = ">=3.10,<4.0.0"
|
|
14
14
|
|
|
15
15
|
[tool.poetry.group.dev]
|
|
16
16
|
optional = true
|
|
@@ -20,6 +20,8 @@ pytest = ">=7.0"
|
|
|
20
20
|
pytest-mock = ">3.0"
|
|
21
21
|
pylint = ">=2.0"
|
|
22
22
|
flake8 = ">=5.0"
|
|
23
|
+
flake8-pytest-style = "2.0.0"
|
|
24
|
+
ruff = "0.5.2"
|
|
23
25
|
coverage = ">=6.0"
|
|
24
26
|
black = ">=24.1"
|
|
25
27
|
mypy = ">=1.7"
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"""
|
|
2
|
-
utilities
|
|
2
|
+
utilities for C-like languages
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
+
import typing
|
|
6
|
+
|
|
5
7
|
from . import core
|
|
6
8
|
from . import utils
|
|
7
9
|
|
|
@@ -21,7 +23,10 @@ def escape_special_char(in_atom: core.Atom) -> str:
|
|
|
21
23
|
return special_chars.get(in_atom.atom_char, in_atom.atom_char)
|
|
22
24
|
|
|
23
25
|
|
|
24
|
-
def get_atom_to_code(
|
|
26
|
+
def get_atom_to_code(
|
|
27
|
+
in_printer_function_name: str,
|
|
28
|
+
in_escape_special_char_fun: typing.Callable[[core.Atom], str],
|
|
29
|
+
) -> typing.Callable[[core.Atom], str]:
|
|
25
30
|
"""returns the atom_to_code type function"""
|
|
26
31
|
|
|
27
32
|
def _inner(in_atom: core.Atom) -> str:
|
|
@@ -36,15 +41,19 @@ def get_function_call_str_fun(get_function_name):
|
|
|
36
41
|
return utils.get_function_call_str_fun(get_function_name, "", "();")
|
|
37
42
|
|
|
38
43
|
|
|
39
|
-
def get_body_to_str(
|
|
44
|
+
def get_body_to_str(
|
|
45
|
+
in_call_function_or_atom: typing.Callable[[core.CalledListEntry], str],
|
|
46
|
+
) -> typing.Callable[[core.SimpleFunction], str]:
|
|
40
47
|
"""returns body_to_str-like function for c-like languages"""
|
|
41
48
|
return utils.get_body_to_str("\n", " ", in_call_function_or_atom, "", "")
|
|
42
49
|
|
|
43
50
|
|
|
44
|
-
def get_merge_to_full_function(
|
|
51
|
+
def get_merge_to_full_function(
|
|
52
|
+
in_function_prefix: str,
|
|
53
|
+
) -> typing.Callable[[str, str], str]:
|
|
45
54
|
"""returns merge_to_full_function-like function for c-like languages"""
|
|
46
55
|
|
|
47
|
-
def _merge_to_full_function(in_function_name, in_function_body):
|
|
56
|
+
def _merge_to_full_function(in_function_name: str, in_function_body: str) -> str:
|
|
48
57
|
body_str = "\n" + in_function_body + "\n" if in_function_body else ""
|
|
49
58
|
return "\n".join(
|
|
50
59
|
[
|
|
@@ -59,7 +68,7 @@ def get_merge_to_full_function(in_function_prefix):
|
|
|
59
68
|
def get_main_call_fun(in_call_function_or_atom):
|
|
60
69
|
"""returns function returning code of main C or C++ function"""
|
|
61
70
|
|
|
62
|
-
def _main_call(in_initial_call, **kwargs):
|
|
71
|
+
def _main_call(in_initial_call: str | None, **kwargs) -> str:
|
|
63
72
|
initial_call_str = (
|
|
64
73
|
" " + in_call_function_or_atom(in_initial_call, **kwargs) + "\n "
|
|
65
74
|
if in_initial_call is not None
|
|
@@ -117,9 +117,8 @@ class PrinterProgram:
|
|
|
117
117
|
if self.initial_call is not None and not isinstance(self.initial_call, Atom):
|
|
118
118
|
assert self.needed_functions
|
|
119
119
|
if self.needed_functions:
|
|
120
|
-
assert isinstance(self.initial_call, int)
|
|
121
|
-
|
|
122
|
-
)
|
|
120
|
+
assert isinstance(self.initial_call, int)
|
|
121
|
+
assert self.initial_call + 1 == len(self.needed_functions)
|
|
123
122
|
for fun_id, fun in enumerate(self.needed_functions):
|
|
124
123
|
assert all(_ < fun_id for _ in fun.called_list if not isinstance(_, Atom))
|
|
125
124
|
|
|
@@ -34,7 +34,7 @@ _body_to_str = utils.get_body_to_str(
|
|
|
34
34
|
)
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
def _merge_to_full_function(in_function_name, in_function_body):
|
|
37
|
+
def _merge_to_full_function(in_function_name: str, in_function_body: str) -> str:
|
|
38
38
|
return "\n".join(
|
|
39
39
|
[
|
|
40
40
|
f" procedure {in_function_name} is",
|
|
@@ -50,7 +50,7 @@ _function_to_code = utils.get_function_to_code(
|
|
|
50
50
|
)
|
|
51
51
|
|
|
52
52
|
|
|
53
|
-
def default_program_name():
|
|
53
|
+
def default_program_name() -> str:
|
|
54
54
|
"""returns the default program name used by the proc function"""
|
|
55
55
|
return "Main"
|
|
56
56
|
|
|
@@ -58,13 +58,13 @@ def default_program_name():
|
|
|
58
58
|
_MAIN_NULL_CALL = " " + _NULL_CALL + "\n"
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
def _main_call_to_code(in_initial_call, **kwargs):
|
|
61
|
+
def _main_call_to_code(in_initial_call: core.InitialCall, **kwargs) -> str:
|
|
62
62
|
if in_initial_call:
|
|
63
63
|
return " " + _call_function_or_atom(in_initial_call, **kwargs) + "\n"
|
|
64
64
|
return _MAIN_NULL_CALL
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
def _join_to_final(main_call, function_definitions, **kwargs):
|
|
67
|
+
def _join_to_final(main_call: str, function_definitions: list[str], **kwargs) -> str:
|
|
68
68
|
function_definitions_str = "\n".join(function_definitions)
|
|
69
69
|
if function_definitions_str:
|
|
70
70
|
function_definitions_str += "\n"
|
|
@@ -29,7 +29,7 @@ _call_function_or_atom = utils.get_call_function_or_atom(
|
|
|
29
29
|
_body_to_str = utils.get_body_to_str("\n", " ", _call_function_or_atom, "", "")
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
def _merge_to_full_function(in_function_name, in_function_body):
|
|
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
35
|
assert in_function_body[-1] == ";"
|
|
@@ -42,7 +42,7 @@ _function_to_code = utils.get_function_to_code(
|
|
|
42
42
|
)
|
|
43
43
|
|
|
44
44
|
|
|
45
|
-
def _main_call_to_code(in_initial_call, **kwargs):
|
|
45
|
+
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)
|
|
@@ -50,7 +50,7 @@ def _main_call_to_code(in_initial_call, **kwargs):
|
|
|
50
50
|
return res[:-1]
|
|
51
51
|
|
|
52
52
|
|
|
53
|
-
def _join_to_final(main_call, function_definitions, **_kwargs):
|
|
53
|
+
def _join_to_final(main_call: str, function_definitions: list[str], **_kwargs) -> str:
|
|
54
54
|
assert main_call[-1] != "\n"
|
|
55
55
|
return "\n\n".join(function_definitions + [main_call + "\n"])
|
|
56
56
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
utilities for to_some_language modules
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
+
import typing
|
|
5
6
|
from . import core
|
|
6
7
|
|
|
7
8
|
|
|
@@ -26,13 +27,16 @@ def get_function_call_str_fun(in_get_function_name, in_prefix: str, in_postfix:
|
|
|
26
27
|
return _function_call_str
|
|
27
28
|
|
|
28
29
|
|
|
29
|
-
def get_call_function_or_atom(
|
|
30
|
+
def get_call_function_or_atom(
|
|
31
|
+
in_atom_to_code: typing.Callable[[core.Atom], str], in_function_call_str
|
|
32
|
+
):
|
|
30
33
|
"""
|
|
31
34
|
returns the function call_function_or_atom returning a string
|
|
32
35
|
representing a function call or displayng given atom
|
|
33
36
|
"""
|
|
34
37
|
|
|
35
38
|
def _inner(in_data: core.CalledListEntry, **kwargs) -> str:
|
|
39
|
+
assert in_data is not None
|
|
36
40
|
if isinstance(in_data, core.Atom):
|
|
37
41
|
return in_atom_to_code(in_data)
|
|
38
42
|
assert isinstance(in_data, int)
|
|
@@ -78,10 +82,10 @@ def get_all_proc_functions(main_call_to_code, function_to_code, join_to_final):
|
|
|
78
82
|
def get_body_to_str(
|
|
79
83
|
in_separator: str,
|
|
80
84
|
in_prefix: str,
|
|
81
|
-
in_call_function_or_atom,
|
|
85
|
+
in_call_function_or_atom: typing.Callable[[core.CalledListEntry], str],
|
|
82
86
|
in_postfix: str,
|
|
83
87
|
in_empty_result: str,
|
|
84
|
-
):
|
|
88
|
+
) -> typing.Callable[[core.SimpleFunction], str]:
|
|
85
89
|
"""returns body_to_str-like function"""
|
|
86
90
|
|
|
87
91
|
def _body_to_str(in_function: core.SimpleFunction) -> str:
|
|
@@ -96,7 +100,9 @@ def get_body_to_str(
|
|
|
96
100
|
|
|
97
101
|
|
|
98
102
|
def get_function_to_code(
|
|
99
|
-
in_get_function_name,
|
|
103
|
+
in_get_function_name,
|
|
104
|
+
in_body_to_str: typing.Callable[[core.SimpleFunction], str],
|
|
105
|
+
in_merge_to_full_function: typing.Callable[[str, str], str],
|
|
100
106
|
):
|
|
101
107
|
"""return function_to_code-like function"""
|
|
102
108
|
|
|
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
|