Skip to content

Commit

Permalink
Simplify definition and improve docstring of epsilon transition label…
Browse files Browse the repository at this point in the history
… constant.
  • Loading branch information
lapets committed Jul 10, 2022
1 parent 9ecffc4 commit be45cc3
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/nfa/nfa.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Pure-Python data structure derived from the built-in :class:`dict <dict>` type
Pure-Python data structure derived from the built-in :obj:`dict` type
that can represent nondeterministic finite automata (NFAs) as an ensemble
of dictionaries (where dictionary instances serve as nodes, dictionary keys
serve as edge labels, and dictionary values serve as edges).
Expand Down Expand Up @@ -915,7 +915,7 @@ def copy(self: nfa, _memo=None) -> nfa:
class epsilon:
"""
Singleton class for the epsilon transition label. Only a sole instance
of this class is ever be created. Therefore, the symbol :obj:`epsilon`
of this class is ever be created. Therefore, the symbol ``epsilon``
exported by this library is assigned the sole *instance* of this class.
Thus, the exported object :obj:`epsilon` can be used in any context that
expects a transition label.
Expand Down Expand Up @@ -959,11 +959,8 @@ def __repr__(self: epsilon) -> str:
"""
return 'epsilon'

# Retain an alias for the class in scope so that doctests are executed.
_epsilon: type = epsilon

# The exported symbol refers to the sole instance of the
# epsilon transition label class.
# The exported symbol defined below refers to the sole object of the epsilon
# transition label class that is defined above.
epsilon = epsilon()
"""
Constant representing an *epsilon* transition when used as an edge label
Expand All @@ -972,6 +969,19 @@ def __repr__(self: epsilon) -> str:
>>> a = nfa({'a': nfa({epsilon: nfa({'b': nfa()})})})
>>> a('ab')
2
This object is
`hashable <https://docs.python.org/3/glossary.html#term-hashable>`__,
is equivalent to itself, and can be converted into a string.
>>> {epsilon, epsilon}
{epsilon}
>>> epsilon == epsilon
True
>>> str(epsilon)
'epsilon'
>>> epsilon is not None
True
"""

if __name__ == '__main__':
Expand Down

0 comments on commit be45cc3

Please sign in to comment.