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

75 lines
1.4 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 "[";
num = digit+ >tstart %number;
color256 = ";5;" (num ";"?)**;
color24b = ";2;" (num ";"?)**;
basic = num ";" num;
single = num;
main := |*
start => { println("START"); };
single => { println("single"); };
basic => { println("basic"); };
color256 => { println("256 color"); };
color24b => { println("true color"); };
"m" => { println("END"); };
*|;
}%%
%% 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[;5;78;98m",
"\x1B[;2;36;46;23m",
"\x1B[36;46m",
"\x1B[36m",
};
for(auto test : tests) {
println("--- PARSING");
parse_ansi(test);
}
return 0;
}