#pragma once #include #include #include "ktype.h" #include "locator.h" #include "util.h" inline bool show_rewrite_rules = false; class Katom { public: static size_t index; Katom(const std::string& src, katom_t type, Locator loc); // Copy constructor Katom(const Katom& other) : m_index(other.m_index) , m_text(other.m_text) , m_src(other.m_src) , m_loc(other.m_loc) , m_type(other.m_type) , m_initial_type(other.m_initial_type) , m_display(other.m_display) {} // Copy assignment operator Katom& operator=(const Katom& other) { if (this != &other) { m_index = other.m_index; m_text = other.m_text; m_src = other.m_src; m_loc = other.m_loc; m_type = other.m_type; m_initial_type = other.m_initial_type; m_display = other.m_display; } return *this; } static inline bool show_index; static inline bool show_type; static inline bool show_id; static inline bool show_whitespace; static inline bool show_all; static inline bool show_replaced; static inline bool show_ignored; bool is_whitespace() const { return m_initial_type == katom_t::space || m_initial_type == katom_t::newline || m_type == katom_t::ws_added; } bool is_word() const { return m_initial_type == katom_t::word; } bool is_text() const { return m_initial_type == katom_t::text; } //bool is_text() { return m_initial_type == katom_t::text; } bool is_literal() const { return m_type == katom_t::literal; } bool is_active() const { return m_type != katom_t::ignored && m_type != katom_t::replaced; }; bool is_nonascii() const { return m_type == katom_t::nonascii; }; size_t m_index; std::string m_text{}; std::string m_src{}; Locator m_loc; katom_t m_type; katom_t m_initial_type; std::string m_display {}; }; bool active(const std::vector& katoms); int active_count(const std::vector& katoms); std::vector split_into_katoms(std::string s, const std::string& source, int source_line); void restore_initial_type(std::vector::iterator begin, std::vector::iterator end); void modify_type(katom_t new_type, std::vector::iterator begin, std::vector::iterator end); void modify_type(katom_t old_type, katom_t new_type, std::vector::iterator begin, std::vector::iterator end); void ignore_whitespace(std::vector::iterator& begin, std::vector& katoms); std::vector::iterator after_whitespace(std::vector::iterator begin); std::vector text_katoms( std::vector::iterator& begin, std::vector::iterator& end); std::string as_string(std::vector::const_iterator begin, std::vector::const_iterator end, bool strip_whitespace); std::string as_string(const std::vector& katoms, bool strip_whitespace); std::vector trim(std::vector& katoms, std::set trim_types = {katom_t::space, katom_t::newline}); std::vector trim(const std::vector& katoms, bool trim_inactive = false); std::vector> bar_split(std::vector::iterator kbegin, std::vector::iterator kend); std::vector line_split(std::string s); std::pair> line_split(fs::path pathname); std::vector katomize(const std::vector& lines, const std::string& source_desc); void process_whitespace_modifiers(std::vector& katoms); std::vector trim_whitespace(std::vector katoms); // escape_backslash() and unescape_backslash() (the ___BS___ hack) were // removed. Backslash is now handled by the general target escape mechanism // via the :escape parameter on @@@target. inline bool is_bar(const Katom& k) { return k.m_type == katom_t::bar; } inline bool is_nonascii(const Katom& k) { return k.m_type == katom_t::nonascii; } inline bool is_newline(const Katom& k) { return k.m_type == katom_t::newline; } inline bool is_ignore_rest(const Katom& k) { return k.m_type == katom_t::ignore_rest; } inline bool is_ignore_line(const Katom& k) { return k.m_type == katom_t::ignore_line; } inline void mark_as_replaced(Katom& k) { k.m_type = katom_t::replaced; } inline void mark_as_literal(Katom& k) { k.m_type = katom_t::literal; } inline void mark_as_ignored(Katom& k) { k.m_type = katom_t::ignored; } inline bool begin_read(Katom& k) { return k.m_type == katom_t::read_begin; } inline bool begin_ignore(const Katom& k) { return k.m_type == katom_t::ignore_begin; } inline bool end_ignore(const Katom& k) { return k.m_type == katom_t::ignore_end; } inline bool begin_literal(const Katom& k) { return k.m_type == katom_t::literal_begin; } inline bool end_literal(const Katom& k) { return k.m_type == katom_t::literal_end; } inline bool begin_eval(const Katom& k) { return k.m_type == katom_t::eval_begin; } inline bool begin_cond(const Katom& k) { return k.m_type == katom_t::cond_begin; } inline bool begin_klammer_def(const Katom& k) { return k.m_type == katom_t::define_begin; } inline bool end_klammer_def(const Katom& k) { return k.m_type == katom_t::define_end; } inline bool begin_klammer_apply(const Katom& k) { return k.m_type == katom_t::apply_begin; } inline bool end_klammer_apply(const Katom& k) { return k.m_type == katom_t::apply_end; } inline bool begin_machine_def(const Katom& k) { return k.m_type == katom_t::machine_begin; } inline bool end_machine_def(const Katom& k) { return k.m_type == katom_t::machine_end; } inline bool begin_apply(const Katom& k) { const std::set opens { katom_t::read_begin, katom_t::eval_begin, katom_t::cond_begin, katom_t::apply_begin}; return opens.contains(k.m_type); } inline bool end_apply(const Katom& k) { return k.m_type == katom_t::apply_end; }