If Amazon used this Besos wouldn't have banned PowerPoint.
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.
 
 
 
 
 
 
besos-loves-slides/md_parser.rl

65 lines
1.4 KiB

#include <fmt/core.h>
#include <iostream>
%%{
machine Parser;
alphtype char;
action token {
tk = input.substr(start - begin, fpc - start);
std::cout << "TOKEN: " << std::quoted(tk) << '\n';
}
action mark { start = fpc; }
action title { fmt::println("TITLE"); }
action enum { fmt::println("ENUM"); }
action content {
tk = input.substr(start - begin, fpc - start);
std::cout << "CONTENT:" << std::quoted(tk) << '\n';
}
action start { fmt::println("----- START"); }
action end { fmt::println("END"); }
action plain { fmt::println("PLAIN"); }
eol = "\n";
start = "===" eol $start;
end = "---" eol $end;
pound = "#" $title;
asterisk = "*" $enum;
content = (any+ -- (eol|end)) >mark %content;
title = pound space* content eol;
enum = asterisk space* content eol;
line = space* content eol;
blank = space* eol;
slide = (title | enum | line | blank)+ end;
main := start (slide)+;
}%%
%% write data;
bool Parser::parse(const 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();
const char *eof = p + input.size(); (void)eof;
std::string tk;
%% write init;
%% write exec;
bool good = pe - p == 0;
if(good) {
finalize();
} else {
error = true;
std::cout << "!!!!!!!!!!!!!!!!!!!!!! error at:";
std::cout << p;
}
return good;
}