From 3394327981adb271e3bccc94eb3cf49de5d29fff Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Thu, 31 Oct 2024 10:08:46 -0400 Subject: [PATCH] Better working but still picks up stray numbers I didn't specify. --- scratchpad/testragel.cpp | 182 ++++++++++++++++++++++----------------- scratchpad/testragel.rl | 25 +++--- 2 files changed, 119 insertions(+), 88 deletions(-) diff --git a/scratchpad/testragel.cpp b/scratchpad/testragel.cpp index 7369e77..f53c942 100644 --- a/scratchpad/testragel.cpp +++ b/scratchpad/testragel.cpp @@ -10,85 +10,125 @@ using namespace fmt; -#line 40 ".\\scratchpad\\testragel.rl" +#line 42 ".\\scratchpad\\testragel.rl" #line 13 ".\\scratchpad\\testragel.cpp" static const char _foo_actions[] = { 0, 1, 0, 1, 1, 1, 2, 1, - 3, 1, 4, 1, 5, 1, 6, 1, - 9, 1, 10, 1, 11, 2, 1, 7, - 2, 1, 8, 2, 1, 9, 2, 1, - 10, 2, 4, 0 + 3, 1, 4, 2, 1, 5, 2, 1, + 6, 2, 1, 7, 2, 1, 8, 2, + 1, 9, 2, 1, 10 }; static const char _foo_key_offsets[] = { - 0, 0, 1, 3, 5, 6, 7, 12, - 15, 17, 19, 22, 24 + 0, 0, 1, 5, 7, 10, 15, 19, + 23, 27, 29, 32, 34, 37, 39, 42, + 46, 48, 51, 53, 56, 61, 65, 69, + 73, 75, 78, 80, 83, 85, 88, 92, + 94, 97, 99, 102 }; static const char _foo_trans_keys[] = { - 91, 48, 57, 50, 53, 59, 59, 27, - 59, 109, 48, 57, 59, 48, 57, 48, + 91, 59, 109, 48, 57, 48, 57, 109, + 48, 57, 56, 59, 109, 48, 57, 59, + 109, 48, 57, 50, 53, 48, 57, 59, + 109, 48, 57, 48, 57, 59, 48, 57, + 48, 57, 59, 48, 57, 48, 57, 109, + 48, 57, 59, 109, 48, 57, 48, 57, + 59, 48, 57, 48, 57, 109, 48, 57, + 56, 59, 109, 48, 57, 59, 109, 48, + 57, 50, 53, 48, 57, 59, 109, 48, 57, 48, 57, 59, 48, 57, 48, 57, - 59, 48, 57, 0 + 59, 48, 57, 48, 57, 109, 48, 57, + 59, 109, 48, 57, 48, 57, 59, 48, + 57, 48, 57, 109, 48, 57, 27, 51, + 52, 48, 57, 0 }; static const char _foo_single_lengths[] = { - 0, 1, 0, 2, 1, 1, 3, 1, - 0, 0, 1, 0, 1 + 0, 1, 2, 0, 1, 3, 2, 2, + 2, 0, 1, 0, 1, 0, 1, 2, + 0, 1, 0, 1, 3, 2, 2, 2, + 0, 1, 0, 1, 0, 1, 2, 0, + 1, 0, 1, 3 }; static const char _foo_range_lengths[] = { - 0, 0, 1, 0, 0, 0, 1, 1, - 1, 1, 1, 1, 1 + 0, 0, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1 }; -static const char _foo_index_offsets[] = { - 0, 0, 2, 4, 7, 9, 11, 16, - 19, 21, 23, 26, 28 +static const unsigned char _foo_index_offsets[] = { + 0, 0, 2, 6, 8, 11, 16, 20, + 24, 28, 30, 33, 35, 38, 40, 43, + 47, 49, 52, 54, 57, 62, 66, 70, + 74, 76, 79, 81, 84, 86, 89, 93, + 95, 98, 100, 103 }; static const char _foo_trans_targs[] = { - 6, 0, 8, 6, 4, 5, 0, 9, - 0, 11, 0, 1, 3, 6, 7, 0, - 2, 7, 6, 8, 6, 10, 6, 9, - 10, 6, 12, 6, 11, 12, 6, 6, - 6, 6, 6, 6, 6, 6, 0 + 35, 0, 3, 35, 2, 0, 4, 0, + 35, 4, 0, 6, 3, 35, 2, 0, + 7, 35, 2, 0, 8, 15, 4, 0, + 9, 35, 4, 0, 10, 0, 11, 10, + 0, 12, 0, 13, 12, 0, 14, 0, + 35, 14, 0, 16, 35, 4, 0, 17, + 0, 18, 17, 0, 19, 0, 35, 19, + 0, 21, 3, 35, 2, 0, 22, 35, + 2, 0, 23, 30, 4, 0, 24, 35, + 4, 0, 25, 0, 26, 25, 0, 27, + 0, 28, 27, 0, 29, 0, 35, 29, + 0, 31, 35, 4, 0, 32, 0, 33, + 32, 0, 34, 0, 35, 34, 0, 1, + 5, 20, 2, 0, 0 }; static const char _foo_trans_actions[] = { - 11, 0, 1, 19, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 13, 33, 0, - 3, 9, 21, 0, 24, 1, 17, 3, - 0, 30, 1, 15, 3, 0, 27, 19, - 21, 24, 17, 30, 15, 27, 0 + 9, 0, 3, 23, 0, 0, 1, 0, + 26, 0, 0, 0, 3, 23, 0, 0, + 3, 23, 0, 0, 1, 1, 1, 0, + 0, 26, 0, 0, 1, 0, 3, 0, + 0, 1, 0, 3, 0, 0, 1, 0, + 17, 0, 0, 0, 26, 0, 0, 1, + 0, 3, 0, 0, 1, 0, 11, 0, + 0, 0, 3, 23, 0, 0, 3, 23, + 0, 0, 1, 1, 1, 0, 0, 26, + 0, 0, 1, 0, 3, 0, 0, 1, + 0, 3, 0, 0, 1, 0, 20, 0, + 0, 0, 26, 0, 0, 1, 0, 3, + 0, 0, 1, 0, 14, 0, 0, 0, + 1, 1, 1, 0, 0 }; static const char _foo_to_state_actions[] = { - 0, 0, 0, 0, 0, 0, 5, 0, - 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 5 }; static const char _foo_from_state_actions[] = { - 0, 0, 0, 0, 0, 0, 7, 0, - 0, 0, 0, 0, 0 -}; - -static const char _foo_eof_trans[] = { - 0, 0, 32, 0, 0, 0, 0, 33, - 34, 35, 36, 37, 38 + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 7 }; -static const int foo_start = 6; -static const int foo_first_final = 6; +static const int foo_start = 35; +static const int foo_first_final = 35; static const int foo_error = 0; -static const int foo_en_main = 6; +static const int foo_en_main = 35; -#line 43 ".\\scratchpad\\testragel.rl" +#line 45 ".\\scratchpad\\testragel.rl" void parse_ansi(std::string_view &codes) { const char *start = NULL; @@ -101,7 +141,7 @@ void parse_ansi(std::string_view &codes) { const char *eof = pe; -#line 96 ".\\scratchpad\\testragel.cpp" +#line 136 ".\\scratchpad\\testragel.cpp" { cs = foo_start; ts = 0; @@ -109,9 +149,9 @@ void parse_ansi(std::string_view &codes) { act = 0; } -#line 55 ".\\scratchpad\\testragel.rl" +#line 57 ".\\scratchpad\\testragel.rl" -#line 102 ".\\scratchpad\\testragel.cpp" +#line 142 ".\\scratchpad\\testragel.cpp" { int _klen; unsigned int _trans; @@ -132,7 +172,7 @@ _resume: #line 1 "NONE" {ts = p;} break; -#line 121 ".\\scratchpad\\testragel.cpp" +#line 161 ".\\scratchpad\\testragel.cpp" } } @@ -185,7 +225,6 @@ _resume: } _match: -_eof_trans: cs = _foo_trans_targs[_trans]; if ( _foo_trans_actions[_trans] == 0 ) @@ -213,38 +252,34 @@ _eof_trans: } break; case 4: -#line 1 "NONE" - {te = p+1;} +#line 34 ".\\scratchpad\\testragel.rl" + {te = p+1;{ println("START"); }} break; case 5: -#line 33 ".\\scratchpad\\testragel.rl" - {te = p+1;{ println("START"); }} +#line 35 ".\\scratchpad\\testragel.rl" + {te = p+1;{ println("fg 256 color"); }} break; case 6: -#line 38 ".\\scratchpad\\testragel.rl" - {te = p+1;{ println("END"); }} +#line 36 ".\\scratchpad\\testragel.rl" + {te = p+1;{ println("bg 256 color"); }} break; case 7: -#line 34 ".\\scratchpad\\testragel.rl" - {te = p;p--;{ println("single"); }} +#line 37 ".\\scratchpad\\testragel.rl" + {te = p+1;{ println("fg true color"); }} break; case 8: -#line 35 ".\\scratchpad\\testragel.rl" - {te = p;p--;{ println("basic"); }} +#line 38 ".\\scratchpad\\testragel.rl" + {te = p+1;{ println("bg true color"); }} break; case 9: -#line 36 ".\\scratchpad\\testragel.rl" - {te = p;p--;{ println("256 color"); }} +#line 39 ".\\scratchpad\\testragel.rl" + {te = p+1;{ println("single"); }} break; case 10: -#line 37 ".\\scratchpad\\testragel.rl" - {te = p;p--;{ println("true color"); }} - break; - case 11: -#line 34 ".\\scratchpad\\testragel.rl" - {{p = ((te))-1;}{ println("single"); }} +#line 40 ".\\scratchpad\\testragel.rl" + {te = p+1;{ println("basic"); }} break; -#line 222 ".\\scratchpad\\testragel.cpp" +#line 258 ".\\scratchpad\\testragel.cpp" } } @@ -257,7 +292,7 @@ _again: #line 1 "NONE" {ts = 0;} break; -#line 233 ".\\scratchpad\\testragel.cpp" +#line 269 ".\\scratchpad\\testragel.cpp" } } @@ -266,30 +301,23 @@ _again: if ( ++p != pe ) goto _resume; _test_eof: {} - if ( p == eof ) - { - if ( _foo_eof_trans[cs] > 0 ) { - _trans = _foo_eof_trans[cs] - 1; - goto _eof_trans; - } - } - _out: {} } -#line 56 ".\\scratchpad\\testragel.rl" +#line 58 ".\\scratchpad\\testragel.rl" } int main() { // possibly put alphtype unsigned int? std::vector 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); diff --git a/scratchpad/testragel.rl b/scratchpad/testragel.rl index 09570bf..31ef376 100644 --- a/scratchpad/testragel.rl +++ b/scratchpad/testragel.rl @@ -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 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);