turing-py 2.1.0__tar.gz → 2.2.1__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.
- {turing_py-2.1.0 → turing_py-2.2.1}/PKG-INFO +1 -1
- {turing_py-2.1.0 → turing_py-2.2.1}/pyproject.toml +1 -1
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/dsl/loader.py +2 -1
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/machine/machine.py +1 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/transition/transition_function.py +10 -12
- {turing_py-2.1.0 → turing_py-2.2.1}/LICENSE +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/README.md +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/__init__.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/alphabet/__init__.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/alphabet/input_alphabet.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/alphabet/symbol.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/alphabet/tape_alphabet.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/dsl/__init__.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/dsl/ast.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/dsl/lexer.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/dsl/parser.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/dsl/token.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/exception.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/machine/__init__.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/machine/states.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/machine/tape.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/transition/__init__.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/transition/direction.py +0 -0
- {turing_py-2.1.0 → turing_py-2.2.1}/src/tmpy/transition/transition.py +0 -0
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
Loader for the Turing machine DSL.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
+
from ..alphabet import Symbol
|
|
8
9
|
from ..transition import Transition
|
|
9
10
|
from .lexer import Lexer
|
|
10
11
|
from .parser import MachineNode, Parser
|
|
@@ -48,7 +49,7 @@ class MachineLoader:
|
|
|
48
49
|
|
|
49
50
|
for node in machine_ast.transitions:
|
|
50
51
|
|
|
51
|
-
t = Transition(node.state, node.read, node.next_state, node.write, node.move)
|
|
52
|
+
t = Transition(node.state, Symbol(node.read), node.next_state, Symbol(node.write), node.move)
|
|
52
53
|
|
|
53
54
|
transitions.append(t)
|
|
54
55
|
|
|
@@ -13,25 +13,23 @@ from .transition import Transition
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
class TransitionFunction:
|
|
16
|
-
def __init__(self) -> None:
|
|
17
|
-
self._transitions: dict[tuple[str, Symbol], Transition] = {}
|
|
16
|
+
def __init__(self, *args: Transition) -> None:
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
self._tr: dict[tuple[str, Symbol], Transition] = {}
|
|
20
19
|
|
|
21
|
-
for t in
|
|
20
|
+
for t in args:
|
|
22
21
|
|
|
23
22
|
if isinstance(t, Iterable) and not isinstance(t, Transition):
|
|
24
23
|
for tr in t:
|
|
25
|
-
self.
|
|
24
|
+
self._tr[(tr.state, tr.symbol)] = tr
|
|
26
25
|
else:
|
|
27
|
-
self.
|
|
26
|
+
self._tr[(t.state, t.symbol)] = t
|
|
28
27
|
|
|
29
28
|
def __call__(self, state: str, symbol: Symbol) -> Transition | None:
|
|
30
|
-
return self.
|
|
29
|
+
return self._tr.get((state, symbol))
|
|
31
30
|
|
|
32
|
-
def
|
|
33
|
-
return
|
|
31
|
+
def __contains__(self, item) -> bool:
|
|
32
|
+
return item in self._tr
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return self._transitions
|
|
34
|
+
def __str__(self) -> str:
|
|
35
|
+
return "\n".join(str(t) for t in self._tr.values())
|
|
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
|