public
Description: An implementation of markdown in C, using a PEG grammar
Clone URL: git://github.com/jgm/peg-markdown.git
Search Repo:
Added 'children' to Element struct; removed 'list' from Contents union.
jgm (author)
Wed May 07 12:51:04 -0700 2008
commit  dcbe375b31b8fe785d6171dda1dce302d3f89d9e
tree    582c1006ae57b37554286a3cc047acef6ef0fa67
parent  090bb095e356c47a15dde48cdd529d940a5aec73
...
143
144
145
146
 
147
148
149
150
151
 
152
153
154
155
 
156
157
158
159
160
161
 
162
163
164
165
166
167
 
168
169
170
171
172
173
 
174
175
176
...
195
196
197
198
 
199
200
201
...
204
205
206
207
 
208
209
210
211
212
...
324
325
326
327
 
328
329
330
331
332
 
333
334
335
336
 
337
338
339
340
341
342
...
341
342
343
344
 
345
346
347
348
349
 
350
351
352
 
353
354
355
356
 
357
358
359
360
...
370
371
372
373
 
374
375
376
377
378
 
379
380
381
382
383
384
385
386
...
480
481
482
483
 
484
485
486
487
488
489
 
490
491
492
493
494
 
495
496
497
498
499
500
501
 
502
503
504
505
506
507
 
508
509
510
511
512
513
514
 
515
516
517
...
533
534
535
536
 
537
538
539
...
542
543
544
545
 
546
547
548
...
143
144
145
 
146
147
148
149
150
 
151
152
153
154
 
155
156
157
158
159
160
 
161
162
163
164
165
166
 
167
168
169
170
171
172
 
173
174
175
176
...
195
196
197
 
198
199
200
201
...
204
205
206
 
207
208
209
210
211
212
...
324
325
326
 
327
328
329
330
331
 
332
333
334
335
 
336
337
338
339
340
341
342
...
341
342
343
 
344
345
346
347
348
 
349
350
351
 
352
353
354
355
 
356
357
358
359
360
...
370
371
372
 
373
374
375
376
377
 
378
379
380
381
382
383
384
385
386
...
480
481
482
 
483
484
485
486
487
488
 
489
490
491
492
493
 
494
495
496
497
498
499
500
 
501
502
503
504
505
506
 
507
508
509
510
511
512
513
 
514
515
516
517
...
533
534
535
 
536
537
538
539
...
542
543
544
 
545
546
547
548
0
@@ -143,34 +143,34 @@
0
         break;
0
     case EMPH:
0
         printf("<em>");
0
- print_html_element_list(elt.contents.list, obfuscate);
0
+ print_html_element_list(elt.children, obfuscate);
0
         printf("</em>");
0
         break;
0
     case STRONG:
0
         printf("<strong>");
0
- print_html_element_list(elt.contents.list, obfuscate);
0
+ print_html_element_list(elt.children, obfuscate);
0
         printf("</strong>");
0
         break;
0
     case LIST:
0
- print_html_element_list(elt.contents.list, obfuscate);
0
+ print_html_element_list(elt.children, obfuscate);
0
         break;
0
     case H1: case H2: case H3: case H4: case H5: case H6:
0
         lev = elt.key - H1 + 1; /* assumes H1 ... H6 are in order */
0
         pad(2);
0
         printf("<h%1d>", lev);
0
- print_html_element_list(elt.contents.list, obfuscate);
0
+ print_html_element_list(elt.children, obfuscate);
0
         printf("</h%1d>", lev);
0
         padded = 0;
0
         break;
0
     case PLAIN:
0
         pad(1);
0
- print_html_element_list(elt.contents.list, obfuscate);
0
+ print_html_element_list(elt.children, obfuscate);
0
         padded = 0;
0
         break;
0
     case PARA:
0
         pad(2);
0
         printf("<p>");
0
- print_html_element_list(elt.contents.list, obfuscate);
0
+ print_html_element_list(elt.children, obfuscate);
0
         printf("</p>");
0
         padded = 0;
0
         break;
0
@@ -195,7 +195,7 @@
0
         pad(2);
0
         printf("<ul>");
0
         padded = 0;
0
- print_html_element_list(elt.contents.list, obfuscate);
0
+ print_html_element_list(elt.children, obfuscate);
0
         pad(1);
0
         printf("</ul>");
0
         padded = 0;
0
@@ -204,7 +204,7 @@
0
         pad(2);
0
         printf("<ol>");
0
         padded = 0;
0
- print_html_element_list(elt.contents.list, obfuscate);
0
+ print_html_element_list(elt.children, obfuscate);
0
         pad(1);
0
         printf("</ol>");
0
         padded = 0;
0
0
0
@@ -324,16 +324,16 @@
0
         break;
0
     case EMPH:
0
         printf("\\emph{");
0
- print_latex_element_list(elt.contents.list);
0
+ print_latex_element_list(elt.children);
0
         printf("}");
0
         break;
0
     case STRONG:
0
         printf("\\textbf{");
0
- print_latex_element_list(elt.contents.list);
0
+ print_latex_element_list(elt.children);
0
         printf("}");
0
         break;
0
     case LIST:
0
- print_latex_element_list(elt.contents.list);
0
+ print_latex_element_list(elt.children);
0
         break;
0
     case H1: case H2: case H3:
0
         lev = elt.key - H1 + 1; /* assumes H1 ... H6 are in order */
0
0
0
0
@@ -341,19 +341,19 @@
0
         for (i = elt.key; i > H1; i--)
0
             printf("sub");
0
         printf("section{");
0
- print_latex_element_list(elt.contents.list);
0
+ print_latex_element_list(elt.children);
0
         printf("}\n\n");
0
         break;
0
     case H4: case H5: case H6:
0
         printf("\\noindent\\textbf{");
0
- print_latex_element_list(elt.contents.list);
0
+ print_latex_element_list(elt.children);
0
         printf("}\n");
0
     case PLAIN:
0
- print_latex_element_list(elt.contents.list);
0
+ print_latex_element_list(elt.children);
0
         printf("\n");
0
         break;
0
     case PARA:
0
- print_latex_element_list(elt.contents.list);
0
+ print_latex_element_list(elt.children);
0
         printf("\n\n");
0
         break;
0
     case HRULE:
0
0
@@ -370,12 +370,12 @@
0
     case BULLETLIST:
0
         printf("\\begin{itemize}\n");
0
         padded = 0;
0
- print_latex_element_list(elt.contents.list);
0
+ print_latex_element_list(elt.children);
0
         printf("\\end{itemize}\n\n");
0
         break;
0
     case ORDEREDLIST:
0
         printf("\\begin{enumerate}\n");
0
- print_latex_element_list(elt.contents.list);
0
+ print_latex_element_list(elt.children);
0
         printf("\\end{enumerate}\n\n");
0
         break;
0
     case LISTITEM:
0
0
0
0
0
0
@@ -480,38 +480,38 @@
0
         break;
0
     case EMPH:
0
         printf("\\fI");
0
- print_groff_mm_element_list(elt.contents.list);
0
+ print_groff_mm_element_list(elt.children);
0
         printf("\\fR");
0
         padded = 0;
0
         break;
0
     case STRONG:
0
         printf("\\fB");
0
- print_groff_mm_element_list(elt.contents.list);
0
+ print_groff_mm_element_list(elt.children);
0
         printf("\\fR");
0
         padded = 0;
0
         break;
0
     case LIST:
0
- print_groff_mm_element_list(elt.contents.list);
0
+ print_groff_mm_element_list(elt.children);
0
         padded = 0;
0
         break;
0
     case H1: case H2: case H3: case H4: case H5: case H6:
0
         lev = elt.key - H1 + 1;
0
         pad(1);
0
         printf(".H %d \"", lev);
0
- print_groff_mm_element_list(elt.contents.list);
0
+ print_groff_mm_element_list(elt.children);
0
         printf("\"");
0
         padded = 0;
0
         break;
0
     case PLAIN:
0
         pad(1);
0
- print_groff_mm_element_list(elt.contents.list);
0
+ print_groff_mm_element_list(elt.children);
0
         padded = 0;
0
         break;
0
     case PARA:
0
         pad(1);
0
         if (!in_list_item || count != 1)
0
             printf(".P\n");
0
- print_groff_mm_element_list(elt.contents.list);
0
+ print_groff_mm_element_list(elt.children);
0
         padded = 0;
0
         break;
0
     case HRULE:
0
@@ -533,7 +533,7 @@
0
         pad(1);
0
         printf(".BL");
0
         padded = 0;
0
- print_groff_mm_element_list(elt.contents.list);
0
+ print_groff_mm_element_list(elt.children);
0
         pad(1);
0
         printf(".LE 1");
0
         padded = 0;
0
@@ -542,7 +542,7 @@
0
         pad(1);
0
         printf(".AL");
0
         padded = 0;
0
- print_groff_mm_element_list(elt.contents.list);
0
+ print_groff_mm_element_list(elt.children);
0
         pad(1);
0
         printf(".LE 1");
0
         padded = 0;
...
40
41
42
43
 
44
45
46
47
...
107
108
109
110
 
111
112
113
114
115
116
 
117
118
119
...
146
147
148
149
 
150
151
152
...
259
260
261
262
 
263
264
265
266
...
270
271
272
273
 
274
275
276
 
277
278
279
280
...
304
305
306
307
 
308
309
310
 
311
312
313
...
315
316
317
318
 
319
320
321
322
...
341
342
343
344
 
345
346
347
348
 
349
350
351
...
354
355
356
357
 
358
359
360
361
362
363
364
...
611
612
613
614
615
 
 
616
617
618
 
619
620
621
622
623
624
625
626
 
 
627
628
629
630
 
631
632
633
634
635
 
636
637
638
...
660
661
662
663
 
664
665
666
...
685
686
687
688
 
689
690
691
...
737
738
739
740
 
741
742
743
...
40
41
42
 
43
44
45
46
47
...
107
108
109
 
110
111
112
113
114
115
 
116
117
118
119
...
146
147
148
 
149
150
151
152
...
259
260
261
 
262
263
264
265
266
...
270
271
272
 
273
274
275
 
276
277
278
279
280
...
304
305
306
 
307
308
309
 
310
311
312
313
...
315
316
317
 
318
319
320
321
322
...
341
342
343
 
344
345
346
347
 
348
349
350
351
...
354
355
356
 
357
358
359
360
361
362
363
364
...
611
612
613
 
 
614
615
616
617
 
618
619
620
621
622
623
624
 
 
625
626
627
628
629
 
630
631
632
633
634
 
635
636
637
638
...
660
661
662
 
663
664
665
666
...
685
686
687
 
688
689
690
691
...
737
738
739
 
740
741
742
743
0
@@ -40,7 +40,7 @@
0
 /* pushelt - push an element onto the (list) contents of an element */
0
 static void pushelt(element new, element *lst) {
0
     assert((*lst).key == LIST);
0
- (*lst).contents.list = cons(new, (*lst).contents.list);
0
+ (*lst).children = cons(new, (*lst).children);
0
 }
0
 
0
 /* reverse - reverse a list, returning pointer to new list */
0
0
@@ -107,13 +107,13 @@
0
     return result;
0
 }
0
 
0
-/* mk_list - constructs an element with key 'key' and contents 'lst' (reversed).
0
+/* mk_list - constructs an element with key 'key' and children from 'lst' (reversed).
0
  * This is designed to be used with pushelt to build lists in a parser action.
0
  * The reversing is necessary because pushelt adds to the head of a list. */
0
 static element mk_list(int key, element lst) {
0
     element result;
0
     result.key = key;
0
- result.contents.list = reverse(lst.contents.list);
0
+ result.children = reverse(lst.children);
0
     return result;
0
 }
0
 
0
@@ -146,7 +146,7 @@
0
         case EMPH:
0
         case STRONG:
0
         case LIST:
0
- if (match_inlines((*l1).contents.list, (*l2).contents.list))
0
+ if (match_inlines((*l1).children, (*l2).children))
0
                 break;
0
             else
0
                 return false;
0
@@ -259,7 +259,7 @@
0
 BlockQuoteLine = '>' ' '? Line
0
 
0
 BlockQuoteRaw = a:StartList ( b:BlockQuoteLine { pushelt(b, &a); } )+
0
- { char *c = concat_string_list(reverse(a.contents.list));
0
+ { char *c = concat_string_list(reverse(a.children));
0
                      strcat(c, "\n"); /* Note: an extra byte was allocated for this */
0
                      $$.contents.str = c;
0
                      $$.key = BLOCKQUOTE;
0
0
@@ -270,10 +270,10 @@
0
 VerbatimChunk = a:StartList
0
                 ( c:BlankLine { pushelt(c, &a); } )*
0
                 ( b:NonblankIndentedLine { pushelt(b, &a); } )+
0
- { $$ = mk_str(concat_string_list(reverse(a.contents.list))); }
0
+ { $$ = mk_str(concat_string_list(reverse(a.children))); }
0
 
0
 Verbatim = a:StartList ( b:VerbatimChunk { pushelt(b, &a); } )+
0
- { $$ = mk_str(concat_string_list(reverse(a.contents.list))); $$.key = VERBATIM; }
0
+ { $$ = mk_str(concat_string_list(reverse(a.children))); $$.key = VERBATIM; }
0
 
0
 HorizontalRule = NonindentSpace
0
                  ( '*' Sp '*' Sp '*' (Sp '*')*
0
0
@@ -304,10 +304,10 @@
0
                  a:StartList
0
                  b:BulletListBlock { pushelt(b, &a); }
0
                  ( c:BulletListContinuationBlock { pushelt(c, &a); } )*
0
- { $$ = mk_str(concat_string_list(reverse(a.contents.list))); $$.key = LISTITEM; }
0
+ { $$ = mk_str(concat_string_list(reverse(a.children))); $$.key = LISTITEM; }
0
 
0
 BulletListBlock = a:StartList b:Line { pushelt(b, &a); } (c:ListBlockLine { pushelt(c, &a); })*
0
- { $$ = mk_str(concat_string_list(reverse(a.contents.list))); }
0
+ { $$ = mk_str(concat_string_list(reverse(a.children))); }
0
 
0
 BulletListContinuationBlock = a:StartList
0
                               ( b:BlankLines
0
@@ -315,7 +315,7 @@
0
                                          b.contents.str = strdup("\001"); /* block separator */
0
                                      pushelt(b, &a); } )
0
                               ( Indent c:BulletListBlock { pushelt(c, &a); } )+
0
- { $$ = mk_str(concat_string_list(reverse(a.contents.list))); }
0
+ { $$ = mk_str(concat_string_list(reverse(a.children))); }
0
 
0
 Enumerator = NonindentSpace [0-9]+ '.' Spacechar+
0
 
0
0
@@ -341,11 +341,11 @@
0
                     a:StartList
0
                     b:OrderedListBlock { pushelt(b, &a); }
0
                     ( c:OrderedListContinuationBlock { pushelt(c, &a); } )*
0
- { $$ = mk_str(concat_string_list(reverse(a.contents.list))); $$.key = LISTITEM; }
0
+ { $$ = mk_str(concat_string_list(reverse(a.children))); $$.key = LISTITEM; }
0
 
0
 OrderedListBlock = a:StartList b:Line { pushelt(b, &a); }
0
                     ( c:ListBlockLine { pushelt(c, &a); } )*
0
- { $$ = mk_str(concat_string_list(reverse(a.contents.list))); }
0
+ { $$ = mk_str(concat_string_list(reverse(a.children))); }
0
 
0
 OrderedListContinuationBlock = a:StartList
0
                               ( b:BlankLines
0
@@ -354,7 +354,7 @@
0
                                      pushelt(b, &a);
0
                                 } )
0
                               ( Indent c:OrderedListBlock { pushelt(c, &a); } )+
0
- { $$ = mk_str(concat_string_list(reverse(a.contents.list))); }
0
+ { $$ = mk_str(concat_string_list(reverse(a.children))); }
0
 
0
 BlankLines = < BlankLine* >
0
                 { $$ = mk_str(yytext); }
0
0
0
0
0
@@ -611,28 +611,28 @@
0
 
0
 ReferenceLinkDouble = a:Label < Spnl > b:Label
0
                        { link match;
0
- if (find_reference(&match, b.contents.list))
0
- $$ = mk_link(a.contents.list, match.url, match.title);
0
+ if (find_reference(&match, b.children))
0
+ $$ = mk_link(a.children, match.url, match.title);
0
                            else {
0
                                /* $$.key == LIST; (not needed because $$.key set by Label match */
0
- $$.contents.list = cons(mk_str("["), cons(a, cons(mk_str("]"), cons(mk_str(yytext),
0
+ $$.children = cons(mk_str("["), cons(a, cons(mk_str("]"), cons(mk_str(yytext),
0
                                            cons(mk_str("["), cons(b, cons(mk_str("]"), NULL)))))));
0
                            }
0
                        }
0
 
0
 ReferenceLinkSingle = a:Label < (Spnl "[]")? >
0
                        { link match;
0
- if (find_reference(&match, a.contents.list)) {
0
- $$ = mk_link(a.contents.list, match.url, match.title);
0
+ if (find_reference(&match, a.children)) {
0
+ $$ = mk_link(a.children, match.url, match.title);
0
                            }
0
                            else {
0
                                $$.key = LIST;
0
- $$.contents.list = cons(mk_str("["), cons(a, cons(mk_str("]"),cons(mk_str(yytext),NULL))));
0
+ $$.children = cons(mk_str("["), cons(a, cons(mk_str("]"),cons(mk_str(yytext),NULL))));
0
                            }
0
                        }
0
 
0
 ExplicitLink = l:Label Spnl '(' Sp s:Source Spnl t:Title Sp ')'
0
- { $$ = mk_link(l.contents.list, s.contents.str, t.contents.str); }
0
+ { $$ = mk_link(l.children, s.contents.str, t.contents.str); }
0
 
0
 Source = ( '<' < SourceContents > '>' | < SourceContents > )
0
           { $$ = mk_str(yytext); }
0
@@ -660,7 +660,7 @@
0
                 }
0
 
0
 Reference = NonindentSpace l:Label ':' Spnl s:RefSrc Spnl t:RefTitle BlankLine*
0
- { $$ = mk_link(l.contents.list, s.contents.str, t.contents.str); $$.key = REFERENCE; }
0
+ { $$ = mk_link(l.children, s.contents.str, t.contents.str); $$.key = REFERENCE; }
0
 
0
 Label = '['
0
         a:StartList
0
@@ -685,7 +685,7 @@
0
 
0
 References = a:StartList
0
              ( b:Reference { pushelt(b, &a); } | SkipBlock )*
0
- { references = a.contents.list; }
0
+ { references = a.children; }
0
 
0
 Ticks1 = "`"
0
 Ticks2 = "``"
0
@@ -737,7 +737,7 @@
0
 
0
 # StartList starts a list data structure that can be added to with pushelt:
0
 StartList = &.
0
- { $$.key = LIST; $$.contents.list = NULL; }
0
+ { $$.key = LIST; $$.children = NULL; }
0
 
0
 Line = ( < (!'\r' !'\n' .)* Newline > | < .+ > Eof )
0
         { $$ = mk_str(yytext); }
...
20
21
22
23
24
25
26
...
51
52
53
54
55
56
 
 
 
 
57
58
59
...
20
21
22
 
23
24
25
...
50
51
52
 
 
 
53
54
55
56
57
58
59
0
@@ -20,7 +20,6 @@
0
 /* Union for contents of an Element (string, list, or link). */
0
 union Contents {
0
     char *str;
0
- struct Element *list;
0
     struct Link link;
0
 };
0
 
0
@@ -51,9 +50,10 @@
0
 
0
 /* Semantic value of a parsing action. */
0
 struct Element {
0
- int key;
0
- union Contents contents;
0
- struct Element *next;
0
+ int key;
0
+ union Contents contents;
0
+ struct Element *children;
0
+ struct Element *next;
0
 };
0
 
0
 typedef struct Element element;

Comments

    No one has commented yet.