State superclass specialized for whitespace (blank lines & indents).
Use this class with StateMachineWS. The transitions 'blank' (for blank lines) and 'indent' (for indented text blocks) are added automatically, before any other transitions. The transition method blank() handles blank lines and indent() handles nested indented blocks. Indented blocks trigger a new state machine to be created by indent() and run. The class of the state machine to be created is in indent_sm, and the constructor keyword arguments are in the dictionary indent_sm_kwargs.
The methods known_indent() and firstknown_indent() are provided for indented blocks where the indent (all lines' and first line's only, respectively) is known to the transition method, along with the attributes known_indent_sm and known_indent_sm_kwargs. Neither transition method is triggered automatically.
There are no implemented interfaces.
indent_sm
(type: NoneType
)
None
indent_sm_kwargs
(type: NoneType
)
None
initial_transitions
(type: NoneType
)
None
known_indent_sm
(type: NoneType
)
None
known_indent_sm_kwargs
(type: NoneType
)
None
nested_sm
(type: NoneType
)
None
nested_sm_kwargs
(type: NoneType
)
None
patterns
(type: NoneType
)
None
ws_initial_transitions
(type:
tuple
)
('blank', 'indent')
ws_patterns
(type:
dict
)
{'indent': ' +', 'blank': ' *$'}
add_initial_transitions()
Add whitespace-specific transitions before those defined in subclass.
Extends State.add_initial_transitions().
add_transition(name, transition)
Add a transition to the start of the transition list.
Parameter transition: a ready-made transition 3-tuple.
Exception: DuplicateTransitionError.
add_transitions(names, transitions)
Add a list of transitions to the start of the transition list.
Parameters:
Exceptions: DuplicateTransitionError, UnknownTransitionError.
blank(match, context, next_state)
Handle blank lines. Does nothing. Override in subclasses.
bof(context)
Handle beginning-of-file. Return unchanged context, empty result.
Override in subclasses.
Parameter context: application-defined storage.
eof(context)
Handle end-of-file. Return empty result.
Override in subclasses.
Parameter context: application-defined storage.
first_known_indent(match, context, next_state)
Handle an indented text block (first line's indent known).
Extend or override in subclasses.
Recursively run the registered state machine for known-indent indented blocks (self.known_indent_sm). The indent is the length of the match, match.end().
indent(match, context, next_state)
Handle an indented text block. Extend or override in subclasses.
Recursively run the registered state machine for indented blocks (self.indent_sm).
known_indent(match, context, next_state)
Handle a known-indent text block. Extend or override in subclasses.
Recursively run the registered state machine for known-indent indented blocks (self.known_indent_sm). The indent is the length of the match, match.end().
make_transition(name, next_state=None)
Make & return a transition tuple based on name.
This is a convenience function to simplify transition creation.
Parameters:
Exceptions: TransitionPatternNotFound, TransitionMethodNotFound.
make_transitions(name_list)
Return a list of transition names and a transition mapping.
Parameter name_list: a list, where each entry is either a transition name string, or a 1- or 2-tuple (transition name, optional next state name).
no_match(context, transitions)
Called when there is no match from StateMachine.check_line().
Return the same values returned by transition methods:
Override in subclasses to catch this event.
nop(match, context, next_state)
A "do nothing" transition method.
Return unchanged context & next_state, empty result. Useful for simple state changes (actionless transitions).
remove_transition(name)
Remove a transition by name.
Exception: UnknownTransitionError.
runtime_init()
Initialize this State before running the state machine; called from self.state_machine.run().
unlink()
Remove circular references to objects no longer required.