Can now handle meta data json at the start but not on each slide. Coming soon.

master
Zed A. Shaw 2 days ago
parent 081ecb9852
commit 0691632f05
  1. 125
      md_parser.cpp
  2. 9
      md_parser.rl
  3. 5
      sample/01-a-good-first-program.md

@ -4,94 +4,100 @@
#include <iostream> #include <iostream>
#line 40 "md_parser.rl" #line 45 "md_parser.rl"
#line 7 "md_parser.cpp" #line 7 "md_parser.cpp"
static const char _Parser_actions[] = { static const char _Parser_actions[] = {
0, 1, 0, 1, 1, 1, 2, 1, 0, 1, 0, 1, 1, 1, 2, 1,
3, 1, 4, 1, 5, 1, 6, 2, 3, 1, 4, 1, 5, 1, 6, 1,
1, 3, 2, 2, 3, 2, 3, 2, 7, 2, 1, 3, 2, 2, 3, 2,
2, 5, 0 3, 2, 2, 6, 0
}; };
static const char _Parser_key_offsets[] = { static const char _Parser_key_offsets[] = {
0, 0, 1, 2, 3, 4, 8, 10, 0, 0, 1, 1, 2, 3, 4, 5,
14, 19, 24, 31, 36, 41, 48, 53, 6, 7, 11, 13, 17, 22, 27, 34,
55, 57, 62, 64, 65, 70, 75 39, 44, 51, 56, 58, 60, 65, 67,
68, 73, 78
}; };
static const char _Parser_trans_keys[] = { static const char _Parser_trans_keys[] = {
61, 61, 61, 10, 10, 35, 42, 45, 123, 125, 10, 61, 61, 61, 10, 10,
10, 45, 10, 35, 42, 45, 10, 32, 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, 45, 9, 13, 10, 32, 45, 9, 13,
10, 32, 35, 42, 45, 9, 13, 10, 10, 45, 10, 45, 10, 32, 45, 9,
32, 45, 9, 13, 10, 32, 45, 9, 13, 10, 45, 10, 10, 32, 45, 9,
13, 10, 32, 35, 42, 45, 9, 13, 13, 10, 32, 45, 9, 13, 10, 35,
10, 32, 45, 9, 13, 10, 45, 10, 42, 45, 0
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[] = { static const char _Parser_single_lengths[] = {
0, 1, 1, 1, 1, 4, 2, 4, 0, 1, 0, 1, 1, 1, 1, 1,
3, 3, 5, 3, 3, 5, 3, 2, 1, 4, 2, 4, 3, 3, 5, 3,
2, 3, 2, 1, 3, 3, 4 3, 5, 3, 2, 2, 3, 2, 1,
3, 3, 4
}; };
static const char _Parser_range_lengths[] = { static const char _Parser_range_lengths[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1,
0, 1, 0, 0, 1, 1, 0 1, 1, 1, 0, 0, 1, 0, 0,
1, 1, 0
}; };
static const char _Parser_index_offsets[] = { static const char _Parser_index_offsets[] = {
0, 0, 2, 4, 6, 8, 13, 16, 0, 0, 2, 3, 5, 7, 9, 11,
21, 26, 31, 38, 43, 48, 55, 60, 13, 15, 20, 23, 28, 33, 38, 45,
63, 66, 71, 74, 76, 81, 86 50, 55, 62, 67, 70, 73, 78, 81,
83, 88, 93
}; };
static const char _Parser_indicies[] = { static const char _Parser_indicies[] = {
0, 1, 2, 1, 3, 1, 4, 1, 0, 1, 2, 3, 2, 4, 1, 5,
6, 7, 8, 9, 5, 11, 12, 10, 1, 6, 1, 7, 1, 8, 1, 10,
14, 15, 16, 17, 13, 19, 18, 12, 11, 12, 13, 9, 15, 16, 14, 18,
18, 10, 21, 20, 22, 20, 13, 23, 19, 20, 21, 17, 23, 22, 16, 22,
20, 15, 24, 25, 20, 13, 27, 26, 14, 25, 24, 26, 24, 17, 27, 24,
12, 26, 10, 29, 28, 22, 28, 13, 19, 28, 29, 24, 17, 31, 30, 16,
30, 28, 15, 16, 17, 28, 13, 31, 30, 14, 33, 32, 26, 32, 17, 34,
26, 12, 26, 10, 11, 32, 10, 11, 32, 19, 20, 21, 32, 17, 35, 30,
1, 10, 31, 26, 33, 26, 10, 11, 16, 30, 14, 15, 36, 14, 15, 1,
34, 10, 35, 1, 31, 26, 32, 26, 14, 35, 30, 37, 30, 14, 15, 38,
10, 27, 26, 33, 26, 10, 6, 7, 14, 39, 1, 35, 30, 36, 30, 14,
8, 9, 5, 0 31, 30, 37, 30, 14, 10, 11, 12,
13, 9, 0
}; };
static const char _Parser_trans_targs[] = { static const char _Parser_trans_targs[] = {
2, 0, 3, 4, 5, 6, 7, 8, 2, 0, 3, 4, 5, 6, 7, 8,
14, 20, 6, 7, 15, 6, 7, 8, 9, 10, 11, 12, 18, 24, 10, 11,
14, 17, 9, 10, 9, 10, 15, 10, 19, 10, 11, 12, 18, 21, 13, 14,
11, 21, 12, 13, 12, 13, 13, 13, 13, 14, 19, 14, 15, 25, 16, 17,
16, 18, 19, 22 16, 17, 17, 17, 20, 22, 23, 26
}; };
static const char _Parser_trans_actions[] = { static const char _Parser_trans_actions[] = {
0, 0, 0, 0, 9, 24, 11, 24, 1, 0, 0, 0, 9, 0, 0, 0,
24, 24, 0, 7, 0, 1, 0, 1, 11, 26, 13, 26, 26, 26, 0, 7,
1, 1, 3, 15, 1, 7, 1, 0, 0, 1, 0, 1, 1, 1, 3, 17,
1, 1, 5, 21, 1, 7, 0, 18, 1, 7, 1, 0, 1, 1, 5, 23,
0, 0, 0, 13 1, 7, 0, 20, 0, 0, 0, 15
}; };
static const int Parser_start = 1; 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_error = 0;
static const int Parser_en_main = 1; static const int Parser_en_main = 1;
#line 43 "md_parser.rl" #line 48 "md_parser.rl"
bool Parser::parse(const std::string& input) { bool Parser::parse(const std::string& input) {
@ -104,14 +110,14 @@ bool Parser::parse(const std::string& input) {
std::string tk; std::string tk;
#line 99 "md_parser.cpp" #line 105 "md_parser.cpp"
{ {
cs = Parser_start; 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; int _klen;
unsigned int _trans; unsigned int _trans;
@ -206,17 +212,24 @@ _match:
break; break;
case 4: case 4:
#line 19 "md_parser.rl" #line 19 "md_parser.rl"
{ fmt::println("----- START"); } {
tk = input.substr(start - begin, p - start);
std::cout << "META:" << std::quoted(tk) << '\n';
}
break; break;
case 5: case 5:
#line 21 "md_parser.rl" #line 23 "md_parser.rl"
{ fmt::println(">> START SLIDE"); } { fmt::println("----- START"); }
break; break;
case 6: 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"); } { fmt::println("<< END SLIDE"); }
break; break;
#line 199 "md_parser.cpp" #line 211 "md_parser.cpp"
} }
} }
@ -229,7 +242,7 @@ _again:
_out: {} _out: {}
} }
#line 56 "md_parser.rl" #line 61 "md_parser.rl"
bool good = pe - p == 0; bool good = pe - p == 0;

@ -16,6 +16,10 @@
tk = input.substr(start - begin, fpc - start); tk = input.substr(start - begin, fpc - start);
std::cout << "CONTENT:" << std::quoted(tk) << '\n'; 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 start { fmt::println("----- START"); }
action plain { fmt::println("PLAIN"); } action plain { fmt::println("PLAIN"); }
action start_slide { fmt::println(">> START SLIDE"); } action start_slide { fmt::println(">> START SLIDE"); }
@ -27,8 +31,9 @@
pound = '#' %title; pound = '#' %title;
asterisk = '*' %enum; asterisk = '*' %enum;
dash = '-' %enum; dash = '-' %enum;
content = (any+ -- (eol|end)) >mark %content;
meta = ('{' ( any+) :>> '}') >mark %meta;
content = (any+ -- (eol|end)) >mark %content;
title = pound space+ content eol; title = pound space+ content eol;
enum = (asterisk | dash) space+ content eol; enum = (asterisk | dash) space+ content eol;
line = content :>> eol; line = content :>> eol;
@ -36,7 +41,7 @@
slide = (title | enum | line | blank)+ >start_slide end eol; slide = (title | enum | line | blank)+ >start_slide end eol;
main := start eol (slide)+; main := meta eol start eol (slide)+;
}%% }%%
%% write data; %% write data;

@ -1,9 +1,14 @@
{
"title": "Test",
"description": "Test"
}
=== ===
# 1: A Good First Program # 1: A Good First Program
* The key is this * The key is this
* That's what we want * That's what we want
--- ---
{"bg_color": [255, 0, 0, 255]}
# What You Should See # What You Should See
Yes, but with more feeling. Yes, but with more feeling.

Loading…
Cancel
Save