|
|
|
|
|
|
|
#line 1 ".\\ansi_parser.rl"
|
|
|
|
#include <fmt/core.h>
|
|
|
|
#include <string_view>
|
|
|
|
#include <charconv>
|
|
|
|
#include "dbc.hpp"
|
|
|
|
|
|
|
|
using namespace fmt;
|
|
|
|
|
|
|
|
|
|
|
|
#line 74 ".\\ansi_parser.rl"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#line 11 ".\\ansi_parser.cpp"
|
|
|
|
static const char _foo_actions[] = {
|
|
|
|
0, 1, 0, 1, 1, 1, 2, 1,
|
|
|
|
3, 1, 4, 1, 5, 1, 6, 1,
|
|
|
|
7, 1, 8, 1, 9, 2, 1, 10,
|
|
|
|
2, 1, 11
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char _foo_key_offsets[] = {
|
|
|
|
0, 0, 1, 2, 3, 4, 6, 7,
|
|
|
|
9, 12, 14, 17, 19, 20, 22, 25,
|
|
|
|
27, 28, 29, 31, 31, 35, 37
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char _foo_trans_keys[] = {
|
|
|
|
27, 91, 56, 59, 50, 53, 59, 48,
|
|
|
|
57, 59, 48, 57, 48, 57, 59, 48,
|
|
|
|
57, 48, 57, 59, 48, 57, 59, 48,
|
|
|
|
57, 48, 57, 56, 59, 50, 53, 27,
|
|
|
|
51, 52, 109, 48, 57, 48, 57, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char _foo_single_lengths[] = {
|
|
|
|
0, 1, 1, 1, 1, 2, 1, 0,
|
|
|
|
1, 0, 1, 0, 1, 0, 1, 0,
|
|
|
|
1, 1, 2, 0, 4, 0, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char _foo_range_lengths[] = {
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 1,
|
|
|
|
1, 1, 1, 1, 0, 1, 1, 1,
|
|
|
|
0, 0, 0, 0, 0, 1, 1
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char _foo_index_offsets[] = {
|
|
|
|
0, 0, 2, 4, 6, 8, 11, 13,
|
|
|
|
15, 18, 20, 23, 25, 27, 29, 32,
|
|
|
|
34, 36, 38, 41, 42, 47, 49
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char _foo_trans_targs[] = {
|
|
|
|
19, 1, 20, 0, 4, 0, 5, 0,
|
|
|
|
6, 12, 0, 7, 0, 8, 0, 9,
|
|
|
|
8, 0, 10, 0, 11, 10, 0, 21,
|
|
|
|
0, 13, 0, 14, 0, 15, 14, 0,
|
|
|
|
22, 0, 17, 0, 18, 0, 6, 12,
|
|
|
|
0, 0, 2, 3, 16, 20, 0, 21,
|
|
|
|
20, 22, 20, 20, 20, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char _foo_trans_actions[] = {
|
|
|
|
11, 9, 17, 0, 0, 0, 0, 0,
|
|
|
|
7, 7, 0, 0, 0, 1, 0, 3,
|
|
|
|
0, 0, 1, 0, 3, 0, 0, 1,
|
|
|
|
0, 0, 0, 1, 0, 3, 0, 0,
|
|
|
|
1, 0, 0, 0, 0, 0, 5, 5,
|
|
|
|
0, 0, 0, 0, 0, 19, 0, 0,
|
|
|
|
24, 0, 21, 24, 21, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char _foo_to_state_actions[] = {
|
|
|
|
0, 13, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 13, 0, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char _foo_from_state_actions[] = {
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 15, 0, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char _foo_eof_trans[] = {
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 52, 53
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int foo_start = 1;
|
|
|
|
static const int foo_first_final = 19;
|
|
|
|
static const int foo_error = 0;
|
|
|
|
|
|
|
|
static const int foo_en_ansi = 20;
|
|
|
|
static const int foo_en_main = 1;
|
|
|
|
|
|
|
|
|
|
|
|
#line 77 ".\\ansi_parser.rl"
|
|
|
|
|
|
|
|
bool parse_ansi(std::string_view codes) {
|
|
|
|
const char *start = NULL;
|
|
|
|
int cs = 0;
|
|
|
|
size_t value = 0;
|
|
|
|
const char *p = codes.data();
|
|
|
|
const char *pe = p + codes.size();
|
|
|
|
const char *eof = pe;
|
|
|
|
const char *ts = p;
|
|
|
|
const char *te = p;
|
|
|
|
int act = 0;
|
|
|
|
|
|
|
|
|
|
|
|
#line 107 ".\\ansi_parser.cpp"
|
|
|
|
{
|
|
|
|
cs = foo_start;
|
|
|
|
ts = 0;
|
|
|
|
te = 0;
|
|
|
|
act = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#line 90 ".\\ansi_parser.rl"
|
|
|
|
|
|
|
|
#line 113 ".\\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:
|
|
|
|
_acts = _foo_actions + _foo_from_state_actions[cs];
|
|
|
|
_nacts = (unsigned int) *_acts++;
|
|
|
|
while ( _nacts-- > 0 ) {
|
|
|
|
switch ( *_acts++ ) {
|
|
|
|
case 7:
|
|
|
|
#line 1 "NONE"
|
|
|
|
{ts = p;}
|
|
|
|
break;
|
|
|
|
#line 132 ".\\ansi_parser.cpp"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_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:
|
|
|
|
_eof_trans:
|
|
|
|
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 11 ".\\ansi_parser.rl"
|
|
|
|
{
|
|
|
|
start = p;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
#line 15 ".\\ansi_parser.rl"
|
|
|
|
{
|
|
|
|
auto [ptr, ec] = std::from_chars(start, p, value);
|
|
|
|
dbc::check(ec == std::errc(), "error in number parsing");
|
|
|
|
println("NUM: {}", value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
#line 37 ".\\ansi_parser.rl"
|
|
|
|
{
|
|
|
|
println("BG");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
#line 41 ".\\ansi_parser.rl"
|
|
|
|
{
|
|
|
|
println("FG");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
#line 45 ".\\ansi_parser.rl"
|
|
|
|
{
|
|
|
|
println("ANY: {}:{}", int((*p)), (*p));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
#line 72 ".\\ansi_parser.rl"
|
|
|
|
{ p--; {cs = 20;goto _again;} }
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
#line 49 ".\\ansi_parser.rl"
|
|
|
|
{te = p+1;{
|
|
|
|
println("START");
|
|
|
|
}}
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
#line 69 ".\\ansi_parser.rl"
|
|
|
|
{te = p+1;{ {cs = 1;goto _again;} }}
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
#line 21 ".\\ansi_parser.rl"
|
|
|
|
{te = p;p--;{
|
|
|
|
println("COLOR256");
|
|
|
|
}}
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
#line 25 ".\\ansi_parser.rl"
|
|
|
|
{te = p;p--;{
|
|
|
|
println("COLOR24B");
|
|
|
|
}}
|
|
|
|
break;
|
|
|
|
#line 244 ".\\ansi_parser.cpp"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_again:
|
|
|
|
_acts = _foo_actions + _foo_to_state_actions[cs];
|
|
|
|
_nacts = (unsigned int) *_acts++;
|
|
|
|
while ( _nacts-- > 0 ) {
|
|
|
|
switch ( *_acts++ ) {
|
|
|
|
case 6:
|
|
|
|
#line 1 "NONE"
|
|
|
|
{ts = 0;}
|
|
|
|
break;
|
|
|
|
#line 255 ".\\ansi_parser.cpp"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( cs == 0 )
|
|
|
|
goto _out;
|
|
|
|
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 91 ".\\ansi_parser.rl"
|
|
|
|
|
|
|
|
print("PROCESSED {} CHARS of {}", p - codes.data(), codes.size());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|