The next little game in the series where I make a fancy rogue game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
roguish/scratchpad/testragel.rl

77 lines
1.6 KiB

#include <fmt/core.h>
#include <string>
#include <vector>
#include <string_view>
#include <charconv>
#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<std::string_view> 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;
}