Initial cut of the lel parser mostly working but none of the basic alignment properties work.

This commit is contained in:
Zed A. Shaw 2025-02-14 15:40:15 -05:00
parent e7e0df6b70
commit 846b7aaf16
7 changed files with 492 additions and 354 deletions

53
lel_parser.rl Normal file
View file

@ -0,0 +1,53 @@
#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) {
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;
finalize();
return good;
}