From 846b7aaf1696a35be75926164f9e76b8db6e5778 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 14 Feb 2025 15:40:15 -0500 Subject: [PATCH] Initial cut of the lel parser mostly working but none of the basic alignment properties work. --- Makefile | 4 +- dinkyecs.hpp | 182 +++++++++++++++++------- lel.cpp | 302 ++++++---------------------------------- lel.hpp | 42 ++++++ lel_parser.cpp | 260 ++++++++++++++++++++++++++++++++++ lel.rl => lel_parser.rl | 38 +---- tests/lel.cpp | 18 ++- 7 files changed, 492 insertions(+), 354 deletions(-) create mode 100644 lel.hpp create mode 100644 lel_parser.cpp rename lel.rl => lel_parser.rl (68%) diff --git a/Makefile b/Makefile index 6f831de..097aa95 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ reset: %.cpp : %.rl ragel -o $@ $< -build: ansi_parser.cpp lel.cpp +build: ansi_parser.cpp lel_parser.cpp meson compile -j 10 -C builddir release_build: @@ -22,7 +22,7 @@ tracy_build: meson compile -j 10 -C builddir test: build - ./builddir/runtests + ./builddir/runtests "[lel]" run: build test powershell "cp ./builddir/zedcaster.exe ." diff --git a/dinkyecs.hpp b/dinkyecs.hpp index c8dc3bc..c0644f2 100644 --- a/dinkyecs.hpp +++ b/dinkyecs.hpp @@ -1,20 +1,29 @@ #pragma once +#include "dbc.hpp" +#include #include +#include +#include #include #include #include -#include -#include -#include -#include "dbc.hpp" -namespace DinkyECS { +namespace DinkyECS +{ typedef unsigned long Entity; - using EntityMap = std::unordered_map; + using EntityMap = std::unordered_map; - struct Event { + template + struct ComponentStorage + { + std::vector data; + std::queue free_indices; + }; + + struct Event + { int event = 0; Entity entity = 0; std::any data; @@ -22,135 +31,202 @@ namespace DinkyECS { typedef std::queue EventQueue; - struct World { + struct World + { unsigned long entity_count = 0; std::unordered_map $components; std::unordered_map $facts; std::unordered_map $events; + std::unordered_map $component_storages; std::vector $constants; - Entity entity() { - return ++entity_count; - } + Entity entity() { return ++entity_count; } - void clone_into(DinkyECS::World &to_world) { + void clone_into(DinkyECS::World &to_world) + { to_world.$constants = $constants; to_world.$facts = $facts; to_world.entity_count = entity_count; - - for(auto eid : $constants) { - for(const auto &[tid, eid_map] : $components) { - auto& their_map = to_world.$components[tid]; - if(eid_map.contains(eid)) { + to_world.$component_storages = $component_storages; + + for (auto eid : $constants) + { + for (const auto &[tid, eid_map] : $components) + { + auto &their_map = to_world.$components[tid]; + if (eid_map.contains(eid)) + { their_map.insert_or_assign(eid, eid_map.at(eid)); } } } } - void make_constant(DinkyECS::Entity entity) { - $constants.push_back(entity); + void make_constant(DinkyECS::Entity entity) + { + $constants.push_back(entity); } template - EntityMap& entity_map_for() { + size_t make_component() + { + auto &storage = component_storage_for(); + size_t index; + + if (!storage.free_indices.empty()) + { + index = storage.free_indices.front(); + storage.free_indices.pop(); + } + else + { + storage.data.emplace_back(); + index = storage.data.size() - 1; + } + + return index; + } + + template + ComponentStorage &component_storage_for() + { + auto type_index = std::type_index(typeid(Comp)); + $component_storages.try_emplace(type_index, ComponentStorage{}); + return std::any_cast &>( + $component_storages.at(type_index)); + } + + template + EntityMap &entity_map_for() + { return $components[std::type_index(typeid(Comp))]; } template - EventQueue& queue_map_for() { + EventQueue &queue_map_for() + { return $events[std::type_index(typeid(Comp))]; } template - void remove(Entity ent) { + void remove(Entity ent) + { EntityMap &map = entity_map_for(); + + if (map.contains(ent)) + { + size_t index = map.at(ent); + component_storage_for().free_indices.push(index); + } + map.erase(ent); } template - void set_the(Comp val) { + void set_the(Comp val) + { $facts.insert_or_assign(std::type_index(typeid(Comp)), val); } template - Comp &get_the() { + Comp &get_the() + { auto comp_id = std::type_index(typeid(Comp)); dbc::check($facts.contains(comp_id), - fmt::format("!!!! ATTEMPT to access world fact that hasn't been set yet: {}", typeid(Comp).name())); + fmt::format("!!!! ATTEMPT to access world fact that hasn't " + "been set yet: {}", + typeid(Comp).name())); // use .at to get std::out_of_range if fact not set std::any &res = $facts.at(comp_id); - return std::any_cast(res); + return std::any_cast(res); } template - bool has_the() { + bool has_the() + { auto comp_id = std::type_index(typeid(Comp)); return $facts.contains(comp_id); } template - void set(Entity ent, Comp val) { + void set(Entity ent, Comp val) + { EntityMap &map = entity_map_for(); - map.insert_or_assign(ent, val); + + if (has(ent)) + { + get(ent) = val; + return; + } + + map.insert_or_assign(ent, make_component()); + get(ent) = val; } template - Comp &get(Entity ent) { + Comp &get(Entity ent) + { EntityMap &map = entity_map_for(); - // use .at for bounds checking - std::any &res = map.at(ent); - return std::any_cast(res); + auto &storage = component_storage_for(); + auto index = map.at(ent); + return storage.data[index]; } template - bool has(Entity ent) { + bool has(Entity ent) + { EntityMap &map = entity_map_for(); return map.contains(ent); } - template - void query(std::function cb) { + template + void query(std::function cb) + { EntityMap &map = entity_map_for(); - for(auto& [entity, any_comp] : map) { - Comp &res = std::any_cast(any_comp); - cb(entity, res); + + for (auto &[entity, index] : map) + { + cb(entity, get(entity)); } } - template - void query(std::function cb) { + template + void query(std::function cb) + { EntityMap &map_a = entity_map_for(); EntityMap &map_b = entity_map_for(); - for(auto& [entity, any_a] : map_a) { - if(map_b.contains(entity)) { - CompA &res_a = std::any_cast(any_a); - CompB &res_b = get(entity); - cb(entity, res_a, res_b); + for (auto &[entity, index_a] : map_a) + { + if (map_b.contains(entity)) + { + cb(entity, get(entity), get(entity)); } } } - template - void send(Comp event, Entity entity, std::any data) { + template + void send(Comp event, Entity entity, std::any data) + { EventQueue &queue = queue_map_for(); queue.push({event, entity, data}); } - template - Event recv() { + template + Event recv() + { EventQueue &queue = queue_map_for(); Event evt = queue.front(); queue.pop(); return evt; } - template - bool has_event() { + template + bool has_event() + { EventQueue &queue = queue_map_for(); return !queue.empty(); } }; -} +} // namespace DinkyECS diff --git a/lel.cpp b/lel.cpp index ac59ef0..f4b4d72 100644 --- a/lel.cpp +++ b/lel.cpp @@ -1,294 +1,82 @@ - -#line 1 "lel.rl" #include "lel.hpp" #include +#include "lel_parser.cpp" -#line 33 "lel.rl" - - - -#line 7 "lel.cpp" -static const char _LELParser_actions[] = { - 0, 1, 1, 1, 2, 1, 3, 1, - 4, 1, 5, 1, 6, 1, 9, 1, - 10, 1, 11, 2, 0, 7, 2, 0, - 8, 2, 4, 1, 2, 4, 5 -}; - -static const char _LELParser_key_offsets[] = { - 0, 0, 4, 18, 20, 24, 35, 47, - 52, 66, 68, 72, 83, 95, 99, 101, - 104, 106, 109 -}; - -static const char _LELParser_trans_keys[] = { - 32, 91, 9, 13, 32, 40, 42, 46, - 60, 62, 94, 95, 9, 13, 65, 90, - 97, 122, 48, 57, 41, 44, 48, 57, - 40, 42, 46, 60, 62, 94, 95, 65, - 90, 97, 122, 32, 93, 95, 124, 9, - 13, 48, 57, 65, 90, 97, 122, 32, - 93, 124, 9, 13, 32, 40, 42, 46, - 60, 62, 94, 95, 9, 13, 65, 90, - 97, 122, 48, 57, 41, 44, 48, 57, - 40, 42, 46, 60, 62, 94, 95, 65, - 90, 97, 122, 32, 93, 95, 124, 9, - 13, 48, 57, 65, 90, 97, 122, 32, - 93, 9, 13, 48, 57, 41, 48, 57, - 48, 57, 41, 48, 57, 32, 91, 9, - 13, 0 -}; - -static const char _LELParser_single_lengths[] = { - 0, 2, 8, 0, 2, 7, 4, 3, - 8, 0, 2, 7, 4, 2, 0, 1, - 0, 1, 2 -}; - -static const char _LELParser_range_lengths[] = { - 0, 1, 3, 1, 1, 2, 4, 1, - 3, 1, 1, 2, 4, 1, 1, 1, - 1, 1, 1 -}; - -static const char _LELParser_index_offsets[] = { - 0, 0, 4, 16, 18, 22, 32, 41, - 46, 58, 60, 64, 74, 83, 87, 89, - 92, 94, 97 -}; - -static const char _LELParser_indicies[] = { - 0, 2, 0, 1, 3, 4, 5, 6, - 7, 7, 6, 8, 3, 8, 8, 1, - 9, 1, 10, 11, 12, 1, 4, 5, - 6, 7, 7, 6, 8, 8, 8, 1, - 13, 15, 14, 16, 13, 14, 14, 14, - 1, 17, 18, 19, 17, 1, 20, 21, - 22, 23, 24, 24, 23, 25, 20, 25, - 25, 1, 26, 1, 27, 28, 29, 1, - 21, 22, 23, 24, 24, 23, 25, 25, - 25, 1, 30, 15, 31, 16, 30, 31, - 31, 31, 1, 32, 18, 32, 1, 33, - 1, 34, 35, 1, 36, 1, 37, 38, - 1, 39, 2, 39, 1, 0 -}; - -static const char _LELParser_trans_targs[] = { - 1, 0, 2, 2, 3, 5, 5, 5, - 6, 4, 5, 16, 4, 7, 6, 18, - 8, 7, 18, 8, 8, 9, 11, 11, - 11, 12, 10, 11, 14, 10, 13, 12, - 13, 15, 11, 15, 17, 5, 17, 18 -}; - -static const char _LELParser_trans_actions[] = { - 0, 0, 3, 0, 0, 13, 5, 11, - 17, 15, 19, 19, 0, 7, 0, 28, - 25, 0, 9, 1, 0, 0, 13, 5, - 11, 17, 15, 19, 19, 0, 7, 0, - 0, 15, 22, 0, 15, 22, 0, 0 -}; - -static const int LELParser_start = 1; -static const int LELParser_first_final = 18; -static const int LELParser_error = 0; - -static const int LELParser_en_main = 1; - - -#line 36 "lel.rl" - -bool LELParser::parse(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(); - std::string tk; - - -#line 103 "lel.cpp" - { - cs = LELParser_start; - } - -#line 46 "lel.rl" - -#line 106 "lel.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 = _LELParser_trans_keys + _LELParser_key_offsets[cs]; - _trans = _LELParser_index_offsets[cs]; +LELParser::LELParser(int x, int y, int width, int height) : + grid_x(x), + grid_y(y), + grid_w(width), + grid_h(height), + cur(0, 0) +{ - _klen = _LELParser_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 = _LELParser_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 = _LELParser_indicies[_trans]; - cs = _LELParser_trans_targs[_trans]; - - if ( _LELParser_trans_actions[_trans] == 0 ) - goto _again; - - _acts = _LELParser_actions + _LELParser_trans_actions[_trans]; - _nacts = (unsigned int) *_acts++; - while ( _nacts-- > 0 ) - { - switch ( *_acts++ ) - { - case 0: -#line 8 "lel.rl" - {tk = input.substr(start - begin, p - start); } - break; - case 1: -#line 10 "lel.rl" - { col(); } - break; - case 2: -#line 11 "lel.rl" - { ltab(); } - break; - case 3: -#line 12 "lel.rl" - { valign((*p)); } - break; - case 4: -#line 13 "lel.rl" - { id(input.substr(start - begin, p - start)); } - break; - case 5: -#line 14 "lel.rl" - { row(); } - break; - case 6: -#line 15 "lel.rl" - { align((*p)); } - break; - case 7: -#line 16 "lel.rl" - { setwidth(std::stoi(tk)); } - break; - case 8: -#line 17 "lel.rl" - { setheight(std::stoi(tk)); } - break; - case 9: -#line 18 "lel.rl" - { expand(); } - break; - case 10: -#line 26 "lel.rl" - { start = p; } - break; - case 11: -#line 29 "lel.rl" - {start = p;} - break; -#line 215 "lel.cpp" - } - } - -_again: - if ( cs == 0 ) - goto _out; - if ( ++p != pe ) - goto _resume; - _test_eof: {} - _out: {} - } - -#line 47 "lel.rl" - - bool good = pe - p == 0; - - return good; } -void LELParser::col() { - fmt::println("col"); +void LELParser::ltab() { + cur.row = row_count; + fmt::println("ltab: rows {}", row_count); } -void LELParser::ltab() { - fmt::println("ltab"); +void LELParser::col() { } void LELParser::valign(char dir) { + cur.top = dir == '^'; fmt::println("valign: {}", dir); } void LELParser::align(char dir) { + cur.left = dir == '<'; fmt::println("align {}", dir); } void LELParser::id(std::string name) { fmt::println("id: {}", name); + cells.insert_or_assign(name, cur); + cur = {cur.col + 1, cur.row}; } void LELParser::row() { - fmt::println("row"); + row_count++; + max_columns = std::max(max_columns, cur.col); + cur.col = 0; + fmt::println("row end: cols {}", cur.col); } void LELParser::setwidth(int width) { fmt::println("setwidth: {}", width); + cur.w = width; } void LELParser::setheight(int height) { fmt::println("setheight: {}", height); + cur.h = height; } void LELParser::expand() { fmt::println("expand"); + cur.expand = true; +} + +void LELParser::finalize() { + int cell_width = grid_w / max_columns; + int cell_height = grid_h / row_count; + fmt::println("FINALIZE: cell w/h: {},{}", cell_width, cell_height); + + for(auto [name, cell] : cells) { + cell.x = cell.col * cell_width; + cell.y = cell.row * cell_height; + if(cell.w == 0) cell.w = cell_width; + if(cell.x == 0) cell.h = cell_height; + + fmt::println("name={}; col/row={},{}; x/y={},{} w/h={},{}; left={}, top={}, expand={}", + name, cell.col, cell.row, cell.x, cell.y, cell.w, cell.h, cell.left, cell.top, cell.expand); + } +} + +void LELParser::reset() { + row_count = 0; + max_columns = 0; + cur = {0, 0}; } diff --git a/lel.hpp b/lel.hpp new file mode 100644 index 0000000..9baf0a7 --- /dev/null +++ b/lel.hpp @@ -0,0 +1,42 @@ +#pragma once +#include +#include + +struct Cell { + int x = 0; + int y = 0; + int w = 0; + int h = 0; + int col = 0; + int row = 0; + bool left = true; + bool top = true; + bool expand = false; + + Cell(int col, int row) : col(col), row(row) {} +}; + +struct LELParser { + int grid_x = 0; + int grid_y = 0; + int grid_w = 0; + int grid_h = 0; + int row_count = 0; + int max_columns = 0; + Cell cur; + std::unordered_map cells; + + LELParser(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(); + bool parse(std::string input); + void finalize(); +}; diff --git a/lel_parser.cpp b/lel_parser.cpp new file mode 100644 index 0000000..c5e284b --- /dev/null +++ b/lel_parser.cpp @@ -0,0 +1,260 @@ + +#line 1 "lel_parser.rl" +#include "lel.hpp" +#include + + +#line 33 "lel_parser.rl" + + + +#line 7 "lel_parser.cpp" +static const char _LELParser_actions[] = { + 0, 1, 1, 1, 2, 1, 3, 1, + 4, 1, 5, 1, 6, 1, 9, 1, + 10, 1, 11, 2, 0, 7, 2, 0, + 8, 2, 4, 1, 2, 4, 5 +}; + +static const char _LELParser_key_offsets[] = { + 0, 0, 4, 18, 20, 24, 35, 47, + 52, 66, 68, 72, 83, 95, 99, 101, + 104, 106, 109 +}; + +static const char _LELParser_trans_keys[] = { + 32, 91, 9, 13, 32, 40, 42, 46, + 60, 62, 94, 95, 9, 13, 65, 90, + 97, 122, 48, 57, 41, 44, 48, 57, + 40, 42, 46, 60, 62, 94, 95, 65, + 90, 97, 122, 32, 93, 95, 124, 9, + 13, 48, 57, 65, 90, 97, 122, 32, + 93, 124, 9, 13, 32, 40, 42, 46, + 60, 62, 94, 95, 9, 13, 65, 90, + 97, 122, 48, 57, 41, 44, 48, 57, + 40, 42, 46, 60, 62, 94, 95, 65, + 90, 97, 122, 32, 93, 95, 124, 9, + 13, 48, 57, 65, 90, 97, 122, 32, + 93, 9, 13, 48, 57, 41, 48, 57, + 48, 57, 41, 48, 57, 32, 91, 9, + 13, 0 +}; + +static const char _LELParser_single_lengths[] = { + 0, 2, 8, 0, 2, 7, 4, 3, + 8, 0, 2, 7, 4, 2, 0, 1, + 0, 1, 2 +}; + +static const char _LELParser_range_lengths[] = { + 0, 1, 3, 1, 1, 2, 4, 1, + 3, 1, 1, 2, 4, 1, 1, 1, + 1, 1, 1 +}; + +static const char _LELParser_index_offsets[] = { + 0, 0, 4, 16, 18, 22, 32, 41, + 46, 58, 60, 64, 74, 83, 87, 89, + 92, 94, 97 +}; + +static const char _LELParser_indicies[] = { + 0, 2, 0, 1, 3, 4, 5, 6, + 7, 7, 6, 8, 3, 8, 8, 1, + 9, 1, 10, 11, 12, 1, 4, 5, + 6, 7, 7, 6, 8, 8, 8, 1, + 13, 15, 14, 16, 13, 14, 14, 14, + 1, 17, 18, 19, 17, 1, 20, 21, + 22, 23, 24, 24, 23, 25, 20, 25, + 25, 1, 26, 1, 27, 28, 29, 1, + 21, 22, 23, 24, 24, 23, 25, 25, + 25, 1, 30, 15, 31, 16, 30, 31, + 31, 31, 1, 32, 18, 32, 1, 33, + 1, 34, 35, 1, 36, 1, 37, 38, + 1, 39, 2, 39, 1, 0 +}; + +static const char _LELParser_trans_targs[] = { + 1, 0, 2, 2, 3, 5, 5, 5, + 6, 4, 5, 16, 4, 7, 6, 18, + 8, 7, 18, 8, 8, 9, 11, 11, + 11, 12, 10, 11, 14, 10, 13, 12, + 13, 15, 11, 15, 17, 5, 17, 18 +}; + +static const char _LELParser_trans_actions[] = { + 0, 0, 3, 0, 0, 13, 5, 11, + 17, 15, 19, 19, 0, 7, 0, 28, + 25, 0, 9, 1, 0, 0, 13, 5, + 11, 17, 15, 19, 19, 0, 7, 0, + 0, 15, 22, 0, 15, 22, 0, 0 +}; + +static const int LELParser_start = 1; +static const int LELParser_first_final = 18; +static const int LELParser_error = 0; + +static const int LELParser_en_main = 1; + + +#line 36 "lel_parser.rl" + +bool LELParser::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 104 "lel_parser.cpp" + { + cs = LELParser_start; + } + +#line 47 "lel_parser.rl" + +#line 107 "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 = _LELParser_trans_keys + _LELParser_key_offsets[cs]; + _trans = _LELParser_index_offsets[cs]; + + _klen = _LELParser_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 = _LELParser_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 = _LELParser_indicies[_trans]; + cs = _LELParser_trans_targs[_trans]; + + if ( _LELParser_trans_actions[_trans] == 0 ) + goto _again; + + _acts = _LELParser_actions + _LELParser_trans_actions[_trans]; + _nacts = (unsigned int) *_acts++; + while ( _nacts-- > 0 ) + { + switch ( *_acts++ ) + { + case 0: +#line 8 "lel_parser.rl" + {tk = input.substr(start - begin, p - start); } + break; + case 1: +#line 10 "lel_parser.rl" + { col(); } + break; + case 2: +#line 11 "lel_parser.rl" + { ltab(); } + break; + case 3: +#line 12 "lel_parser.rl" + { valign((*p)); } + break; + case 4: +#line 13 "lel_parser.rl" + { id(input.substr(start - begin, p - start)); } + break; + case 5: +#line 14 "lel_parser.rl" + { row(); } + break; + case 6: +#line 15 "lel_parser.rl" + { align((*p)); } + break; + case 7: +#line 16 "lel_parser.rl" + { setwidth(std::stoi(tk)); } + break; + case 8: +#line 17 "lel_parser.rl" + { setheight(std::stoi(tk)); } + break; + case 9: +#line 18 "lel_parser.rl" + { expand(); } + break; + case 10: +#line 26 "lel_parser.rl" + { start = p; } + break; + case 11: +#line 29 "lel_parser.rl" + {start = p;} + break; +#line 216 "lel_parser.cpp" + } + } + +_again: + if ( cs == 0 ) + goto _out; + if ( ++p != pe ) + goto _resume; + _test_eof: {} + _out: {} + } + +#line 48 "lel_parser.rl" + + bool good = pe - p == 0; + finalize(); + + return good; +} diff --git a/lel.rl b/lel_parser.rl similarity index 68% rename from lel.rl rename to lel_parser.rl index 555e7b7..8bc89d9 100644 --- a/lel.rl +++ b/lel_parser.rl @@ -35,6 +35,7 @@ %% write data; bool LELParser::parse(std::string input) { + reset(); int cs = 0; const char *start = nullptr; const char *begin = input.data(); @@ -46,42 +47,7 @@ bool LELParser::parse(std::string input) { %% write exec; bool good = pe - p == 0; + finalize(); return good; } - -void LELParser::col() { - fmt::println("col"); -} - -void LELParser::ltab() { - fmt::println("ltab"); -} - -void LELParser::valign(char dir) { - fmt::println("valign: {}", dir); -} - -void LELParser::align(char dir) { - fmt::println("align {}", dir); -} - -void LELParser::id(std::string name) { - fmt::println("id: {}", name); -} - -void LELParser::row() { - fmt::println("row"); -} - -void LELParser::setwidth(int width) { - fmt::println("setwidth: {}", width); -} - -void LELParser::setheight(int height) { - fmt::println("setheight: {}", height); -} - -void LELParser::expand() { - fmt::println("expand"); -} diff --git a/tests/lel.cpp b/tests/lel.cpp index b142433..cae1056 100644 --- a/tests/lel.cpp +++ b/tests/lel.cpp @@ -6,16 +6,22 @@ #include #include - - TEST_CASE("test basic ops", "[lel]") { - LELParser parser; + LELParser parser(0, 0, 500, 500); bool good = parser.parse( - "[ label_1 | label3 ]" - "[ (300,300)*text1 | (150)people ]" - "[ label2 | _ ]" "[ message | buttons ]"); REQUIRE(good); + + REQUIRE(parser.row_count == 4); + REQUIRE(parser.max_columns == 2); + REQUIRE(parser.cells.size() == 8); + REQUIRE(parser.cells.at("label2").left == false); + REQUIRE(parser.cells.at("label3").expand == true); + REQUIRE(parser.cells.at("people").expand == false); + REQUIRE(parser.cells.at("message").expand == false); }