1 #ifndef NEWSBOAT_FILTER_PARSER_H_ 2 #define NEWSBOAT_FILTER_PARSER_H_ 3 4 #include <string> 5 #include <sys/types.h> 6 #include <regex.h> 7 8 9 enum { LOGOP_INVALID = 0, LOGOP_AND = 1, LOGOP_OR, MATCHOP_EQ, MATCHOP_NE, MATCHOP_RXEQ, MATCHOP_RXNE, MATCHOP_LT, MATCHOP_GT, MATCHOP_LE, MATCHOP_GE, MATCHOP_CONTAINS, MATCHOP_CONTAINSNOT, MATCHOP_BETWEEN }; 10 11 struct expression { 12 expression(const std::string& n, const std::string& lit, int o); 13 expression(int o = LOGOP_INVALID); 14 ~expression(); 15 16 std::string name; 17 std::string literal; 18 int op; 19 expression * l, * r; 20 expression * parent; 21 regex_t * regex; 22 }; 23 24 class FilterParser { 25 public: 26 FilterParser(); 27 FilterParser(const FilterParser& p); 28 ~FilterParser(); 29 void add_logop(int op); 30 void add_matchexpr(char * name, int op, char * lit); 31 void open_block(); 32 void close_block(); 33 34 bool parse_string(const std::string& str); 35 void cleanup(); 36 get_root()37 inline expression * get_root() { return root; } 38 FilterParser& operator=(FilterParser& p); 39 get_error()40 const std::wstring& get_error() { return errmsg; } 41 42 private: 43 void print_tree_r(expression * e, unsigned int depth); 44 void cleanup_r(expression * e); 45 46 expression * root; 47 expression * curpos; 48 bool next_must_descend_right; 49 std::string strexpr; 50 std::wstring errmsg; 51 }; 52 53 54 #endif /* NEWSBOAT_FILTER_PARSER_H_ */ 55