forked from Aunsiels/pyformlang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
33 lines (25 loc) · 783 Bytes
/
utils.py
File metadata and controls
33 lines (25 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
""" Utility for pda object creation """
from typing import Hashable
from .state import State
from .symbol import Symbol
from .stack_symbol import StackSymbol
from .epsilon import Epsilon
def to_state(given: Hashable) -> State:
""" Convert to a state """
if isinstance(given, State):
return given
return State(given)
def to_symbol(given: Hashable) -> Symbol:
""" Convert to a symbol """
if given == Epsilon():
return Epsilon()
if isinstance(given, Symbol):
return given
return Symbol(given)
def to_stack_symbol(given: Hashable) -> StackSymbol:
""" Convert to a stack symbol """
if given == Epsilon():
return Epsilon()
if isinstance(given, StackSymbol):
return given
return StackSymbol(given)