#line 1 ".\\ansi_parser.rl" #include #include #include #include "dbc.hpp" #include #include "ansi_parser.hpp" using namespace fmt; #line 59 ".\\ansi_parser.rl" #line 13 ".\\ansi_parser.cpp" static const char _foo_actions[] = { 0, 1, 0, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 11, 1, 12, 2, 1, 8, 2, 1, 9, 2, 12, 5, 3, 1, 10, 2 }; static const char _foo_key_offsets[] = { 0, 0, 1, 2, 4, 6, 7, 8, 9, 11, 14, 16, 19, 21, 24, 25, 27, 28, 29, 30, 31 }; static const char _foo_trans_keys[] = { 27, 91, 51, 52, 56, 57, 59, 50, 59, 48, 57, 59, 48, 57, 48, 57, 59, 48, 57, 48, 57, 109, 48, 57, 109, 56, 57, 59, 50, 109, 27, 27, 0 }; static const char _foo_single_lengths[] = { 0, 1, 1, 2, 2, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 2, 1, 1, 1, 1, 1 }; static const char _foo_range_lengths[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; static const char _foo_index_offsets[] = { 0, 0, 2, 4, 7, 10, 12, 14, 16, 18, 21, 23, 26, 28, 31, 33, 36, 38, 40, 42, 44 }; static const char _foo_trans_targs[] = { 2, 1, 3, 0, 4, 15, 0, 5, 14, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 9, 0, 11, 0, 12, 11, 0, 13, 0, 20, 13, 0, 20, 0, 16, 18, 0, 17, 0, 7, 0, 20, 0, 2, 1, 2, 1, 0 }; static const char _foo_trans_actions[] = { 0, 7, 0, 0, 13, 13, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 17, 0, 0, 1, 0, 20, 0, 0, 1, 0, 26, 0, 0, 9, 0, 0, 0, 0, 0, 0, 5, 0, 11, 0, 0, 7, 15, 23, 0 }; static const char _foo_eof_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15 }; static const int foo_start = 19; static const int foo_first_final = 19; static const int foo_error = 0; static const int foo_en_main = 19; #line 62 ".\\ansi_parser.rl" bool parse_ansi(std::string_view codes, sf::Color default_fg, sf::Color default_bg, WriteCB write) { const char *start = NULL; int cs = 0; unsigned int value = 0; const char *p = codes.data(); const char *pe = p + codes.size(); const char *eof = pe; sf::Color bgcolor(default_bg); sf::Color color(default_fg); sf::Color &target = bgcolor; #line 94 ".\\ansi_parser.cpp" { cs = foo_start; } #line 75 ".\\ansi_parser.rl" #line 97 ".\\ansi_parser.cpp" { int _klen; unsigned int _trans; const char *_acts; unsigned int _nacts; const char *_keys; if ( p == pe ) goto _test_eof; if ( cs == 0 ) goto _out; _resume: _keys = _foo_trans_keys + _foo_key_offsets[cs]; _trans = _foo_index_offsets[cs]; _klen = _foo_single_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_mid; const char *_upper = _keys + _klen - 1; while (1) { if ( _upper < _lower ) break; _mid = _lower + ((_upper-_lower) >> 1); if ( (*p) < *_mid ) _upper = _mid - 1; else if ( (*p) > *_mid ) _lower = _mid + 1; else { _trans += (unsigned int)(_mid - _keys); goto _match; } } _keys += _klen; _trans += _klen; } _klen = _foo_range_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_mid; const char *_upper = _keys + (_klen<<1) - 2; while (1) { if ( _upper < _lower ) break; _mid = _lower + (((_upper-_lower) >> 1) & ~1); if ( (*p) < _mid[0] ) _upper = _mid - 2; else if ( (*p) > _mid[1] ) _lower = _mid + 2; else { _trans += (unsigned int)((_mid - _keys)>>1); goto _match; } } _trans += _klen; } _match: cs = _foo_trans_targs[_trans]; if ( _foo_trans_actions[_trans] == 0 ) goto _again; _acts = _foo_actions + _foo_trans_actions[_trans]; _nacts = (unsigned int) *_acts++; while ( _nacts-- > 0 ) { switch ( *_acts++ ) { case 0: #line 13 ".\\ansi_parser.rl" { start = p; } break; case 1: #line 17 ".\\ansi_parser.rl" { auto [ptr, ec] = std::from_chars(start, p, value); dbc::check(ec == std::errc(), "error in number parsing"); } break; case 2: #line 22 ".\\ansi_parser.rl" { } break; case 3: #line 23 ".\\ansi_parser.rl" { target = color; } break; case 4: #line 24 ".\\ansi_parser.rl" { target = bgcolor; } break; case 5: #line 26 ".\\ansi_parser.rl" { write(bgcolor, color, (*p)); } break; case 6: #line 30 ".\\ansi_parser.rl" { color = default_fg; } break; case 7: #line 31 ".\\ansi_parser.rl" { bgcolor = default_bg; } break; case 8: #line 33 ".\\ansi_parser.rl" { target.r = value; } break; case 9: #line 34 ".\\ansi_parser.rl" { target.g = value; } break; case 10: #line 35 ".\\ansi_parser.rl" { target.b = value; } break; case 11: #line 36 ".\\ansi_parser.rl" { value = 0; } break; case 12: #line 37 ".\\ansi_parser.rl" { } break; #line 215 ".\\ansi_parser.cpp" } } _again: if ( cs == 0 ) goto _out; if ( ++p != pe ) goto _resume; _test_eof: {} if ( p == eof ) { const char *__acts = _foo_actions + _foo_eof_actions[cs]; unsigned int __nacts = (unsigned int) *__acts++; while ( __nacts-- > 0 ) { switch ( *__acts++ ) { case 12: #line 37 ".\\ansi_parser.rl" { } break; #line 233 ".\\ansi_parser.cpp" } } } _out: {} } #line 76 ".\\ansi_parser.rl" return p - pe == 0; }