Exploring raycasters and possibly make a little "doom like" game based on it.
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.
 
 
 
 
 
 
raycaster/lel_parser.cpp

261 lines
4.7 KiB

#line 1 "lel_parser.rl"
#include "lel.hpp"
#include <fmt/core.h>
#include <iostream>
namespace lel {
#line 40 "lel_parser.rl"
#line 10 "lel_parser.cpp"
static const char _Parser_actions[] = {
0, 1, 1, 1, 2, 1, 3, 1,
4, 1, 5, 1, 6, 1, 9, 1,
10, 1, 11, 1, 12, 1, 13, 2,
0, 7, 2, 0, 8, 2, 4, 1,
2, 4, 5
};
static const char _Parser_key_offsets[] = {
0, 0, 4, 20, 33, 35, 39, 41,
44, 56, 61
};
static const char _Parser_trans_keys[] = {
32, 91, 9, 13, 32, 37, 40, 42,
46, 61, 94, 95, 9, 13, 60, 62,
65, 90, 97, 122, 37, 40, 42, 46,
61, 94, 95, 60, 62, 65, 90, 97,
122, 48, 57, 41, 44, 48, 57, 48,
57, 41, 48, 57, 32, 93, 95, 124,
9, 13, 48, 57, 65, 90, 97, 122,
32, 93, 124, 9, 13, 32, 91, 9,
13, 0
};
static const char _Parser_single_lengths[] = {
0, 2, 8, 7, 0, 2, 0, 1,
4, 3, 2
};
static const char _Parser_range_lengths[] = {
0, 1, 4, 3, 1, 1, 1, 1,
4, 1, 1
};
static const char _Parser_index_offsets[] = {
0, 0, 4, 17, 28, 30, 34, 36,
39, 48, 53
};
static const char _Parser_indicies[] = {
0, 2, 0, 1, 3, 4, 5, 6,
7, 9, 7, 10, 3, 8, 10, 10,
1, 4, 5, 6, 7, 9, 7, 10,
8, 10, 10, 1, 11, 1, 12, 13,
14, 1, 15, 1, 16, 17, 1, 18,
20, 19, 21, 18, 19, 19, 19, 1,
22, 23, 24, 22, 1, 25, 2, 25,
1, 0
};
static const char _Parser_trans_targs[] = {
1, 0, 2, 2, 3, 4, 3, 3,
3, 3, 8, 5, 3, 6, 5, 7,
3, 7, 9, 8, 10, 2, 9, 10,
2, 10
};
static const char _Parser_trans_actions[] = {
0, 0, 3, 0, 17, 0, 13, 5,
11, 15, 21, 19, 23, 23, 0, 19,
26, 0, 7, 0, 32, 29, 0, 9,
1, 0
};
static const int Parser_start = 1;
static const int Parser_first_final = 10;
static const int Parser_error = 0;
static const int Parser_en_main = 1;
#line 43 "lel_parser.rl"
bool Parser::parse(std::string input) {
reset();
int cs = 0;
const char *start = nullptr;
const char *begin = input.data();
const char *p = input.data();
const char *pe = p + input.size();
std::string tk;
#line 91 "lel_parser.cpp"
{
cs = Parser_start;
}
#line 54 "lel_parser.rl"
#line 94 "lel_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 11 "lel_parser.rl"
{tk = input.substr(start - begin, p - start); }
break;
case 1:
#line 13 "lel_parser.rl"
{}
break;
case 2:
#line 14 "lel_parser.rl"
{ grid.push_back(Row()); }
break;
case 3:
#line 15 "lel_parser.rl"
{ cur.bottom = (*p) == '.'; }
break;
case 4:
#line 16 "lel_parser.rl"
{ id(input.substr(start - begin, p - start)); }
break;
case 5:
#line 17 "lel_parser.rl"
{ cur.col = 0; cur.row++; }
break;
case 6:
#line 18 "lel_parser.rl"
{ cur.right = (*p) == '>'; }
break;
case 7:
#line 19 "lel_parser.rl"
{cur.max_w = std::stoi(tk); }
break;
case 8:
#line 20 "lel_parser.rl"
{ cur.max_h = std::stoi(tk); }
break;
case 9:
#line 21 "lel_parser.rl"
{ cur.expand = true; }
break;
case 10:
#line 22 "lel_parser.rl"
{ cur.center = true; }
break;
case 11:
#line 23 "lel_parser.rl"
{ cur.percent = true; }
break;
case 12:
#line 33 "lel_parser.rl"
{ start = p; }
break;
case 13:
#line 36 "lel_parser.rl"
{start = p;}
break;
#line 209 "lel_parser.cpp"
}
}
_again:
if ( cs == 0 )
goto _out;
if ( ++p != pe )
goto _resume;
_test_eof: {}
_out: {}
}
#line 55 "lel_parser.rl"
bool good = pe - p == 0;
if(good) {
finalize();
} else {
fmt::println("error at");
std::cout << p;
}
return good;
}
}