Skip to content

Commit 138ae56

Browse files
committed
correct contains method of pda
1 parent da4eeb1 commit 138ae56

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

pyformlang/pda/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
"""
2222

2323
from .pda import PDA
24+
from .transition_function import TransitionFunction
2425
from ..objects.pda_objects import State, Symbol, StackSymbol, Epsilon
2526

2627

2728
__all__ = ["PDA",
29+
"TransitionFunction",
2830
"State",
2931
"Symbol",
3032
"StackSymbol",

pyformlang/pda/pda.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def __contains__(self, transition: InputTransition) -> bool:
270270
input_symbol = to_symbol(input_symbol)
271271
stack_from = to_stack_symbol(stack_from)
272272
s_to = to_state(s_to)
273-
stack_to = [to_stack_symbol(x) for x in stack_to]
273+
stack_to = tuple(to_stack_symbol(x) for x in stack_to)
274274
return (s_to, stack_to) in self(s_from, input_symbol, stack_from)
275275

276276
def __iter__(self) -> Iterator[Transition]:

pyformlang/regular_expression/regex.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,16 @@ def to_epsilon_nfa(self) -> EpsilonNFA:
157157
>>> regex.to_epsilon_nfa()
158158
159159
"""
160-
return self._to_epsilon_nfa_internal(True)
160+
return self._to_epsilon_nfa_internal().copy()
161161

162-
def _to_epsilon_nfa_internal(self, copy: bool) -> EpsilonNFA:
163-
"""
164-
Transforms the regular expression into an epsilon NFA.
165-
Copy enfa in case of external usage.
166-
"""
162+
def _to_epsilon_nfa_internal(self) -> EpsilonNFA:
163+
""" Transforms the regular expression into an epsilon NFA """
167164
if self._enfa is None:
168165
self._enfa = EpsilonNFA()
169166
s_initial = self._set_and_get_initial_state_in_enfa(self._enfa)
170167
s_final = self._set_and_get_final_state_in_enfa(self._enfa)
171168
self._process_to_enfa(self._enfa, s_initial, s_final)
172-
return self._enfa.copy() if copy else self._enfa
169+
return self._enfa
173170

174171
def _set_and_get_final_state_in_enfa(self, enfa: EpsilonNFA) -> State:
175172
s_final = self._get_next_state_enfa()
@@ -567,7 +564,7 @@ def accepts(self, word: Iterable[str]) -> bool:
567564
True
568565
569566
"""
570-
self._enfa = self._to_epsilon_nfa_internal(False)
567+
self._enfa = self._to_epsilon_nfa_internal()
571568
return self._enfa.accepts(word)
572569

573570
@classmethod

0 commit comments

Comments
 (0)