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

87 lines
1.8 KiB

#include "lel.hpp"
#include <fmt/core.h>
%%{
machine LELParser;
alphtype char;
action token {tk = input.substr(start - begin, fpc - start); }
action col { col(); }
action ltab { ltab(); }
action valign { valign(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(); }
col = "|" $col;
ltab = "[" $ltab;
rtab = "]" $row;
valign = ("^" | ".") $valign;
expand = "*" $expand;
halign = ("<" | ">") $align;
number = digit+ >{ start = fpc; } %token;
setw = ("(" number %setwidth ("," number %setheight)? ")") ;
modifiers = (expand | valign | halign | setw);
id = modifiers* ((alpha | '_')+ :>> (alnum | '_')*) >{start = fpc;} %id;
row = space* ltab space* id space* (col space* id)* space* rtab space*;
main := row+;
}%%
%% write data;
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;
%% write init;
%% write exec;
bool good = pe - p == 0;
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");
}