turing-py 2.2.1__tar.gz → 2.2.2__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.
Files changed (25) hide show
  1. {turing_py-2.2.1 → turing_py-2.2.2}/PKG-INFO +1 -1
  2. {turing_py-2.2.1 → turing_py-2.2.2}/pyproject.toml +1 -1
  3. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/__init__.py +5 -27
  4. turing_py-2.2.2/src/tmpy/dsl/loader.py +63 -0
  5. turing_py-2.2.1/src/tmpy/dsl/loader.py +0 -56
  6. {turing_py-2.2.1 → turing_py-2.2.2}/LICENSE +0 -0
  7. {turing_py-2.2.1 → turing_py-2.2.2}/README.md +0 -0
  8. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/alphabet/__init__.py +0 -0
  9. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/alphabet/input_alphabet.py +0 -0
  10. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/alphabet/symbol.py +0 -0
  11. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/alphabet/tape_alphabet.py +0 -0
  12. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/dsl/__init__.py +0 -0
  13. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/dsl/ast.py +0 -0
  14. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/dsl/lexer.py +0 -0
  15. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/dsl/parser.py +0 -0
  16. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/dsl/token.py +0 -0
  17. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/exception.py +0 -0
  18. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/machine/__init__.py +0 -0
  19. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/machine/machine.py +0 -0
  20. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/machine/states.py +0 -0
  21. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/machine/tape.py +0 -0
  22. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/transition/__init__.py +0 -0
  23. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/transition/direction.py +0 -0
  24. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/transition/transition.py +0 -0
  25. {turing_py-2.2.1 → turing_py-2.2.2}/src/tmpy/transition/transition_function.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: turing-py
3
- Version: 2.2.1
3
+ Version: 2.2.2
4
4
  Summary: Education Turing Machine simulator in Python
5
5
  License-File: LICENSE
6
6
  Author: Eric Santos
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "turing-py"
3
- version = "2.2.1"
3
+ version = "2.2.2"
4
4
  description = "Education Turing Machine simulator in Python"
5
5
  authors = [
6
6
  {name = "Eric Santos",email = "ericshantos13@gmail.com"}
@@ -1,13 +1,4 @@
1
- from .alphabet import Alphabet, Symbol, TapeAlphabet
2
- from .dsl import (
3
- Lexer,
4
- MachineLoader,
5
- MachineNode,
6
- Parser,
7
- Token,
8
- TokenType,
9
- TransitionNode,
10
- )
1
+ from . import alphabet, dsl, machine, transition
11
2
  from .exception import (
12
3
  AlphabetError,
13
4
  BlankSymbolError,
@@ -24,25 +15,12 @@ from .exception import (
24
15
  TransitionNotDefinedError,
25
16
  TuringMachineError,
26
17
  )
27
- from .machine import States, Tape, TuringMachine
28
- from .transition import Direction, Transition, TransitionFunction
29
18
 
30
19
  __all__ = [
31
- "TransitionFunction",
32
- "Transition",
33
- "Alphabet",
34
- "TapeAlphabet",
35
- "Symbol",
36
- "TuringMachine",
37
- "States",
38
- "Tape",
39
- "Direction",
40
- "MachineNode",
41
- "TransitionNode",
42
- "Lexer",
43
- "MachineLoader",
44
- "Parser",
45
- "Token",
20
+ "alphabet",
21
+ "dsl",
22
+ "machine",
23
+ "transition",
46
24
  "TokenType",
47
25
  "BlankSymbolError",
48
26
  "TuringMachineError",
@@ -0,0 +1,63 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ @author: Eric Santos <ericshantos13@gmail.com>
4
+
5
+ Loader for the Turing machine DSL.
6
+ """
7
+
8
+ from pathlib import Path
9
+ from typing import Iterable
10
+
11
+ from ..alphabet import Symbol
12
+ from ..transition import Transition
13
+ from .ast import MachineNode
14
+ from .lexer import Lexer
15
+ from .parser import Parser
16
+ from .token import Token
17
+
18
+
19
+ class MachineLoader:
20
+
21
+ @classmethod
22
+ def load(cls, path: str | Path) -> Iterable[Transition]:
23
+
24
+ text = cls._read_file(path)
25
+
26
+ tokens = cls._lex(text)
27
+
28
+ ast = cls._parse(tokens)
29
+
30
+ transitions = cls._build_transitions(ast)
31
+
32
+ return transitions
33
+
34
+ @classmethod
35
+ def _read_file(cls, path: str | Path) -> str:
36
+
37
+ with open(path, "r") as f:
38
+ return f.read()
39
+
40
+ @classmethod
41
+ def _lex(cls, text: str) -> list[Token]:
42
+
43
+ lexer = Lexer(text)
44
+
45
+ return lexer.tokenize()
46
+
47
+ @classmethod
48
+ def _parse(cls, tokens: list[Token]) -> MachineNode:
49
+
50
+ parser = Parser(tokens)
51
+
52
+ return parser.parse()
53
+
54
+ @classmethod
55
+ def _build_transitions(cls, ast: MachineNode) -> list[Transition]:
56
+
57
+ transitions = []
58
+
59
+ for node in ast.transitions:
60
+
61
+ transitions.append(Transition(node.state, Symbol(node.read), node.next_state, Symbol(node.write), node.move))
62
+
63
+ return transitions
@@ -1,56 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- @author: Eric Santos <ericshantos13@gmail.com>
4
-
5
- Loader for the Turing machine DSL.
6
- """
7
-
8
- from ..alphabet import Symbol
9
- from ..transition import Transition
10
- from .lexer import Lexer
11
- from .parser import MachineNode, Parser
12
-
13
-
14
- class MachineLoader:
15
-
16
- def load(self, path: str):
17
- text = self._read_file(path)
18
-
19
- tokens = self._lex(text)
20
-
21
- ast = self._parse(tokens)
22
-
23
- transitions = self._build_transitions(ast)
24
-
25
- return transitions
26
-
27
- def _read_file(self, path: str) -> str:
28
-
29
- with open(path, "r") as f:
30
- return f.read()
31
-
32
- from tmpy.dsl.lexer import Lexer
33
-
34
- def _lex(self, text: str):
35
-
36
- lexer = Lexer(text)
37
-
38
- return lexer.tokenize()
39
-
40
- def _parse(self, tokens):
41
-
42
- parser = Parser(tokens)
43
-
44
- return parser.parse()
45
-
46
- def _build_transitions(self, machine_ast: MachineNode) -> list[Transition]:
47
-
48
- transitions = []
49
-
50
- for node in machine_ast.transitions:
51
-
52
- t = Transition(node.state, Symbol(node.read), node.next_state, Symbol(node.write), node.move)
53
-
54
- transitions.append(t)
55
-
56
- return transitions
File without changes
File without changes
File without changes