#include #include #include #include #include #include "dbc.hpp" using namespace fmt; %%{ machine foo; action tstart { start = fpc; } action number { size_t value = 0; auto [ptr, ec] = std::from_chars(start, fpc, value); dbc::check(ec == std::errc(), "error in number parsing"); println("NUMBER {}", value); } start = 0x1B "["; fg = "38;"; bg = "48;"; num = digit+ >tstart %number; color256 = "5;" num ";" num; color24b = "2;" num ";" num ";" num; basic = num ";" num; single = num; main := |* start => { println("START"); }; fg color256 "m" => { println("fg 256 color"); }; bg color256 "m" => { println("bg 256 color"); }; fg color24b "m" => { println("fg true color"); }; bg color24b "m" => { println("bg true color"); }; single "m" => { println("single"); }; basic "m" => { println("basic"); }; *|; }%% %% write data; void parse_ansi(std::string_view &codes) { const char *start = NULL; int cs = 0; size_t act = 0; const char *p = codes.data(); const char *pe = p + codes.size(); const char *ts = p; const char *te = pe; const char *eof = pe; %% write init; %% write exec; } int main() { // possibly put alphtype unsigned int? std::vector tests = { "\x1B[38;5;78;98m", "\x1B[48;5;78;98m", "\x1B[38;2;36;46;23m", "\x1B[48;2;36;46;23m", "\x1B[36;46m", "\x1B[36m", }; for(auto test : tests) { println("--- PARSING"); parse_ansi(test); } return 0; }