#include "lel.hpp" #include %%{ 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"); }