string-to-code 0.2.5__tar.gz → 0.2.6__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.5 → string_to_code-0.2.6}/PKG-INFO +1 -1
- {string_to_code-0.2.5 → string_to_code-0.2.6}/pyproject.toml +1 -1
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/core.py +24 -13
- {string_to_code-0.2.5 → string_to_code-0.2.6}/LICENSE +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/README.md +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/__init__.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/c_like_utils.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/string_to_code.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/to_ada.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/to_algol68.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/to_ballerina.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/to_bash.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/to_c.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/to_cobol.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/to_cpp.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/to_haskell.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/to_java.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/to_lisp.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/to_nim.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/to_pascal.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/to_python3.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/to_rust.py +0 -0
- {string_to_code-0.2.5 → string_to_code-0.2.6}/string_to_code/utils.py +0 -0
|
@@ -6,6 +6,8 @@ import collections.abc
|
|
|
6
6
|
import random
|
|
7
7
|
import functools
|
|
8
8
|
|
|
9
|
+
Strings: typing.TypeAlias = typing.List[str]
|
|
10
|
+
|
|
9
11
|
|
|
10
12
|
class Atom(typing.NamedTuple):
|
|
11
13
|
"""represents a single character to be printed"""
|
|
@@ -13,16 +15,23 @@ class Atom(typing.NamedTuple):
|
|
|
13
15
|
atom_char: str
|
|
14
16
|
|
|
15
17
|
|
|
18
|
+
CalledListEntry: typing.TypeAlias = int | Atom
|
|
19
|
+
InitialCall: typing.TypeAlias = CalledListEntry | None
|
|
20
|
+
|
|
21
|
+
|
|
16
22
|
class SimpleFunction(typing.NamedTuple):
|
|
17
23
|
"""
|
|
18
24
|
represents a function with no arguments and no return value calling
|
|
19
25
|
other functions of such type or displaying single characters
|
|
20
26
|
"""
|
|
21
27
|
|
|
22
|
-
called_list: typing.List[
|
|
28
|
+
called_list: typing.List[CalledListEntry]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
SimpleFunctions: typing.TypeAlias = typing.List[SimpleFunction]
|
|
23
32
|
|
|
24
33
|
|
|
25
|
-
def str_pieces(in_str: str, in_pieces_len: typing.List[int]) ->
|
|
34
|
+
def str_pieces(in_str: str, in_pieces_len: typing.List[int]) -> Strings:
|
|
26
35
|
"""returns in_str splited into pieces of lengths as in in_pieces_len"""
|
|
27
36
|
assert all(_ > 0 for _ in in_pieces_len)
|
|
28
37
|
assert sum(in_pieces_len) == len(in_str)
|
|
@@ -48,12 +57,12 @@ def random_pieces_len(in_total_len: int) -> typing.List[int]:
|
|
|
48
57
|
return res
|
|
49
58
|
|
|
50
59
|
|
|
51
|
-
def random_split(in_str: str) ->
|
|
60
|
+
def random_split(in_str: str) -> Strings:
|
|
52
61
|
"""randomply splits in_str"""
|
|
53
62
|
return str_pieces(in_str, random_pieces_len(len(in_str)))
|
|
54
63
|
|
|
55
64
|
|
|
56
|
-
def _interesting_random_split(in_str: str) ->
|
|
65
|
+
def _interesting_random_split(in_str: str) -> Strings:
|
|
57
66
|
assert len(in_str) > 1
|
|
58
67
|
res = random_split(in_str)
|
|
59
68
|
while len(res) == 1:
|
|
@@ -74,11 +83,11 @@ def get_function_namer(
|
|
|
74
83
|
|
|
75
84
|
def _prepare_printer_program(
|
|
76
85
|
in_str: str,
|
|
77
|
-
) -> typing.Tuple[
|
|
78
|
-
needed_functions:
|
|
86
|
+
) -> typing.Tuple[InitialCall, SimpleFunctions]:
|
|
87
|
+
needed_functions: SimpleFunctions = []
|
|
79
88
|
|
|
80
89
|
@functools.lru_cache(maxsize=None)
|
|
81
|
-
def _generate_code(in_str: str) ->
|
|
90
|
+
def _generate_code(in_str: str) -> CalledListEntry:
|
|
82
91
|
if len(in_str) == 1:
|
|
83
92
|
return Atom(in_str)
|
|
84
93
|
|
|
@@ -97,13 +106,13 @@ class PrinterProgram:
|
|
|
97
106
|
It consists only of SimpleFunctions and Atoms.
|
|
98
107
|
"""
|
|
99
108
|
|
|
100
|
-
def __init__(self, initial_call, needed_functions):
|
|
109
|
+
def __init__(self, initial_call: InitialCall, needed_functions: SimpleFunctions):
|
|
101
110
|
self._initial_call = initial_call
|
|
102
111
|
self._needed_functions = needed_functions
|
|
103
112
|
|
|
104
113
|
self._check_data()
|
|
105
114
|
|
|
106
|
-
def _check_data(self):
|
|
115
|
+
def _check_data(self) -> None:
|
|
107
116
|
if self.initial_call is not None and not isinstance(self.initial_call, Atom):
|
|
108
117
|
assert self.needed_functions
|
|
109
118
|
if self.needed_functions:
|
|
@@ -113,7 +122,9 @@ class PrinterProgram:
|
|
|
113
122
|
for fun_id, fun in enumerate(self.needed_functions):
|
|
114
123
|
assert all(_ < fun_id for _ in fun.called_list if not isinstance(_, Atom))
|
|
115
124
|
|
|
116
|
-
def needed_function_definitions_str_list(
|
|
125
|
+
def needed_function_definitions_str_list(
|
|
126
|
+
self, in_function_to_str, **kwargs
|
|
127
|
+
) -> Strings:
|
|
117
128
|
"""
|
|
118
129
|
returns a list of string representations of the definition of
|
|
119
130
|
the needed functions
|
|
@@ -124,16 +135,16 @@ class PrinterProgram:
|
|
|
124
135
|
]
|
|
125
136
|
|
|
126
137
|
@property
|
|
127
|
-
def initial_call(self):
|
|
138
|
+
def initial_call(self) -> InitialCall:
|
|
128
139
|
"""returns the 'entry point' of the program"""
|
|
129
140
|
return self._initial_call
|
|
130
141
|
|
|
131
142
|
@property
|
|
132
|
-
def needed_functions(self):
|
|
143
|
+
def needed_functions(self) -> SimpleFunctions:
|
|
133
144
|
"""returns the list of all needed functions"""
|
|
134
145
|
return self._needed_functions
|
|
135
146
|
|
|
136
147
|
|
|
137
|
-
def get_printer_program(in_str):
|
|
148
|
+
def get_printer_program(in_str: str) -> PrinterProgram:
|
|
138
149
|
"""returns a PrinterProgram object diplaying in_str"""
|
|
139
150
|
return PrinterProgram(*_prepare_printer_program(in_str))
|
|
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
|