#include "lel.hpp" #include #include namespace lel { %%{ machine Parser; 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(); } action center { center(); } col = "|" $col; ltab = "[" $ltab; rtab = "]" $row; valign = ("^" | ".") $valign; expand = "*" $expand; center = "=" $center; halign = ("<" | ">") $align; number = digit+ >{ start = fpc; } %token; setw = ("(" number %setwidth ("," number %setheight)? ")") ; modifiers = (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; } }