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.rl

66 lines
1.6 KiB

#include "lel.hpp"
#include <fmt/core.h>
#include <iostream>
namespace lel {
%%{
machine Parser;
alphtype char;
action token {tk = input.substr(start - begin, fpc - start); }
action col {}
action ltab { grid.push_back(Row()); }
action valign { cur.bottom = fc == '.'; }
action id { id(input.substr(start - begin, fpc - start)); }
action row { cur.col = 0; cur.row++; }
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; }
action percent { cur.percent = true; }
col = "|" $col;
ltab = "[" $ltab;
rtab = "]" $row;
valign = ("^" | ".") $valign;
expand = "*" $expand;
center = "=" $center;
percent = "%" $percent;
halign = ("<" | ">") $align;
number = digit+ >{ start = fpc; } %token;
setw = ("(" number %setwidth ("," number %setheight)? ")") ;
modifiers = (percent | center | expand | valign | halign | setw);
id = modifiers* ((alpha | '_')+ :>> (alnum | '_')*) >{start = fpc;} %id;
row = space* ltab space* id space* (col space* id space*)* space* rtab space*;
main := row+;
}%%
%% write data;
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;
%% write init;
%% write exec;
bool good = pe - p == 0;
if(good) {
finalize();
} else {
fmt::println("error at");
std::cout << p;
}
return good;
}
}