#ifndef __MACHINES_H_INCLUDED__ #define __MACHINES_H_INCLUDED__ #include "interpolate.h" #include "kblib/kblib.h" #include namespace fsm { class state { public: std::pair step(char32_t c) const; const std::string& suf() const {return end;} private: struct action_t { std::string format; const state* dest; }; vmap cmap; struct set_action_t { std::string matches; action_t action; }; std::vector set; struct map_action_t { small_vector in_set; small_vector out_set; const state* dest; }; std::vector map; struct match_action_t { small_vector matches; const state* dest; }; std::vector match; std::optional def; const state* ret; std::string end; friend std::optional toState(const YAML::Node&); friend bool set_dests(std::map& states, std::string name, const YAML::Node& data); }; class state_machine { public: enum dir_override : unsigned char { none = 0, r_in = 1, r_out = 2, r_both = 3, }; //be a valid string_transformer word_data_t operator()(Word, channelID) const; private: //using std::map for reference stability std::map states; dir_override dir; friend struct YAML::convert; }; } // namespace fsm namespace YAML { template<> struct convert { static bool decode(const Node& node, fsm::state_machine& sm); }; template<> struct convert { static bool decode(const Node& node, fsm::state& s); }; } #endif //__MACHINES_H_INCLUDED__