#ifndef GENTOOBROWSE_SERVICE_UTILS_LEXER_H #define GENTOOBROWSE_SERVICE_UTILS_LEXER_H #include #include #include #include #include #include #include namespace Gentoo { namespace Utils { class Lexer { public: class Pattern { public: virtual ~Pattern() = default; virtual bool matches(const gchar *, size_t, size_t) const = 0; virtual size_t matchedLength() const = 0; virtual boost::optional match(int) const = 0; }; typedef boost::shared_ptr PatternPtr; typedef std::string State; typedef std::set States; class ExecuteState { public: ExecuteState(); void pushState(const State &); void popState(); void setState(const State &); const State & getState() const; size_t position; PatternPtr pattern; private: std::vector stateStack; }; typedef boost::function Handler; typedef boost::tuple Rule; typedef std::vector Rules; static const State InitialState; Rules rules; static PatternPtr regex(const Glib::ustring &, GRegexCompileFlags compile = (GRegexCompileFlags)0, GRegexMatchFlags match = (GRegexMatchFlags)0); public: void extract(const gchar * string, size_t length) const; }; } } #endif