After reading the manual some more I have a basic working parser, now to add the json metadata feature.

master
Zed A. Shaw 1 week ago
parent 664de68d9d
commit 081ecb9852
  1. 100
      md_parser.cpp
  2. 24
      md_parser.rl
  3. 4
      sample/01-a-good-first-program.md

@ -4,76 +4,94 @@
#include <iostream> #include <iostream>
#line 38 "md_parser.rl" #line 40 "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, 3, 1, 4, 2, 0, 1, 0, 1, 1, 1, 2, 1,
0, 1, 2, 0, 2, 2, 1, 0, 3, 1, 4, 1, 5, 1, 6, 2,
2, 2, 0, 2, 3, 5 1, 3, 2, 2, 3, 2, 3, 2,
2, 5, 0
}; };
static const char _Parser_key_offsets[] = { static const char _Parser_key_offsets[] = {
0, 0, 1, 2, 3, 4, 10, 11, 0, 0, 1, 2, 3, 4, 8, 10,
18, 22, 29, 31, 33, 34 14, 19, 24, 31, 36, 41, 48, 53,
55, 57, 62, 64, 65, 70, 75
}; };
static const char _Parser_trans_keys[] = { static const char _Parser_trans_keys[] = {
61, 61, 61, 10, 10, 32, 35, 42, 61, 61, 61, 10, 10, 35, 42, 45,
9, 13, 10, 10, 32, 35, 42, 45, 10, 45, 10, 35, 42, 45, 10, 32,
9, 13, 10, 32, 9, 13, 10, 32, 45, 9, 13, 10, 32, 45, 9, 13,
35, 42, 45, 9, 13, 10, 45, 10, 10, 32, 35, 42, 45, 9, 13, 10,
45, 10, 10, 32, 35, 42, 45, 9, 32, 45, 9, 13, 10, 32, 45, 9,
13, 0 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
}; };
static const char _Parser_single_lengths[] = { static const char _Parser_single_lengths[] = {
0, 1, 1, 1, 1, 4, 1, 5, 0, 1, 1, 1, 1, 4, 2, 4,
2, 5, 2, 2, 1, 5 3, 3, 5, 3, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 0, 0, 0, 1 1, 1, 1, 1, 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, 14, 16, 0, 0, 2, 4, 6, 8, 13, 16,
23, 27, 34, 37, 40, 42 21, 26, 31, 38, 43, 48, 55, 60,
63, 66, 71, 74, 76, 81, 86
}; };
static const char _Parser_indicies[] = { static const char _Parser_indicies[] = {
0, 1, 2, 1, 3, 1, 4, 1, 0, 1, 2, 1, 3, 1, 4, 1,
7, 6, 8, 9, 6, 5, 11, 10, 6, 7, 8, 9, 5, 11, 12, 10,
7, 6, 8, 9, 12, 6, 5, 13, 14, 15, 16, 17, 13, 19, 18, 12,
6, 6, 5, 7, 6, 14, 15, 12, 18, 10, 21, 20, 22, 20, 13, 23,
6, 5, 11, 16, 10, 11, 17, 10, 20, 15, 24, 25, 20, 13, 27, 26,
18, 10, 7, 6, 8, 9, 12, 6, 12, 26, 10, 29, 28, 22, 28, 13,
5, 0 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
}; };
static const char _Parser_trans_targs[] = { static const char _Parser_trans_targs[] = {
2, 0, 3, 4, 5, 6, 8, 9, 2, 0, 3, 4, 5, 6, 7, 8,
8, 8, 6, 7, 10, 9, 8, 8, 14, 20, 6, 7, 15, 6, 7, 8,
11, 12, 13 14, 17, 9, 10, 9, 10, 15, 10,
11, 21, 12, 13, 12, 13, 13, 13,
16, 18, 19, 22
}; };
static const char _Parser_trans_actions[] = { static const char _Parser_trans_actions[] = {
0, 0, 0, 0, 5, 1, 1, 0, 0, 0, 0, 0, 9, 24, 11, 24,
13, 16, 0, 3, 1, 3, 7, 10, 24, 24, 0, 7, 0, 1, 0, 1,
0, 0, 19 1, 1, 3, 15, 1, 7, 1, 0,
1, 1, 5, 21, 1, 7, 0, 18,
0, 0, 0, 13
}; };
static const int Parser_start = 1; static const int Parser_start = 1;
static const int Parser_first_final = 13; static const int Parser_first_final = 22;
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 41 "md_parser.rl" #line 43 "md_parser.rl"
bool Parser::parse(const std::string& input) { bool Parser::parse(const std::string& input) {
@ -86,14 +104,14 @@ bool Parser::parse(const std::string& input) {
std::string tk; std::string tk;
#line 81 "md_parser.cpp" #line 99 "md_parser.cpp"
{ {
cs = Parser_start; cs = Parser_start;
} }
#line 53 "md_parser.rl" #line 55 "md_parser.rl"
#line 84 "md_parser.cpp" #line 102 "md_parser.cpp"
{ {
int _klen; int _klen;
unsigned int _trans; unsigned int _trans;
@ -191,10 +209,14 @@ _match:
{ fmt::println("----- START"); } { fmt::println("----- START"); }
break; break;
case 5: case 5:
#line 20 "md_parser.rl" #line 21 "md_parser.rl"
{ fmt::println("END"); } { fmt::println(">> START SLIDE"); }
break; break;
#line 178 "md_parser.cpp" case 6:
#line 22 "md_parser.rl"
{ fmt::println("<< END SLIDE"); }
break;
#line 199 "md_parser.cpp"
} }
} }
@ -207,7 +229,7 @@ _again:
_out: {} _out: {}
} }
#line 54 "md_parser.rl" #line 56 "md_parser.rl"
bool good = pe - p == 0; bool good = pe - p == 0;

@ -17,24 +17,26 @@
std::cout << "CONTENT:" << std::quoted(tk) << '\n'; std::cout << "CONTENT:" << std::quoted(tk) << '\n';
} }
action start { fmt::println("----- START"); } action start { fmt::println("----- START"); }
action end { fmt::println("END"); }
action plain { fmt::println("PLAIN"); } action plain { fmt::println("PLAIN"); }
action start_slide { fmt::println(">> START SLIDE"); }
action end_slide { fmt::println("<< END SLIDE"); }
eol = "\n"; eol = '\n';
start = "===" eol $start; start = '===' %start;
end = "---" eol $end; end = '---' %end_slide;
pound = "#" $title; pound = '#' %title;
asterisk = "*" $enum; asterisk = '*' %enum;
dash = '-' %enum;
content = (any+ -- (eol|end)) >mark %content; content = (any+ -- (eol|end)) >mark %content;
title = pound space* content eol; title = pound space+ content eol;
enum = asterisk space* content eol; enum = (asterisk | dash) space+ content eol;
line = space* content eol; line = content :>> eol;
blank = space* eol; blank = space* eol;
slide = (title | enum | line | blank)+ end; slide = (title | enum | line | blank)+ >start_slide end eol;
main := start (slide)+; main := start eol (slide)+;
}%% }%%
%% write data; %% write data;

@ -14,8 +14,8 @@ Besos would be proud.
--- ---
# Common Student Questions # Common Student Questions
* This again. - This again.
* That too. - That too.
--- ---
# The Blue Plus # The Blue Plus

Loading…
Cancel
Save