Better working but still picks up stray numbers I didn't specify.

This commit is contained in:
Zed A. Shaw 2024-10-31 10:08:46 -04:00
parent 74310304bd
commit 3394327981
2 changed files with 120 additions and 89 deletions

View file

@ -22,20 +22,22 @@ using namespace fmt;
}
start = 0x1B "[";
fg = "38;";
bg = "48;";
num = digit+ >tstart %number;
color256 = ";5;" (num ";"?)**;
color24b = ";2;" (num ";"?)**;
color256 = "5;" num ";" num;
color24b = "2;" num ";" num ";" 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"); };
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"); };
*|;
}%%
@ -58,13 +60,14 @@ void parse_ansi(std::string_view &codes) {
int main() {
// possibly put alphtype unsigned int?
std::vector<std::string_view> tests = {
"\x1B[;5;78;98m",
"\x1B[;2;36;46;23m",
"\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);