def _extract_states(self, states, accepted): """ Extracts and packages States from specified lines. :param str states: All States :param str accepted: All accepted states :return: """ accepted_states = api.NEW_SPLIT_COMMA(accepted, remove_empty=True) for state in api.NEW_SPLIT_COMMA(states, remove_empty=True): state_name = helper.de_escape_string(state)[0] # epsilon is format-specific so it should be bound to a specific Generator implementation. state_obj = self.state_imp(state_name, 1 if state in accepted_states else 0) self.states[state_name] = state_obj
def _extract_functions(self, functions): for line in functions: if line == '': continue start_value, ends = api.split_factory2('->')(line) start, value = helper.de_escape_string( *api.NEW_SPLIT_COMMA(start_value)) end, symbol, movement = helper.de_escape_string( *api.NEW_SPLIT_COMMA(ends)) end = self.states[end] movement = pk.TuringOutputPack.LEFT if movement == 'L' else pk.TuringOutputPack.RIGHT self.states[start].add_function( pk.TuringOutputPack(end, symbol, movement), value)
def _extract_functions(self, functions): for line in functions: if line == '': continue start_value, ends = api.split_factory2('->')(line) start, value = helper.de_escape_string( *api.NEW_SPLIT_COMMA(start_value)) for end in api.NEW_SPLIT_COMMA(ends): end = helper.de_escape_string(end)[0] if end != '#': try: self.states[start].add_function( self.states[end], value) except Exception as err: print(self.states, start, end, value) raise err
def _extract_inputs(self, text): for inp in api.NEW_SPLIT_COMMA(text, remove_empty=True): self.inputs.add(*helper.de_escape_string(inp))