polybar-dwm/include/components/parser.hpp

48 lines
1.1 KiB
C++
Raw Normal View History

2016-06-15 03:32:35 +00:00
#pragma once
#include "common.hpp"
2016-11-25 12:55:15 +00:00
#include "errors.hpp"
2016-06-15 03:32:35 +00:00
2016-11-19 05:22:44 +00:00
POLYBAR_NS
2016-06-15 03:32:35 +00:00
class signal_emitter;
2016-11-21 14:07:00 +00:00
enum class attribute : uint8_t;
enum class mousebtn : uint8_t;
struct bar_settings;
2016-11-21 14:07:00 +00:00
2016-11-25 03:10:26 +00:00
DEFINE_ERROR(parser_error);
DEFINE_CHILD_ERROR(unrecognized_token, parser_error);
DEFINE_CHILD_ERROR(unrecognized_attribute, parser_error);
DEFINE_CHILD_ERROR(unclosed_actionblocks, parser_error);
2016-06-15 03:32:35 +00:00
class parser {
public:
struct packet {
uint16_t data[128]{0U};
size_t length{0};
};
using make_type = unique_ptr<parser>;
static make_type make();
public:
explicit parser(signal_emitter& emitter);
void parse(const bar_settings& bar, string data);
2016-06-15 03:32:35 +00:00
protected:
void codeblock(string&& data, const bar_settings& bar);
2016-12-14 04:17:18 +00:00
size_t text(string&& data);
uint32_t parse_color(const string& s, uint32_t fallback = 0);
int8_t parse_fontindex(const string& s);
2016-11-25 12:55:15 +00:00
attribute parse_attr(const char attr);
2016-12-14 04:17:18 +00:00
mousebtn parse_action_btn(const string& data);
string parse_action_cmd(string&& data);
2016-06-15 03:32:35 +00:00
private:
signal_emitter& m_sig;
2016-06-15 03:32:35 +00:00
vector<int> m_actions;
unique_ptr<parser> m_parser;
2016-06-15 03:32:35 +00:00
};
2016-11-19 05:22:44 +00:00
POLYBAR_NS_END