If Amazon used this Besos wouldn't have banned PowerPoint.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
besos-loves-slides/md_parser.cpp

421 lines
9.9 KiB

#line 1 "md_parser.rl"
#include <fmt/core.h>
#include <iostream>
enum {
PLAIN=0,
TITLE=1,
ENUM=2
};
#line 72 "md_parser.rl"
#line 13 "md_parser.cpp"
static const char _Parser_actions[] = {
0, 1, 0, 1, 1, 1, 2, 1,
3, 1, 4, 1, 5, 1, 6, 1,
7, 1, 8, 2, 0, 5, 2, 1,
3, 2, 2, 3, 2, 3, 0, 2,
3, 2, 2, 5, 0, 2, 7, 0,
3, 5, 7, 0
};
static const short _Parser_key_offsets[] = {
0, 0, 1, 1, 2, 3, 4, 5,
6, 7, 12, 14, 19, 22, 24, 27,
33, 37, 40, 43, 48, 53, 58, 66,
69, 71, 74, 79, 84, 89, 97, 102,
104, 106, 111, 113, 114, 117, 119, 122,
128, 132, 135, 138, 139, 145, 151, 154,
157, 160, 169, 173, 176, 179, 182, 188,
194, 200, 209, 215, 221, 227, 230, 232,
236, 239, 245, 251, 254, 259, 264, 267,
273, 279, 288, 292, 295, 301, 307, 313,
322, 328, 332, 335, 341, 347, 350, 356,
359, 364
};
static const char _Parser_trans_keys[] = {
123, 125, 10, 61, 61, 61, 10, 10,
33, 35, 42, 45, 10, 45, 10, 33,
35, 42, 45, 10, 40, 45, 10, 45,
10, 41, 45, 10, 33, 35, 41, 42,
45, 10, 40, 41, 45, 10, 41, 45,
10, 41, 45, 10, 33, 35, 42, 45,
10, 32, 45, 9, 13, 10, 32, 45,
9, 13, 10, 32, 33, 35, 42, 45,
9, 13, 10, 40, 45, 10, 45, 10,
41, 45, 10, 33, 35, 42, 45, 10,
32, 45, 9, 13, 10, 32, 45, 9,
13, 10, 32, 33, 35, 42, 45, 9,
13, 10, 32, 45, 9, 13, 10, 45,
10, 45, 10, 32, 45, 9, 13, 10,
45, 10, 10, 40, 45, 10, 45, 10,
41, 45, 10, 33, 35, 41, 42, 45,
10, 40, 41, 45, 10, 41, 45, 10,
41, 45, 41, 10, 32, 41, 45, 9,
13, 10, 32, 41, 45, 9, 13, 10,
41, 45, 10, 41, 45, 10, 41, 45,
10, 32, 33, 35, 41, 42, 45, 9,
13, 10, 40, 41, 45, 10, 41, 45,
10, 41, 45, 10, 41, 45, 10, 32,
41, 45, 9, 13, 10, 32, 41, 45,
9, 13, 10, 32, 41, 45, 9, 13,
10, 32, 33, 35, 41, 42, 45, 9,
13, 10, 32, 41, 45, 9, 13, 10,
32, 41, 45, 9, 13, 10, 32, 41,
45, 9, 13, 10, 41, 45, 10, 41,
10, 40, 41, 45, 10, 41, 45, 10,
32, 41, 45, 9, 13, 10, 32, 41,
45, 9, 13, 10, 41, 45, 10, 32,
45, 9, 13, 10, 32, 45, 9, 13,
10, 41, 45, 10, 32, 41, 45, 9,
13, 10, 32, 41, 45, 9, 13, 10,
32, 33, 35, 41, 42, 45, 9, 13,
10, 40, 41, 45, 10, 41, 45, 10,
32, 41, 45, 9, 13, 10, 32, 41,
45, 9, 13, 10, 32, 41, 45, 9,
13, 10, 32, 33, 35, 41, 42, 45,
9, 13, 10, 32, 41, 45, 9, 13,
10, 40, 41, 45, 10, 41, 45, 10,
32, 41, 45, 9, 13, 10, 32, 41,
45, 9, 13, 10, 41, 45, 10, 32,
41, 45, 9, 13, 10, 41, 45, 10,
33, 35, 42, 45, 10, 33, 35, 41,
42, 45, 0
};
static const char _Parser_single_lengths[] = {
0, 1, 0, 1, 1, 1, 1, 1,
1, 5, 2, 5, 3, 2, 3, 6,
4, 3, 3, 5, 3, 3, 6, 3,
2, 3, 5, 3, 3, 6, 3, 2,
2, 3, 2, 1, 3, 2, 3, 6,
4, 3, 3, 1, 4, 4, 3, 3,
3, 7, 4, 3, 3, 3, 4, 4,
4, 7, 4, 4, 4, 3, 2, 4,
3, 4, 4, 3, 3, 3, 3, 4,
4, 7, 4, 3, 4, 4, 4, 7,
4, 4, 3, 4, 4, 3, 4, 3,
5, 6
};
static const char _Parser_range_lengths[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 1, 1, 0,
0, 0, 0, 1, 1, 1, 1, 0,
0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 1, 0, 0,
0, 1, 0, 0, 0, 0, 1, 1,
1, 1, 1, 1, 1, 0, 0, 0,
0, 1, 1, 0, 1, 1, 0, 1,
1, 1, 0, 0, 1, 1, 1, 1,
1, 0, 0, 1, 1, 0, 1, 0,
0, 0
};
static const short _Parser_index_offsets[] = {
0, 0, 2, 3, 5, 7, 9, 11,
13, 15, 21, 24, 30, 34, 37, 41,
48, 53, 57, 61, 67, 72, 77, 85,
89, 92, 96, 102, 107, 112, 120, 125,
128, 131, 136, 139, 141, 145, 148, 152,
159, 164, 168, 172, 174, 180, 186, 190,
194, 198, 207, 212, 216, 220, 224, 230,
236, 242, 251, 257, 263, 269, 273, 276,
281, 285, 291, 297, 301, 306, 311, 315,
321, 327, 336, 341, 345, 351, 357, 363,
372, 378, 383, 387, 393, 399, 403, 409,
413, 419
};
static const unsigned char _Parser_indicies[] = {
0, 1, 2, 3, 2, 4, 1, 5,
1, 6, 1, 7, 1, 8, 1, 10,
11, 12, 13, 14, 9, 16, 17, 15,
19, 20, 21, 22, 23, 18, 16, 24,
17, 15, 26, 27, 25, 29, 30, 31,
28, 32, 33, 34, 35, 36, 37, 25,
29, 38, 30, 31, 28, 26, 39, 27,
25, 29, 30, 40, 28, 16, 20, 21,
22, 23, 18, 42, 41, 17, 41, 15,
44, 43, 45, 43, 18, 46, 43, 47,
21, 48, 49, 43, 18, 16, 50, 17,
15, 26, 52, 51, 29, 54, 55, 53,
16, 47, 21, 48, 49, 18, 57, 56,
17, 56, 15, 59, 58, 45, 58, 18,
60, 58, 20, 21, 22, 23, 58, 18,
61, 56, 17, 56, 15, 16, 62, 15,
16, 1, 15, 61, 56, 63, 56, 15,
16, 64, 15, 65, 1, 16, 66, 17,
15, 68, 69, 67, 71, 30, 72, 70,
73, 74, 75, 35, 76, 77, 67, 71,
38, 30, 72, 70, 71, 30, 78, 70,
71, 30, 79, 70, 39, 79, 81, 80,
30, 72, 80, 70, 84, 83, 85, 86,
83, 82, 71, 54, 88, 87, 71, 54,
89, 87, 71, 54, 79, 87, 90, 83,
91, 92, 85, 93, 94, 83, 82, 71,
95, 54, 88, 87, 26, 39, 52, 51,
29, 54, 96, 53, 29, 54, 79, 53,
81, 80, 54, 88, 80, 87, 98, 97,
54, 88, 97, 87, 100, 99, 85, 86,
99, 82, 102, 101, 74, 75, 103, 76,
77, 101, 67, 100, 101, 103, 69, 101,
67, 105, 104, 30, 72, 104, 70, 105,
104, 30, 106, 104, 70, 71, 30, 107,
70, 108, 39, 79, 71, 109, 30, 72,
70, 68, 39, 69, 67, 105, 104, 30,
78, 104, 70, 98, 97, 54, 110, 97,
87, 71, 54, 107, 87, 61, 56, 62,
56, 15, 57, 56, 63, 56, 15, 29,
30, 79, 28, 112, 111, 30, 31, 111,
28, 114, 113, 85, 52, 113, 51, 115,
113, 116, 117, 85, 118, 119, 113, 51,
29, 120, 54, 55, 53, 26, 54, 52,
51, 112, 111, 54, 55, 111, 53, 122,
121, 54, 55, 121, 53, 124, 123, 85,
52, 123, 51, 126, 125, 127, 34, 103,
36, 37, 125, 25, 124, 125, 103, 27,
125, 25, 29, 128, 30, 31, 28, 26,
30, 27, 25, 130, 129, 30, 31, 129,
28, 130, 129, 30, 131, 129, 28, 29,
30, 107, 28, 122, 121, 54, 132, 121,
53, 29, 54, 107, 53, 10, 11, 12,
13, 14, 9, 134, 135, 136, 137, 138,
139, 133, 0
};
static const char _Parser_trans_targs[] = {
2, 0, 3, 4, 5, 6, 7, 8,
9, 10, 11, 36, 20, 30, 68, 10,
11, 31, 10, 11, 12, 20, 30, 33,
13, 14, 15, 18, 14, 15, 19, 18,
15, 16, 71, 19, 83, 84, 17, 11,
70, 21, 22, 21, 22, 31, 22, 23,
27, 69, 24, 25, 52, 25, 26, 52,
28, 29, 28, 29, 29, 29, 32, 34,
35, 88, 37, 38, 39, 41, 38, 39,
41, 39, 40, 44, 59, 60, 42, 43,
45, 49, 46, 45, 49, 26, 47, 46,
47, 48, 49, 50, 54, 55, 66, 51,
53, 56, 57, 56, 57, 58, 57, 19,
58, 57, 61, 62, 89, 64, 67, 72,
73, 72, 73, 73, 74, 76, 77, 86,
75, 78, 79, 78, 79, 80, 79, 81,
82, 80, 79, 85, 87, 38, 39, 63,
44, 19, 59, 65
};
static const char _Parser_trans_actions[] = {
1, 0, 0, 0, 9, 0, 0, 0,
13, 37, 15, 37, 37, 37, 37, 0,
7, 0, 1, 0, 1, 1, 1, 1,
0, 1, 28, 1, 0, 7, 11, 0,
0, 1, 1, 34, 1, 1, 0, 11,
0, 3, 22, 1, 7, 1, 0, 1,
1, 1, 0, 1, 1, 0, 11, 0,
5, 31, 1, 7, 0, 25, 0, 0,
0, 17, 0, 1, 28, 1, 0, 7,
0, 0, 1, 1, 1, 1, 0, 0,
3, 22, 1, 1, 7, 19, 1, 0,
0, 0, 0, 1, 1, 1, 1, 0,
0, 5, 31, 1, 7, 1, 0, 19,
5, 25, 0, 0, 17, 0, 0, 3,
22, 1, 7, 0, 1, 1, 1, 1,
0, 5, 31, 1, 7, 1, 0, 1,
0, 5, 25, 0, 0, 37, 15, 37,
37, 40, 37, 37
};
static const int Parser_start = 1;
static const int Parser_first_final = 88;
static const int Parser_error = 0;
static const int Parser_en_main = 1;
#line 75 "md_parser.rl"
bool Parser::parse(const std::string& input) {
int cs = 0;
const char *start = nullptr;
const char *begin = input.data();
const char *p = input.data();
const char *pe = p + input.size();
const char *eof = p + input.size(); (void)eof;
std::string tk;
#line 248 "md_parser.cpp"
{
cs = Parser_start;
}
#line 87 "md_parser.rl"
#line 251 "md_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 = _Parser_trans_keys + _Parser_key_offsets[cs];
_trans = _Parser_index_offsets[cs];
_klen = _Parser_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 = _Parser_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:
_trans = _Parser_indicies[_trans];
cs = _Parser_trans_targs[_trans];
if ( _Parser_trans_actions[_trans] == 0 )
goto _again;
_acts = _Parser_actions + _Parser_trans_actions[_trans];
_nacts = (unsigned int) *_acts++;
while ( _nacts-- > 0 )
{
switch ( *_acts++ )
{
case 0:
#line 14 "md_parser.rl"
{ start = p; }
break;
case 1:
#line 15 "md_parser.rl"
{ last = TITLE; }
break;
case 2:
#line 17 "md_parser.rl"
{ last = ENUM; }
break;
case 3:
#line 19 "md_parser.rl"
{
if(last == TITLE) {
title = input.substr(start - begin, p - start);
} else if(last == ENUM) {
content += "* " + input.substr(start - begin, p - start);
content += "\n";
} else {
content += input.substr(start - begin, p - start);
content += "\n";
}
last = PLAIN;
}
break;
case 4:
#line 32 "md_parser.rl"
{
tk = input.substr(start - begin, p - start);
deck->config = json::parse(tk);
std::cout << "META:" << deck->config << '\n';
}
break;
case 5:
#line 38 "md_parser.rl"
{
config["image"] = input.substr(start - begin, p - start);
}
break;
case 6:
#line 42 "md_parser.rl"
{ fmt::println("----- START"); }
break;
case 7:
#line 44 "md_parser.rl"
{
title.clear();
content.clear();
}
break;
case 8:
#line 49 "md_parser.rl"
{
deck->slides.emplace_back(title, content, config);
}
break;
#line 374 "md_parser.cpp"
}
}
_again:
if ( cs == 0 )
goto _out;
if ( ++p != pe )
goto _resume;
_test_eof: {}
_out: {}
}
#line 88 "md_parser.rl"
bool good = pe - p == 0;
if(good) {
finalize();
} else {
error = true;
std::cout << "!!!!!!!!!!!!!!!!!!!!!! error at:";
std::cout << p;
}
return good;
}