|
|
@ -5,105 +5,108 @@ |
|
|
|
#include <charconv> |
|
|
|
#include <charconv> |
|
|
|
#include "dbc.hpp" |
|
|
|
#include "dbc.hpp" |
|
|
|
#include <SFML/Graphics.hpp> |
|
|
|
#include <SFML/Graphics.hpp> |
|
|
|
|
|
|
|
#include "ansi_parser.hpp" |
|
|
|
|
|
|
|
|
|
|
|
using namespace fmt; |
|
|
|
using namespace fmt; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#line 62 ".\\ansi_parser.rl" |
|
|
|
#line 59 ".\\ansi_parser.rl" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#line 12 ".\\ansi_parser.cpp" |
|
|
|
#line 13 ".\\ansi_parser.cpp" |
|
|
|
static const char _foo_actions[] = { |
|
|
|
static const char _foo_actions[] = { |
|
|
|
0, 1, 0, 1, 3, 1, 4, 1,
|
|
|
|
0, 1, 0, 1, 3, 1, 4, 1,
|
|
|
|
5, 1, 9, 1, 10, 2, 1, 6,
|
|
|
|
5, 1, 6, 1, 7, 1, 11, 1,
|
|
|
|
2, 1, 7, 2, 10, 5, 3, 1,
|
|
|
|
12, 2, 1, 8, 2, 1, 9, 2,
|
|
|
|
8, 2 |
|
|
|
12, 5, 3, 1, 10, 2 |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static const char _foo_key_offsets[] = { |
|
|
|
static const char _foo_key_offsets[] = { |
|
|
|
0, 0, 1, 2, 4, 6, 7, 8,
|
|
|
|
0, 0, 1, 2, 4, 6, 7, 8,
|
|
|
|
9, 11, 14, 16, 19, 21, 24, 25,
|
|
|
|
9, 11, 14, 16, 19, 21, 24, 25,
|
|
|
|
27, 28, 29, 30 |
|
|
|
27, 28, 29, 30, 31 |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static const char _foo_trans_keys[] = { |
|
|
|
static const char _foo_trans_keys[] = { |
|
|
|
27, 91, 51, 52, 56, 57, 59, 50,
|
|
|
|
27, 91, 51, 52, 56, 57, 59, 50,
|
|
|
|
59, 48, 57, 59, 48, 57, 48, 57,
|
|
|
|
59, 48, 57, 59, 48, 57, 48, 57,
|
|
|
|
59, 48, 57, 48, 57, 109, 48, 57,
|
|
|
|
59, 48, 57, 48, 57, 109, 48, 57,
|
|
|
|
109, 56, 57, 59, 50, 27, 27, 0 |
|
|
|
109, 56, 57, 59, 50, 109, 27, 27,
|
|
|
|
|
|
|
|
0 |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static const char _foo_single_lengths[] = { |
|
|
|
static const char _foo_single_lengths[] = { |
|
|
|
0, 1, 1, 2, 2, 1, 1, 1,
|
|
|
|
0, 1, 1, 2, 2, 1, 1, 1,
|
|
|
|
0, 1, 0, 1, 0, 1, 1, 2,
|
|
|
|
0, 1, 0, 1, 0, 1, 1, 2,
|
|
|
|
1, 1, 1, 1 |
|
|
|
1, 1, 1, 1, 1 |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static const char _foo_range_lengths[] = { |
|
|
|
static const char _foo_range_lengths[] = { |
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
1, 1, 1, 1, 1, 1, 0, 0,
|
|
|
|
1, 1, 1, 1, 1, 1, 0, 0,
|
|
|
|
0, 0, 0, 0 |
|
|
|
0, 0, 0, 0, 0 |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static const char _foo_index_offsets[] = { |
|
|
|
static const char _foo_index_offsets[] = { |
|
|
|
0, 0, 2, 4, 7, 10, 12, 14,
|
|
|
|
0, 0, 2, 4, 7, 10, 12, 14,
|
|
|
|
16, 18, 21, 23, 26, 28, 31, 33,
|
|
|
|
16, 18, 21, 23, 26, 28, 31, 33,
|
|
|
|
36, 38, 40, 42 |
|
|
|
36, 38, 40, 42, 44 |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static const char _foo_trans_targs[] = { |
|
|
|
static const char _foo_trans_targs[] = { |
|
|
|
2, 1, 3, 0, 4, 15, 0, 5,
|
|
|
|
2, 1, 3, 0, 4, 15, 0, 5,
|
|
|
|
14, 0, 6, 0, 7, 0, 8, 0,
|
|
|
|
14, 0, 6, 0, 7, 0, 8, 0,
|
|
|
|
9, 0, 10, 9, 0, 11, 0, 12,
|
|
|
|
9, 0, 10, 9, 0, 11, 0, 12,
|
|
|
|
11, 0, 13, 0, 19, 13, 0, 19,
|
|
|
|
11, 0, 13, 0, 20, 13, 0, 20,
|
|
|
|
0, 16, 14, 0, 17, 0, 7, 0,
|
|
|
|
0, 16, 18, 0, 17, 0, 7, 0,
|
|
|
|
2, 1, 2, 1, 0 |
|
|
|
20, 0, 2, 1, 2, 1, 0 |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static const char _foo_trans_actions[] = { |
|
|
|
static const char _foo_trans_actions[] = { |
|
|
|
0, 7, 0, 0, 9, 9, 0, 0,
|
|
|
|
0, 7, 0, 0, 13, 13, 0, 0,
|
|
|
|
0, 0, 0, 0, 3, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 3, 0, 0, 0,
|
|
|
|
1, 0, 13, 0, 0, 1, 0, 16,
|
|
|
|
1, 0, 17, 0, 0, 1, 0, 20,
|
|
|
|
0, 0, 1, 0, 22, 0, 0, 0,
|
|
|
|
0, 0, 1, 0, 26, 0, 0, 9,
|
|
|
|
0, 0, 0, 0, 0, 0, 5, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 5, 0,
|
|
|
|
0, 7, 11, 19, 0 |
|
|
|
11, 0, 0, 7, 15, 23, 0 |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static const char _foo_eof_actions[] = { |
|
|
|
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, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 11 |
|
|
|
0, 0, 0, 0, 15 |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static const int foo_start = 18; |
|
|
|
static const int foo_start = 19; |
|
|
|
static const int foo_first_final = 18; |
|
|
|
static const int foo_first_final = 19; |
|
|
|
static const int foo_error = 0; |
|
|
|
static const int foo_error = 0; |
|
|
|
|
|
|
|
|
|
|
|
static const int foo_en_main = 18; |
|
|
|
static const int foo_en_main = 19; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#line 65 ".\\ansi_parser.rl" |
|
|
|
#line 62 ".\\ansi_parser.rl" |
|
|
|
|
|
|
|
|
|
|
|
bool parse_ansi(std::string_view codes) { |
|
|
|
bool parse_ansi(std::string_view codes, sf::Color default_fg, sf::Color default_bg, WriteCB write) { |
|
|
|
const char *start = NULL; |
|
|
|
const char *start = NULL; |
|
|
|
int cs = 0; |
|
|
|
int cs = 0; |
|
|
|
unsigned int value = 0; |
|
|
|
unsigned int value = 0; |
|
|
|
const char *p = codes.data(); |
|
|
|
const char *p = codes.data(); |
|
|
|
const char *pe = p + codes.size(); |
|
|
|
const char *pe = p + codes.size(); |
|
|
|
const char *eof = pe; |
|
|
|
const char *eof = pe; |
|
|
|
bool is_fg = false; |
|
|
|
sf::Color bgcolor(default_bg); |
|
|
|
sf::Color color; |
|
|
|
sf::Color color(default_fg); |
|
|
|
|
|
|
|
sf::Color &target = bgcolor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#line 91 ".\\ansi_parser.cpp" |
|
|
|
#line 94 ".\\ansi_parser.cpp" |
|
|
|
{ |
|
|
|
{ |
|
|
|
cs = foo_start; |
|
|
|
cs = foo_start; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#line 77 ".\\ansi_parser.rl" |
|
|
|
#line 75 ".\\ansi_parser.rl" |
|
|
|
|
|
|
|
|
|
|
|
#line 94 ".\\ansi_parser.cpp" |
|
|
|
#line 97 ".\\ansi_parser.cpp" |
|
|
|
{ |
|
|
|
{ |
|
|
|
int _klen; |
|
|
|
int _klen; |
|
|
|
unsigned int _trans; |
|
|
|
unsigned int _trans; |
|
|
@ -177,62 +180,65 @@ _match: |
|
|
|
switch ( *_acts++ ) |
|
|
|
switch ( *_acts++ ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case 0: |
|
|
|
case 0: |
|
|
|
#line 12 ".\\ansi_parser.rl" |
|
|
|
#line 13 ".\\ansi_parser.rl" |
|
|
|
{ |
|
|
|
{ |
|
|
|
start = p; |
|
|
|
start = p; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
case 1: |
|
|
|
#line 16 ".\\ansi_parser.rl" |
|
|
|
#line 17 ".\\ansi_parser.rl" |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto [ptr, ec] = std::from_chars(start, p, value); |
|
|
|
auto [ptr, ec] = std::from_chars(start, p, value); |
|
|
|
dbc::check(ec == std::errc(), "error in number parsing"); |
|
|
|
dbc::check(ec == std::errc(), "error in number parsing"); |
|
|
|
println("NUM: {}", value); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
case 2: |
|
|
|
#line 22 ".\\ansi_parser.rl" |
|
|
|
#line 22 ".\\ansi_parser.rl" |
|
|
|
{ |
|
|
|
{ } |
|
|
|
println("color24b"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
case 3: |
|
|
|
#line 26 ".\\ansi_parser.rl" |
|
|
|
#line 23 ".\\ansi_parser.rl" |
|
|
|
{ is_fg = true; } |
|
|
|
{ target = color; } |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 4: |
|
|
|
case 4: |
|
|
|
#line 27 ".\\ansi_parser.rl" |
|
|
|
#line 24 ".\\ansi_parser.rl" |
|
|
|
{ is_fg = false; } |
|
|
|
{ target = bgcolor; } |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 5: |
|
|
|
case 5: |
|
|
|
#line 29 ".\\ansi_parser.rl" |
|
|
|
#line 26 ".\\ansi_parser.rl" |
|
|
|
{ |
|
|
|
{ |
|
|
|
println("ANY: {}:{}", int((*p)), (*p)); |
|
|
|
write(bgcolor, color, (*p)); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 6: |
|
|
|
case 6: |
|
|
|
#line 33 ".\\ansi_parser.rl" |
|
|
|
#line 30 ".\\ansi_parser.rl" |
|
|
|
{ color.r = value; } |
|
|
|
{ color = default_fg; } |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 7: |
|
|
|
case 7: |
|
|
|
#line 34 ".\\ansi_parser.rl" |
|
|
|
#line 31 ".\\ansi_parser.rl" |
|
|
|
{ color.g = value; } |
|
|
|
{ bgcolor = default_bg; } |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 8: |
|
|
|
case 8: |
|
|
|
#line 35 ".\\ansi_parser.rl" |
|
|
|
#line 33 ".\\ansi_parser.rl" |
|
|
|
{ color.b = value; } |
|
|
|
{ target.r = value; } |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 9: |
|
|
|
case 9: |
|
|
|
#line 37 ".\\ansi_parser.rl" |
|
|
|
#line 34 ".\\ansi_parser.rl" |
|
|
|
{ value = 0; } |
|
|
|
{ target.g = value; } |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 10: |
|
|
|
case 10: |
|
|
|
#line 39 ".\\ansi_parser.rl" |
|
|
|
#line 35 ".\\ansi_parser.rl" |
|
|
|
{ |
|
|
|
{ target.b = value; } |
|
|
|
println("fg? {}, sf:Color: {},{},{},{}", is_fg, color.r, color.g, color.b, color.a); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
#line 211 ".\\ansi_parser.cpp" |
|
|
|
case 11: |
|
|
|
|
|
|
|
#line 36 ".\\ansi_parser.rl" |
|
|
|
|
|
|
|
{ value = 0; } |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 12: |
|
|
|
|
|
|
|
#line 37 ".\\ansi_parser.rl" |
|
|
|
|
|
|
|
{ } |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
#line 215 ".\\ansi_parser.cpp" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -248,13 +254,11 @@ _again: |
|
|
|
unsigned int __nacts = (unsigned int) *__acts++; |
|
|
|
unsigned int __nacts = (unsigned int) *__acts++; |
|
|
|
while ( __nacts-- > 0 ) { |
|
|
|
while ( __nacts-- > 0 ) { |
|
|
|
switch ( *__acts++ ) { |
|
|
|
switch ( *__acts++ ) { |
|
|
|
case 10: |
|
|
|
case 12: |
|
|
|
#line 39 ".\\ansi_parser.rl" |
|
|
|
#line 37 ".\\ansi_parser.rl" |
|
|
|
{ |
|
|
|
{ } |
|
|
|
println("fg? {}, sf:Color: {},{},{},{}", is_fg, color.r, color.g, color.b, color.a); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
#line 231 ".\\ansi_parser.cpp" |
|
|
|
#line 233 ".\\ansi_parser.cpp" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -262,9 +266,7 @@ _again: |
|
|
|
_out: {} |
|
|
|
_out: {} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#line 78 ".\\ansi_parser.rl" |
|
|
|
#line 76 ".\\ansi_parser.rl" |
|
|
|
|
|
|
|
|
|
|
|
print("PROCESSED {} CHARS of {}: {}", p - codes.data(), codes.size(), p); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return p - pe == 0; |
|
|
|
} |
|
|
|
} |
|
|
|