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.
64 lines
1.4 KiB
64 lines
1.4 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 { 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;
|
|
}
|
|
|
|
}
|
|
|