|
|
|
|
|
|
|
#line 1 ".\\scratchpad\\testragel.rl"
|
|
|
|
#include <fmt/core.h>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <string_view>
|
|
|
|
#include <charconv>
|
|
|
|
#include "dbc.hpp"
|
|
|
|
|
|
|
|
using namespace fmt;
|
|
|
|
|
|
|
|
|
|
|
|
#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, 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, 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, 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, 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, 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, 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 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[] = {
|
|
|
|
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[] = {
|
|
|
|
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, 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, 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 = 35;
|
|
|
|
static const int foo_first_final = 35;
|
|
|
|
static const int foo_error = 0;
|
|
|
|
|
|
|
|
static const int foo_en_main = 35;
|
|
|
|
|
|
|
|
|
|
|
|
#line 45 ".\\scratchpad\\testragel.rl"
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
#line 136 ".\\scratchpad\\testragel.cpp"
|
|
|
|
{
|
|
|
|
cs = foo_start;
|
|
|
|
ts = 0;
|
|
|
|
te = 0;
|
|
|
|
act = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#line 57 ".\\scratchpad\\testragel.rl"
|
|
|
|
|
|
|
|
#line 142 ".\\scratchpad\\testragel.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 3:
|
|
|
|
#line 1 "NONE"
|
|
|
|
{ts = p;}
|
|
|
|
break;
|
|
|
|
#line 161 ".\\scratchpad\\testragel.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:
|
|
|
|
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 ".\\scratchpad\\testragel.rl"
|
|
|
|
{
|
|
|
|
start = p;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
#line 17 ".\\scratchpad\\testragel.rl"
|
|
|
|
{
|
|
|
|
size_t value = 0;
|
|
|
|
auto [ptr, ec] = std::from_chars(start, p, value);
|
|
|
|
dbc::check(ec == std::errc(), "error in number parsing");
|
|
|
|
println("NUMBER {}", value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
#line 34 ".\\scratchpad\\testragel.rl"
|
|
|
|
{te = p+1;{ println("START"); }}
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
#line 35 ".\\scratchpad\\testragel.rl"
|
|
|
|
{te = p+1;{ println("fg 256 color"); }}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
#line 36 ".\\scratchpad\\testragel.rl"
|
|
|
|
{te = p+1;{ println("bg 256 color"); }}
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
#line 37 ".\\scratchpad\\testragel.rl"
|
|
|
|
{te = p+1;{ println("fg true color"); }}
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
#line 38 ".\\scratchpad\\testragel.rl"
|
|
|
|
{te = p+1;{ println("bg true color"); }}
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
#line 39 ".\\scratchpad\\testragel.rl"
|
|
|
|
{te = p+1;{ println("single"); }}
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
#line 40 ".\\scratchpad\\testragel.rl"
|
|
|
|
{te = p+1;{ println("basic"); }}
|
|
|
|
break;
|
|
|
|
#line 258 ".\\scratchpad\\testragel.cpp"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_again:
|
|
|
|
_acts = _foo_actions + _foo_to_state_actions[cs];
|
|
|
|
_nacts = (unsigned int) *_acts++;
|
|
|
|
while ( _nacts-- > 0 ) {
|
|
|
|
switch ( *_acts++ ) {
|
|
|
|
case 2:
|
|
|
|
#line 1 "NONE"
|
|
|
|
{ts = 0;}
|
|
|
|
break;
|
|
|
|
#line 269 ".\\scratchpad\\testragel.cpp"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( cs == 0 )
|
|
|
|
goto _out;
|
|
|
|
if ( ++p != pe )
|
|
|
|
goto _resume;
|
|
|
|
_test_eof: {}
|
|
|
|
_out: {}
|
|
|
|
}
|
|
|
|
|
|
|
|
#line 58 ".\\scratchpad\\testragel.rl"
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
// possibly put alphtype unsigned int?
|
|
|
|
std::vector<std::string_view> tests = {
|
|
|
|
"\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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|