From d558da162048941f329bf63be87a5a5936f50118 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 15 Feb 2025 12:21:04 -0500 Subject: [PATCH] Just move all the one-liner functions straight into the parser. --- lel.cpp | 37 ------------------------------------- lel.hpp | 9 --------- lel_parser.cpp | 46 +++++++++++++++++++++++++--------------------- lel_parser.rl | 22 +++++++++++++--------- 4 files changed, 38 insertions(+), 76 deletions(-) diff --git a/lel.cpp b/lel.cpp index 2f15d6b..a4bb4fd 100644 --- a/lel.cpp +++ b/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) { if(name != "_") { dbc::check(!cells.contains(name), @@ -41,28 +26,6 @@ namespace lel { 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() { dbc::check(columns > 0, "columns are 0"); dbc::check(rows > 0, "rows are 0"); diff --git a/lel.hpp b/lel.hpp index 41f7476..fde3c38 100644 --- a/lel.hpp +++ b/lel.hpp @@ -32,17 +32,8 @@ namespace lel { std::unordered_map cells; 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 row(); - void setwidth(int width); - void setheight(int height); - void expand(); void reset(); - void center(); bool parse(std::string input); void finalize(); }; diff --git a/lel_parser.cpp b/lel_parser.cpp index dcdc7cb..289fa70 100644 --- a/lel_parser.cpp +++ b/lel_parser.cpp @@ -7,7 +7,7 @@ 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; -#line 41 "lel_parser.rl" +#line 45 "lel_parser.rl" bool Parser::parse(std::string input) { reset(); @@ -99,7 +99,7 @@ bool Parser::parse(std::string input) { cs = Parser_start; } -#line 52 "lel_parser.rl" +#line 56 "lel_parser.rl" #line 92 "lel_parser.cpp" { @@ -181,15 +181,15 @@ _match: break; case 1: #line 13 "lel_parser.rl" - { col(); } + { } break; case 2: #line 14 "lel_parser.rl" - { ltab(); } + { cur.row = rows; } break; case 3: #line 15 "lel_parser.rl" - { valign((*p)); } + { cur.bottom = (*p) == '.'; } break; case 4: #line 16 "lel_parser.rl" @@ -197,37 +197,41 @@ _match: break; case 5: #line 17 "lel_parser.rl" - { row(); } + { + rows++; + columns = std::max(columns, cur.col); + cur.col = 0; + } break; case 6: -#line 18 "lel_parser.rl" - { align((*p)); } +#line 22 "lel_parser.rl" + { cur.right = (*p) == '>'; } break; case 7: -#line 19 "lel_parser.rl" - { setwidth(std::stoi(tk)); } +#line 23 "lel_parser.rl" + {cur.max_w = std::stoi(tk); } break; case 8: -#line 20 "lel_parser.rl" - { setheight(std::stoi(tk)); } +#line 24 "lel_parser.rl" + { cur.max_h = std::stoi(tk); } break; case 9: -#line 21 "lel_parser.rl" - { expand(); } +#line 25 "lel_parser.rl" + { cur.expand = true; } break; case 10: -#line 22 "lel_parser.rl" - { center(); } +#line 26 "lel_parser.rl" + { cur.center = true; } break; case 11: -#line 31 "lel_parser.rl" +#line 35 "lel_parser.rl" { start = p; } break; case 12: -#line 34 "lel_parser.rl" +#line 38 "lel_parser.rl" {start = p;} break; -#line 204 "lel_parser.cpp" +#line 208 "lel_parser.cpp" } } @@ -240,7 +244,7 @@ _again: _out: {} } -#line 53 "lel_parser.rl" +#line 57 "lel_parser.rl" bool good = pe - p == 0; if(good) { diff --git a/lel_parser.rl b/lel_parser.rl index aa07da0..fa6aed9 100644 --- a/lel_parser.rl +++ b/lel_parser.rl @@ -10,16 +10,20 @@ namespace lel { action token {tk = input.substr(start - begin, fpc - start); } - action col { col(); } - action ltab { ltab(); } - action valign { valign(fc); } + action col { } + action ltab { cur.row = rows; } + action valign { cur.bottom = fc == '.'; } action id { id(input.substr(start - begin, fpc - start)); } - action row { row(); } - action align { align(fc); } - action setwidth { setwidth(std::stoi(tk)); } - action setheight { setheight(std::stoi(tk)); } - action expand { expand(); } - action center { center(); } + action row { + rows++; + columns = std::max(columns, cur.col); + cur.col = 0; + } + 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; ltab = "[" $ltab;