public
Description: An implementation of markdown in C, using a PEG grammar
Clone URL: git://github.com/jgm/peg-markdown.git
Search Repo:
Simplified some grammar definitions.
jgm (author)
Fri May 09 09:49:59 -0700 2008
commit  0670aafd649d8e61b46e65e23a3b9dcee49c6e66
tree    4267baeda05b4520ed9041ca9fe82b9ba75c1705
parent  3fff272c9928551a50f1171155df761616aff0f6
...
213
214
215
216
 
217
218
219
220
221
222
...
239
240
241
242
 
243
244
245
246
247
248
249
 
250
251
252
 
253
254
255
256
257
258
259
260
261
 
262
263
264
265
...
268
269
270
271
272
 
 
273
274
275
 
276
277
278
...
286
287
288
289
 
290
291
292
293
294
...
302
303
304
305
306
 
 
307
308
309
 
310
311
312
313
314
315
316
317
 
 
 
 
 
318
319
320
...
322
323
324
325
 
326
327
328
329
330
331
...
339
340
341
342
343
 
 
344
345
346
347
 
 
348
349
350
351
352
353
354
 
 
 
 
355
356
 
357
358
359
...
519
520
521
522
 
523
524
525
...
568
569
570
571
 
572
573
574
...
577
578
579
580
 
581
582
583
...
588
589
590
591
 
592
593
594
...
596
597
598
599
 
600
601
602
603
...
664
665
666
667
 
668
669
670
671
672
673
674
...
213
214
215
 
216
217
218
219
220
221
222
...
239
240
241
 
242
243
244
245
246
 
 
 
247
248
249
 
250
251
252
253
254
255
256
 
 
 
257
258
259
260
261
...
264
265
266
 
 
267
268
269
270
 
271
272
273
274
...
282
283
284
 
285
286
287
288
289
290
...
298
299
300
 
 
301
302
303
304
 
305
306
307
308
 
 
 
 
 
309
310
311
312
313
314
315
316
...
318
319
320
 
321
322
323
324
325
326
327
...
335
336
337
 
 
338
339
340
341
 
 
342
343
344
345
346
 
 
 
 
347
348
349
350
351
 
352
353
354
355
...
515
516
517
 
518
519
520
521
...
564
565
566
 
567
568
569
570
...
573
574
575
 
576
577
578
579
...
584
585
586
 
587
588
589
590
...
592
593
594
 
595
596
597
598
599
...
660
661
662
 
663
664
665
 
 
666
667
668
0
@@ -213,7 +213,7 @@
0
 Doc = a:Blocks BlankLine* Eof
0
             { parse_result = a; }
0
 
0
-Blocks = a:StartList ( b:Block { pushelt(b, &a); } )*
0
+Blocks = a:StartList ( Block { pushelt($$, &a); } )*
0
             { $$ = mk_list(LIST, a); }
0
 
0
 Block = BlankLine*
0
0
0
0
@@ -239,26 +239,22 @@
0
 AtxStart = < ( "######" | "#####" | "####" | "###" | "##" | "#" ) >
0
             { $$.key = H1 + (strlen(yytext) - 1); }
0
  
0
-AtxHeading = s:AtxStart Sp a:StartList ( b:AtxInline { pushelt(b, &a); } )+ (Sp '#'* Sp)? Newline
0
+AtxHeading = s:AtxStart Sp a:StartList ( AtxInline { pushelt($$, &a); } )+ (Sp '#'* Sp)? Newline
0
             { $$ = mk_list(s.key, a); }
0
 
0
 SetextHeading = SetextHeading1 | SetextHeading2
0
 
0
-SetextHeadingInline = !Endline Inline
0
-
0
-SetextHeading1 = a:StartList ( b:SetextHeadingInline { pushelt(b, &a); } )+ Newline "===" '='* Newline
0
+SetextHeading1 = a:StartList ( !Endline Inline { pushelt($$, &a); } )+ Newline "===" '='* Newline
0
                   { $$ = mk_list(H1, a); }
0
 
0
-SetextHeading2 = a:StartList ( b:SetextHeadingInline { pushelt(b, &a) ; } )+ Newline "---" '-'* Newline
0
+SetextHeading2 = a:StartList ( !Endline Inline { pushelt($$, &a) ; } )+ Newline "---" '-'* Newline
0
                   { $$ = mk_list(H2, a); }
0
 
0
 Heading = AtxHeading | SetextHeading
0
 
0
 BlockQuote = BlockQuoteRaw
0
 
0
-BlockQuoteLine = '>' ' '? Line
0
-
0
-BlockQuoteRaw = a:StartList ( b:BlockQuoteLine { pushelt(b, &a); } )+
0
+BlockQuoteRaw = a:StartList ( '>' ' '? Line { pushelt($$, &a); } )+
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
0
@@ -268,11 +264,11 @@
0
 NonblankIndentedLine = !BlankLine IndentedLine
0
 
0
 VerbatimChunk = a:StartList
0
- ( c:BlankLine { pushelt(c, &a); } )*
0
- ( b:NonblankIndentedLine { pushelt(b, &a); } )+
0
+ ( BlankLine { pushelt($$, &a); } )*
0
+ ( NonblankIndentedLine { pushelt($$, &a); } )+
0
                 { $$ = mk_str(concat_string_list(reverse(a.children))); }
0
 
0
-Verbatim = a:StartList ( b:VerbatimChunk { pushelt(b, &a); } )+
0
+Verbatim = a:StartList ( VerbatimChunk { pushelt($$, &a); } )+
0
                { $$ = mk_str(concat_string_list(reverse(a.children))); $$.key = VERBATIM; }
0
 
0
 HorizontalRule = NonindentSpace
0
@@ -286,7 +282,7 @@
0
 
0
 BulletList = BulletListTight | BulletListLoose
0
 
0
-BulletListTight = a:StartList ( b:BulletListItem { pushelt(b, &a); } )+ BlankLine* !BulletListLoose
0
+BulletListTight = a:StartList ( BulletListItem { pushelt($$, &a); } )+ BlankLine* !BulletListLoose
0
                   { $$ = mk_list(BULLETLIST, a); }
0
 
0
 BulletListLoose = a:StartList
0
0
0
@@ -302,19 +298,19 @@
0
 
0
 BulletListItem = !HorizontalRule Bullet
0
                  a:StartList
0
- b:BulletListBlock { pushelt(b, &a); }
0
- ( c:BulletListContinuationBlock { pushelt(c, &a); } )*
0
+ BulletListBlock { pushelt($$, &a); }
0
+ ( BulletListContinuationBlock { pushelt($$, &a); } )*
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
+BulletListBlock = a:StartList Line { pushelt($$, &a); } (ListBlockLine { pushelt($$, &a); })*
0
                   { $$ = mk_str(concat_string_list(reverse(a.children))); }
0
 
0
 BulletListContinuationBlock = a:StartList
0
- ( b:BlankLines
0
- { if (strlen(b.contents.str) == 0)
0
- b.contents.str = strdup("\001"); /* block separator */
0
- pushelt(b, &a); } )
0
- ( Indent c:BulletListBlock { pushelt(c, &a); } )+
0
+ ( BlankLines
0
+ { if (strlen($$.contents.str) == 0)
0
+ $$.contents.str = strdup("\001"); /* block separator */
0
+ pushelt($$, &a); } )
0
+ ( Indent BulletListBlock { pushelt($$, &a); } )+
0
                               { $$ = mk_str(concat_string_list(reverse(a.children))); }
0
 
0
 Enumerator = NonindentSpace [0-9]+ '.' Spacechar+
0
@@ -322,7 +318,7 @@
0
 OrderedList = OrderedListTight | OrderedListLoose
0
 
0
 OrderedListTight = a:StartList
0
- ( b:OrderedListItem { pushelt(b, &a); } )+
0
+ ( OrderedListItem { pushelt($$, &a); } )+
0
                    BlankLine* !OrderedListLoose
0
                    { $$ = mk_list(ORDEREDLIST, a); }
0
 
0
0
0
0
@@ -339,21 +335,21 @@
0
 
0
 OrderedListItem = !HorizontalRule Enumerator
0
                     a:StartList
0
- b:OrderedListBlock { pushelt(b, &a); }
0
- ( c:OrderedListContinuationBlock { pushelt(c, &a); } )*
0
+ OrderedListBlock { pushelt($$, &a); }
0
+ ( OrderedListContinuationBlock { pushelt($$, &a); } )*
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
+OrderedListBlock = a:StartList Line { pushelt($$, &a); }
0
+ ( ListBlockLine { pushelt($$, &a); } )*
0
                     { $$ = mk_str(concat_string_list(reverse(a.children))); }
0
 
0
 OrderedListContinuationBlock = a:StartList
0
- ( b:BlankLines
0
- { if (strlen(b.contents.str) == 0)
0
- b.contents.str = strdup("\001"); /* block separator */
0
- pushelt(b, &a);
0
+ ( BlankLines
0
+ { if (strlen($$.contents.str) == 0)
0
+ $$.contents.str = strdup("\001"); /* block separator */
0
+ pushelt($$, &a);
0
                                 } )
0
- ( Indent c:OrderedListBlock { pushelt(c, &a); } )+
0
+ ( Indent OrderedListBlock { pushelt($$, &a); } )+
0
                               { $$ = mk_str(concat_string_list(reverse(a.children))); }
0
 
0
 BlankLines = < BlankLine* >
0
@@ -519,7 +515,7 @@
0
                 "H4" | "H5" | "H6" | "HR" | "ISINDEX" | "MENU" | "NOFRAMES" | "NOSCRIPT" | "OL" | "P" | "PRE" | "TABLE" |
0
                 "UL" | "DD" | "DT" | "FRAMESET" | "LI" | "TBODY" | "TD" | "TFOOT" | "TH" | "THEAD" | "TR" | "SCRIPT"
0
 
0
-Inlines = a:StartList ( !Endline b:Inline { pushelt(b, &a); }
0
+Inlines = a:StartList ( !Endline Inline { pushelt($$, &a); }
0
                         | c:Endline &Inline { pushelt(c, &a); } )+ Endline?
0
             { $$ = mk_list(LIST, a); }
0
 
0
@@ -568,7 +564,7 @@
0
 
0
 EmphStar = OneStar !Spacechar !Newline
0
             a:StartList
0
- ( b:EmphInlineStar { pushelt(b, &a); } )+
0
+ ( EmphInlineStar { pushelt($$, &a); } )+
0
             OneStar
0
             { $$ = mk_list(EMPH, a); }
0
 
0
@@ -577,7 +573,7 @@
0
 
0
 EmphUl = OneUl !Spacechar !Newline
0
             a:StartList
0
- ( b:EmphInlineUl { pushelt(b, &a); } )+
0
+ ( EmphInlineUl { pushelt($$, &a); } )+
0
             OneUl !Alphanumeric
0
             { $$ = mk_list(EMPH, a); }
0
 
0
@@ -588,7 +584,7 @@
0
 
0
 StrongStar = TwoStar !Spacechar !Newline
0
                 a:StartList
0
- ( b:StrongInlineStar { pushelt(b, &a); } )+
0
+ ( StrongInlineStar { pushelt($$, &a); } )+
0
                 TwoStar
0
                 { $$ = mk_list(STRONG, a); }
0
 
0
@@ -596,7 +592,7 @@
0
 
0
 StrongUl = TwoUl !Spacechar !Newline
0
             a:StartList
0
- ( b:StrongInlineUl { pushelt(b, &a); } )+
0
+ ( StrongInlineUl { pushelt($$, &a); } )+
0
             TwoUl
0
             { $$ = mk_list(STRONG, a); }
0
 
0
0
@@ -664,11 +660,9 @@
0
 
0
 Label = '['
0
         a:StartList
0
- ( b:LabelInline { pushelt(b, &a); } )+
0
+ ( !']' Inline { pushelt($$, &a); } )+
0
         ']'
0
         { $$ = mk_list(LIST, a); }
0
-
0
-LabelInline = !']' Inline
0
 
0
 RefSrc = < Nonspacechar+ > { $$ = mk_str(yytext); $$.key = HTML; }
0
 

Comments

    No one has commented yet.