Just move all the one-liner functions straight into the parser.
This commit is contained in:
parent
60ed686eb0
commit
d558da1620
4 changed files with 38 additions and 76 deletions
37
lel.cpp
37
lel.cpp
|
@ -16,21 +16,6 @@ namespace lel {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::ltab() {
|
|
||||||
cur.row = rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Parser::col() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Parser::valign(char dir) {
|
|
||||||
cur.bottom = dir == '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
void Parser::align(char dir) {
|
|
||||||
cur.right = dir == '>';
|
|
||||||
}
|
|
||||||
|
|
||||||
void Parser::id(std::string name) {
|
void Parser::id(std::string name) {
|
||||||
if(name != "_") {
|
if(name != "_") {
|
||||||
dbc::check(!cells.contains(name),
|
dbc::check(!cells.contains(name),
|
||||||
|
@ -41,28 +26,6 @@ namespace lel {
|
||||||
cur = {cur.col + 1, cur.row};
|
cur = {cur.col + 1, cur.row};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::row() {
|
|
||||||
rows++;
|
|
||||||
columns = std::max(columns, cur.col);
|
|
||||||
cur.col = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Parser::setwidth(int width) {
|
|
||||||
cur.max_w = width;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Parser::setheight(int height) {
|
|
||||||
cur.max_h = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Parser::expand() {
|
|
||||||
cur.expand = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Parser::center() {
|
|
||||||
cur.center = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Parser::finalize() {
|
void Parser::finalize() {
|
||||||
dbc::check(columns > 0, "columns are 0");
|
dbc::check(columns > 0, "columns are 0");
|
||||||
dbc::check(rows > 0, "rows are 0");
|
dbc::check(rows > 0, "rows are 0");
|
||||||
|
|
9
lel.hpp
9
lel.hpp
|
@ -32,17 +32,8 @@ namespace lel {
|
||||||
std::unordered_map<std::string, Cell> cells;
|
std::unordered_map<std::string, Cell> cells;
|
||||||
|
|
||||||
Parser(int x, int y, int width, int height);
|
Parser(int x, int y, int width, int height);
|
||||||
void col();
|
|
||||||
void ltab();
|
|
||||||
void align(char dir);
|
|
||||||
void valign(char dir);
|
|
||||||
void id(std::string name);
|
void id(std::string name);
|
||||||
void row();
|
|
||||||
void setwidth(int width);
|
|
||||||
void setheight(int height);
|
|
||||||
void expand();
|
|
||||||
void reset();
|
void reset();
|
||||||
void center();
|
|
||||||
bool parse(std::string input);
|
bool parse(std::string input);
|
||||||
void finalize();
|
void finalize();
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
namespace lel {
|
namespace lel {
|
||||||
|
|
||||||
|
|
||||||
#line 38 "lel_parser.rl"
|
#line 42 "lel_parser.rl"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ static const int Parser_error = 0;
|
||||||
static const int Parser_en_main = 1;
|
static const int Parser_en_main = 1;
|
||||||
|
|
||||||
|
|
||||||
#line 41 "lel_parser.rl"
|
#line 45 "lel_parser.rl"
|
||||||
|
|
||||||
bool Parser::parse(std::string input) {
|
bool Parser::parse(std::string input) {
|
||||||
reset();
|
reset();
|
||||||
|
@ -99,7 +99,7 @@ bool Parser::parse(std::string input) {
|
||||||
cs = Parser_start;
|
cs = Parser_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
#line 52 "lel_parser.rl"
|
#line 56 "lel_parser.rl"
|
||||||
|
|
||||||
#line 92 "lel_parser.cpp"
|
#line 92 "lel_parser.cpp"
|
||||||
{
|
{
|
||||||
|
@ -181,15 +181,15 @@ _match:
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
#line 13 "lel_parser.rl"
|
#line 13 "lel_parser.rl"
|
||||||
{ col(); }
|
{ }
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
#line 14 "lel_parser.rl"
|
#line 14 "lel_parser.rl"
|
||||||
{ ltab(); }
|
{ cur.row = rows; }
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
#line 15 "lel_parser.rl"
|
#line 15 "lel_parser.rl"
|
||||||
{ valign((*p)); }
|
{ cur.bottom = (*p) == '.'; }
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
#line 16 "lel_parser.rl"
|
#line 16 "lel_parser.rl"
|
||||||
|
@ -197,37 +197,41 @@ _match:
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
#line 17 "lel_parser.rl"
|
#line 17 "lel_parser.rl"
|
||||||
{ row(); }
|
{
|
||||||
|
rows++;
|
||||||
|
columns = std::max(columns, cur.col);
|
||||||
|
cur.col = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
#line 18 "lel_parser.rl"
|
#line 22 "lel_parser.rl"
|
||||||
{ align((*p)); }
|
{ cur.right = (*p) == '>'; }
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
#line 19 "lel_parser.rl"
|
#line 23 "lel_parser.rl"
|
||||||
{ setwidth(std::stoi(tk)); }
|
{cur.max_w = std::stoi(tk); }
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
#line 20 "lel_parser.rl"
|
#line 24 "lel_parser.rl"
|
||||||
{ setheight(std::stoi(tk)); }
|
{ cur.max_h = std::stoi(tk); }
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
#line 21 "lel_parser.rl"
|
#line 25 "lel_parser.rl"
|
||||||
{ expand(); }
|
{ cur.expand = true; }
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
#line 22 "lel_parser.rl"
|
#line 26 "lel_parser.rl"
|
||||||
{ center(); }
|
{ cur.center = true; }
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
#line 31 "lel_parser.rl"
|
#line 35 "lel_parser.rl"
|
||||||
{ start = p; }
|
{ start = p; }
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
#line 34 "lel_parser.rl"
|
#line 38 "lel_parser.rl"
|
||||||
{start = p;}
|
{start = p;}
|
||||||
break;
|
break;
|
||||||
#line 204 "lel_parser.cpp"
|
#line 208 "lel_parser.cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +244,7 @@ _again:
|
||||||
_out: {}
|
_out: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#line 53 "lel_parser.rl"
|
#line 57 "lel_parser.rl"
|
||||||
|
|
||||||
bool good = pe - p == 0;
|
bool good = pe - p == 0;
|
||||||
if(good) {
|
if(good) {
|
||||||
|
|
|
@ -10,16 +10,20 @@ namespace lel {
|
||||||
|
|
||||||
action token {tk = input.substr(start - begin, fpc - start); }
|
action token {tk = input.substr(start - begin, fpc - start); }
|
||||||
|
|
||||||
action col { col(); }
|
action col { }
|
||||||
action ltab { ltab(); }
|
action ltab { cur.row = rows; }
|
||||||
action valign { valign(fc); }
|
action valign { cur.bottom = fc == '.'; }
|
||||||
action id { id(input.substr(start - begin, fpc - start)); }
|
action id { id(input.substr(start - begin, fpc - start)); }
|
||||||
action row { row(); }
|
action row {
|
||||||
action align { align(fc); }
|
rows++;
|
||||||
action setwidth { setwidth(std::stoi(tk)); }
|
columns = std::max(columns, cur.col);
|
||||||
action setheight { setheight(std::stoi(tk)); }
|
cur.col = 0;
|
||||||
action expand { expand(); }
|
}
|
||||||
action center { center(); }
|
action align { cur.right = fc == '>'; }
|
||||||
|
action setwidth {cur.max_w = std::stoi(tk); }
|
||||||
|
action setheight { cur.max_h = std::stoi(tk); }
|
||||||
|
action expand { cur.expand = true; }
|
||||||
|
action center { cur.center = true; }
|
||||||
|
|
||||||
col = "|" $col;
|
col = "|" $col;
|
||||||
ltab = "[" $ltab;
|
ltab = "[" $ltab;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue