From 0691632f052e560810bc707437e0d63b46e26ace Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 16 Aug 2025 23:01:45 -0400 Subject: [PATCH] Can now handle meta data json at the start but not on each slide. Coming soon. --- md_parser.cpp | 125 +++++++++++++++++------------- md_parser.rl | 9 ++- sample/01-a-good-first-program.md | 5 ++ 3 files changed, 81 insertions(+), 58 deletions(-) diff --git a/md_parser.cpp b/md_parser.cpp index d3655f0..2fbde8d 100644 --- a/md_parser.cpp +++ b/md_parser.cpp @@ -4,94 +4,100 @@ #include -#line 40 "md_parser.rl" +#line 45 "md_parser.rl" #line 7 "md_parser.cpp" static const char _Parser_actions[] = { 0, 1, 0, 1, 1, 1, 2, 1, - 3, 1, 4, 1, 5, 1, 6, 2, - 1, 3, 2, 2, 3, 2, 3, 2, - 2, 5, 0 + 3, 1, 4, 1, 5, 1, 6, 1, + 7, 2, 1, 3, 2, 2, 3, 2, + 3, 2, 2, 6, 0 }; static const char _Parser_key_offsets[] = { - 0, 0, 1, 2, 3, 4, 8, 10, - 14, 19, 24, 31, 36, 41, 48, 53, - 55, 57, 62, 64, 65, 70, 75 + 0, 0, 1, 1, 2, 3, 4, 5, + 6, 7, 11, 13, 17, 22, 27, 34, + 39, 44, 51, 56, 58, 60, 65, 67, + 68, 73, 78 }; static const char _Parser_trans_keys[] = { - 61, 61, 61, 10, 10, 35, 42, 45, - 10, 45, 10, 35, 42, 45, 10, 32, + 123, 125, 10, 61, 61, 61, 10, 10, + 35, 42, 45, 10, 45, 10, 35, 42, + 45, 10, 32, 45, 9, 13, 10, 32, + 45, 9, 13, 10, 32, 35, 42, 45, + 9, 13, 10, 32, 45, 9, 13, 10, + 32, 45, 9, 13, 10, 32, 35, 42, 45, 9, 13, 10, 32, 45, 9, 13, - 10, 32, 35, 42, 45, 9, 13, 10, - 32, 45, 9, 13, 10, 32, 45, 9, - 13, 10, 32, 35, 42, 45, 9, 13, - 10, 32, 45, 9, 13, 10, 45, 10, - 45, 10, 32, 45, 9, 13, 10, 45, - 10, 10, 32, 45, 9, 13, 10, 32, - 45, 9, 13, 10, 35, 42, 45, 0 + 10, 45, 10, 45, 10, 32, 45, 9, + 13, 10, 45, 10, 10, 32, 45, 9, + 13, 10, 32, 45, 9, 13, 10, 35, + 42, 45, 0 }; static const char _Parser_single_lengths[] = { - 0, 1, 1, 1, 1, 4, 2, 4, - 3, 3, 5, 3, 3, 5, 3, 2, - 2, 3, 2, 1, 3, 3, 4 + 0, 1, 0, 1, 1, 1, 1, 1, + 1, 4, 2, 4, 3, 3, 5, 3, + 3, 5, 3, 2, 2, 3, 2, 1, + 3, 3, 4 }; static const char _Parser_range_lengths[] = { 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 0, - 0, 1, 0, 0, 1, 1, 0 + 0, 0, 0, 0, 1, 1, 1, 1, + 1, 1, 1, 0, 0, 1, 0, 0, + 1, 1, 0 }; static const char _Parser_index_offsets[] = { - 0, 0, 2, 4, 6, 8, 13, 16, - 21, 26, 31, 38, 43, 48, 55, 60, - 63, 66, 71, 74, 76, 81, 86 + 0, 0, 2, 3, 5, 7, 9, 11, + 13, 15, 20, 23, 28, 33, 38, 45, + 50, 55, 62, 67, 70, 73, 78, 81, + 83, 88, 93 }; static const char _Parser_indicies[] = { - 0, 1, 2, 1, 3, 1, 4, 1, - 6, 7, 8, 9, 5, 11, 12, 10, - 14, 15, 16, 17, 13, 19, 18, 12, - 18, 10, 21, 20, 22, 20, 13, 23, - 20, 15, 24, 25, 20, 13, 27, 26, - 12, 26, 10, 29, 28, 22, 28, 13, - 30, 28, 15, 16, 17, 28, 13, 31, - 26, 12, 26, 10, 11, 32, 10, 11, - 1, 10, 31, 26, 33, 26, 10, 11, - 34, 10, 35, 1, 31, 26, 32, 26, - 10, 27, 26, 33, 26, 10, 6, 7, - 8, 9, 5, 0 + 0, 1, 2, 3, 2, 4, 1, 5, + 1, 6, 1, 7, 1, 8, 1, 10, + 11, 12, 13, 9, 15, 16, 14, 18, + 19, 20, 21, 17, 23, 22, 16, 22, + 14, 25, 24, 26, 24, 17, 27, 24, + 19, 28, 29, 24, 17, 31, 30, 16, + 30, 14, 33, 32, 26, 32, 17, 34, + 32, 19, 20, 21, 32, 17, 35, 30, + 16, 30, 14, 15, 36, 14, 15, 1, + 14, 35, 30, 37, 30, 14, 15, 38, + 14, 39, 1, 35, 30, 36, 30, 14, + 31, 30, 37, 30, 14, 10, 11, 12, + 13, 9, 0 }; static const char _Parser_trans_targs[] = { 2, 0, 3, 4, 5, 6, 7, 8, - 14, 20, 6, 7, 15, 6, 7, 8, - 14, 17, 9, 10, 9, 10, 15, 10, - 11, 21, 12, 13, 12, 13, 13, 13, - 16, 18, 19, 22 + 9, 10, 11, 12, 18, 24, 10, 11, + 19, 10, 11, 12, 18, 21, 13, 14, + 13, 14, 19, 14, 15, 25, 16, 17, + 16, 17, 17, 17, 20, 22, 23, 26 }; static const char _Parser_trans_actions[] = { - 0, 0, 0, 0, 9, 24, 11, 24, - 24, 24, 0, 7, 0, 1, 0, 1, - 1, 1, 3, 15, 1, 7, 1, 0, - 1, 1, 5, 21, 1, 7, 0, 18, - 0, 0, 0, 13 + 1, 0, 0, 0, 9, 0, 0, 0, + 11, 26, 13, 26, 26, 26, 0, 7, + 0, 1, 0, 1, 1, 1, 3, 17, + 1, 7, 1, 0, 1, 1, 5, 23, + 1, 7, 0, 20, 0, 0, 0, 15 }; static const int Parser_start = 1; -static const int Parser_first_final = 22; +static const int Parser_first_final = 26; static const int Parser_error = 0; static const int Parser_en_main = 1; -#line 43 "md_parser.rl" +#line 48 "md_parser.rl" bool Parser::parse(const std::string& input) { @@ -104,14 +110,14 @@ bool Parser::parse(const std::string& input) { std::string tk; -#line 99 "md_parser.cpp" +#line 105 "md_parser.cpp" { cs = Parser_start; } -#line 55 "md_parser.rl" +#line 60 "md_parser.rl" -#line 102 "md_parser.cpp" +#line 108 "md_parser.cpp" { int _klen; unsigned int _trans; @@ -206,17 +212,24 @@ _match: break; case 4: #line 19 "md_parser.rl" - { fmt::println("----- START"); } + { + tk = input.substr(start - begin, p - start); + std::cout << "META:" << std::quoted(tk) << '\n'; + } break; case 5: -#line 21 "md_parser.rl" - { fmt::println(">> START SLIDE"); } +#line 23 "md_parser.rl" + { fmt::println("----- START"); } break; case 6: -#line 22 "md_parser.rl" +#line 25 "md_parser.rl" + { fmt::println(">> START SLIDE"); } + break; + case 7: +#line 26 "md_parser.rl" { fmt::println("<< END SLIDE"); } break; -#line 199 "md_parser.cpp" +#line 211 "md_parser.cpp" } } @@ -229,7 +242,7 @@ _again: _out: {} } -#line 56 "md_parser.rl" +#line 61 "md_parser.rl" bool good = pe - p == 0; diff --git a/md_parser.rl b/md_parser.rl index 325d1d7..820367e 100644 --- a/md_parser.rl +++ b/md_parser.rl @@ -16,6 +16,10 @@ tk = input.substr(start - begin, fpc - start); std::cout << "CONTENT:" << std::quoted(tk) << '\n'; } + action meta { + tk = input.substr(start - begin, fpc - start); + std::cout << "META:" << std::quoted(tk) << '\n'; + } action start { fmt::println("----- START"); } action plain { fmt::println("PLAIN"); } action start_slide { fmt::println(">> START SLIDE"); } @@ -27,8 +31,9 @@ pound = '#' %title; asterisk = '*' %enum; dash = '-' %enum; - content = (any+ -- (eol|end)) >mark %content; + meta = ('{' ( any+) :>> '}') >mark %meta; + content = (any+ -- (eol|end)) >mark %content; title = pound space+ content eol; enum = (asterisk | dash) space+ content eol; line = content :>> eol; @@ -36,7 +41,7 @@ slide = (title | enum | line | blank)+ >start_slide end eol; - main := start eol (slide)+; + main := meta eol start eol (slide)+; }%% %% write data; diff --git a/sample/01-a-good-first-program.md b/sample/01-a-good-first-program.md index 699a575..95a4036 100644 --- a/sample/01-a-good-first-program.md +++ b/sample/01-a-good-first-program.md @@ -1,9 +1,14 @@ +{ + "title": "Test", + "description": "Test" +} === # 1: A Good First Program * The key is this * That's what we want --- +{"bg_color": [255, 0, 0, 255]} # What You Should See Yes, but with more feeling.