r5285 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r5284‎ | r5285 | r5286 >
Date:23:28, 17 September 2004
Author:timwi
Status:old
Tags:
Comment:
Table captions (|+ syntax)
Modified paths:
  • /trunk/flexbisonparse/parsetree.c (modified) (history)
  • /trunk/flexbisonparse/parsetree.h (modified) (history)
  • /trunk/flexbisonparse/test.txt (modified) (history)
  • /trunk/flexbisonparse/wikilex.l (modified) (history)
  • /trunk/flexbisonparse/wikiparse.y (modified) (history)

Diff [purge]

Index: trunk/flexbisonparse/parsetree.h
@@ -13,7 +13,8 @@
1414 Article, Paragraph, Heading, TextBlock, TextToken, ExtensionToken,
1515 Newlines, PreBlock, PreLine, Bold, Italics, Comment,
1616 LinkEtc, LinkTarget, LinkOption, Template, TemplateVar,
17 - Table, TableRow, TableCell, TableHead /* 20 */, Attribute, AttributeGroup,
 17+ Table, TableRow, TableCell, TableHead /* 20 */, TableCaption,
 18+ Attribute, AttributeGroup,
1819
1920 /* After first parse */
2021 ListBlock, ListLine, ListBullet, ListNumbered,
@@ -115,6 +116,7 @@
116117 Node convertTableRowToText (int info);
117118 Node convertTableCellToText (int info);
118119 Node convertTableHeadToText (int info);
 120+Node convertTableCaptionToText (int info);
119121 Node convertHeadingToText (int info);
120122
121123 /* Parameter must be a TextBlock. Turns something like
Index: trunk/flexbisonparse/wikiparse.y
@@ -36,15 +36,15 @@
3737 textelement textelementnoboit textelementnobold textelementnoital textelementinlink
3838 textnoboit textnobold textnoital textinlink textorempty zeroormorenewlines
3939 zeroormorenewlinessave textintbl textelementintbl textintmpl textelementintmpl
40 - template templatevar
 40+ template templatevar tablecaption
4141 TEXT EXTENSION
4242 %type <ad> ATTRIBUTE
43 -%type <num> HEADING ENDHEADING TABLEBEGIN TABLECELL TABLEHEAD TABLEROW EQUALS ATTRAPO ATTRQ
 43+%type <num> HEADING ENDHEADING EQUALS ATTRAPO ATTRQ
 44+ TABLEBEGIN TABLECELL TABLEHEAD TABLEROW TABLECAPTION
4445
4546 %token EXTENSION BEGINCOMMENT TEXT ENDCOMMENT OPENLINK OPENDBLSQBR CLOSEDBLSQBR PIPE
4647 NEWLINE PRELINE LISTBULLET LISTNUMBERED HEADING ENDHEADING APO5 APO3 APO2 TABLEBEGIN
47 - TABLECELL TABLEHEAD TABLEROW TABLEEND ATTRIBUTE EQUALS ATTRAPO ATTRQ
48 - // Not yet used:
 48+ TABLECELL TABLEHEAD TABLEROW TABLEEND TABLECAPTION ATTRIBUTE EQUALS ATTRAPO ATTRQ
4949 OPENPENTUPLECURLY CLOSEPENTUPLECURLY OPENTEMPLATEVAR CLOSETEMPLATEVAR OPENTEMPLATE
5050 CLOSETEMPLATE
5151
@@ -283,6 +283,8 @@
284284 { debugf ("tablerow#8 "); $$ = 0; }
285285 | TABLEROW
286286 { debugf ("tablerow#9 "); $$ = 0; }
 287+ | tablecaption
 288+ { debugf ("tablerow#10 "); $$ = $1; }
287289
288290 tablecells : tablecell { debugf ("tablecells#1 "); $$ = $1; }
289291 | tablecells tablecell { debugf ("tablecells#2 "); $$ = nodeAddSibling ($1, $2); }
@@ -317,6 +319,19 @@
318320 | oneormorenewlines blocksintbl
319321 { debugf ("tablecellcontents#2 "); $$ = $2; }
320322
 323+tablecaption : TABLECAPTION attributes PIPE textintbl
 324+ { debugf ("tablecaption#1 "); $$ = nodeAddChild2 (newNode (TableCaption), $2, $4); }
 325+ | TABLECAPTION attributes textintbl
 326+ { debugf ("tablecaption#2 "); $$ = nodeAddChild (newNode (TableCaption), makeTextBlock (convertAttributesToText ($2), $3)); }
 327+ | TABLECAPTION textintbl
 328+ { debugf ("tablecaption#3 "); $$ = nodeAddChild (newNode (TableCaption), $2); }
 329+ | TABLECAPTION attributes PIPE
 330+ { debugf ("tablecaption#4 "); $$ = nodeAddChild (newNode (TableCaption), makeTextBlock (convertAttributesToText ($2), newNodeS (TextToken, "|"))); }
 331+ | TABLECAPTION attributes
 332+ { debugf ("tablecaption#5 "); $$ = nodeAddChild (newNode (TableCaption), convertAttributesToText ($2)); }
 333+ | TABLECAPTION
 334+ { debugf ("tablecaption#6 "); $$ = 0; }
 335+
321336 /* In order to reduce the second one (ATTRIBUTE EQUALS TEXT) correctly, this rule must
322337 * be further up than textelement. */
323338 attribute : ATTRIBUTE
@@ -363,15 +378,16 @@
364379 | TABLEROW { debugf ("textelement#11 "); $$ = convertTableRowToText ($1); }
365380 | TABLECELL { debugf ("textelement#12 "); $$ = convertTableCellToText ($1); }
366381 | TABLEHEAD { debugf ("textelement#13 "); $$ = convertTableHeadToText ($1); }
367 - | ATTRIBUTE { debugf ("textelement#14 "); $$ = convertAttributeDataToText ($1); }
368 - | CLOSEPENTUPLECURLY { debugf ("textelement#15 "); $$ = newNodeS (TextToken, "}}}}}"); }
369 - | CLOSETEMPLATEVAR { debugf ("textelement#16 "); $$ = newNodeS (TextToken, "}}}"); }
370 - | CLOSETEMPLATE { debugf ("textelement#17 "); $$ = newNodeS (TextToken, "}}"); }
371 - | comment { debugf ("textelement#18 "); $$ = $1; }
372 - | linketc { debugf ("textelement#19 "); $$ = $1; }
373 - | italicsorbold { debugf ("textelement#20 "); $$ = $1; }
374 - | template { debugf ("textelement#21 "); $$ = $1; }
375 - | templatevar { debugf ("textelement#22 "); $$ = $1; }
 382+ | TABLECAPTION { debugf ("textelement#14 "); $$ = convertTableCaptionToText ($1); }
 383+ | ATTRIBUTE { debugf ("textelement#15 "); $$ = convertAttributeDataToText ($1); }
 384+ | CLOSEPENTUPLECURLY { debugf ("textelement#16 "); $$ = newNodeS (TextToken, "}}}}}"); }
 385+ | CLOSETEMPLATEVAR { debugf ("textelement#17 "); $$ = newNodeS (TextToken, "}}}"); }
 386+ | CLOSETEMPLATE { debugf ("textelement#18 "); $$ = newNodeS (TextToken, "}}"); }
 387+ | comment { debugf ("textelement#19 "); $$ = $1; }
 388+ | linketc { debugf ("textelement#20 "); $$ = $1; }
 389+ | italicsorbold { debugf ("textelement#21 "); $$ = $1; }
 390+ | template { debugf ("textelement#22 "); $$ = $1; }
 391+ | templatevar { debugf ("textelement#23 "); $$ = $1; }
376392
377393 textelementnoital : TEXT { debugf ("textelementnoital#1 "); $$ = $1; }
378394 | EXTENSION { debugf ("textelementnoital#2 "); $$ = $1; }
@@ -382,15 +398,16 @@
383399 | TABLEROW { debugf ("textelementnoital#7 "); $$ = convertTableRowToText ($1); }
384400 | TABLECELL { debugf ("textelementnoital#8 "); $$ = convertTableCellToText ($1); }
385401 | TABLEHEAD { debugf ("textelementnoital#9 "); $$ = convertTableHeadToText ($1); }
386 - | ATTRIBUTE { debugf ("textelementnoital#10 "); $$ = convertAttributeDataToText ($1); }
387 - | CLOSEPENTUPLECURLY { debugf ("textelementnoital#11 "); $$ = newNodeS (TextToken, "}}}}}"); }
388 - | CLOSETEMPLATEVAR { debugf ("textelementnoital#12 "); $$ = newNodeS (TextToken, "}}}"); }
389 - | CLOSETEMPLATE { debugf ("textelementnoital#13 "); $$ = newNodeS (TextToken, "}}"); }
390 - | comment { debugf ("textelementnoital#14 "); $$ = $1; }
391 - | linketc { debugf ("textelementnoital#15 "); $$ = $1; }
392 - | boldnoitalics { debugf ("textelementnoital#16 "); $$ = $1; }
393 - | template { debugf ("textelementnoital#17 "); $$ = $1; }
394 - | templatevar { debugf ("textelementnoital#18 "); $$ = $1; }
 402+ | TABLECAPTION { debugf ("textelementnoital#10 "); $$ = convertTableCaptionToText ($1); }
 403+ | ATTRIBUTE { debugf ("textelementnoital#11 "); $$ = convertAttributeDataToText ($1); }
 404+ | CLOSEPENTUPLECURLY { debugf ("textelementnoital#12 "); $$ = newNodeS (TextToken, "}}}}}"); }
 405+ | CLOSETEMPLATEVAR { debugf ("textelementnoital#13 "); $$ = newNodeS (TextToken, "}}}"); }
 406+ | CLOSETEMPLATE { debugf ("textelementnoital#14 "); $$ = newNodeS (TextToken, "}}"); }
 407+ | comment { debugf ("textelementnoital#15 "); $$ = $1; }
 408+ | linketc { debugf ("textelementnoital#16 "); $$ = $1; }
 409+ | boldnoitalics { debugf ("textelementnoital#17 "); $$ = $1; }
 410+ | template { debugf ("textelementnoital#18 "); $$ = $1; }
 411+ | templatevar { debugf ("textelementnoital#19 "); $$ = $1; }
395412
396413 textelementnobold : TEXT { debugf ("textelementnobold#1 "); $$ = $1; }
397414 | EXTENSION { debugf ("textelementnobold#2 "); $$ = $1; }
@@ -401,15 +418,16 @@
402419 | TABLEROW { debugf ("textelementnobold#7 "); $$ = convertTableRowToText ($1); }
403420 | TABLECELL { debugf ("textelementnobold#8 "); $$ = convertTableCellToText ($1); }
404421 | TABLEHEAD { debugf ("textelementnobold#9 "); $$ = convertTableHeadToText ($1); }
405 - | ATTRIBUTE { debugf ("textelementnobold#10 "); $$ = convertAttributeDataToText ($1); }
406 - | CLOSEPENTUPLECURLY { debugf ("textelementnobold#11 "); $$ = newNodeS (TextToken, "}}}}}"); }
407 - | CLOSETEMPLATEVAR { debugf ("textelementnobold#12 "); $$ = newNodeS (TextToken, "}}}"); }
408 - | CLOSETEMPLATE { debugf ("textelementnobold#13 "); $$ = newNodeS (TextToken, "}}"); }
409 - | comment { debugf ("textelementnobold#14 "); $$ = $1; }
410 - | linketc { debugf ("textelementnobold#15 "); $$ = $1; }
411 - | italicsnobold { debugf ("textelementnobold#16 "); $$ = $1; }
412 - | template { debugf ("textelementnobold#17 "); $$ = $1; }
413 - | templatevar { debugf ("textelementnobold#18 "); $$ = $1; }
 422+ | TABLECAPTION { debugf ("textelementnobold#10 "); $$ = convertTableCaptionToText ($1); }
 423+ | ATTRIBUTE { debugf ("textelementnobold#11 "); $$ = convertAttributeDataToText ($1); }
 424+ | CLOSEPENTUPLECURLY { debugf ("textelementnobold#12 "); $$ = newNodeS (TextToken, "}}}}}"); }
 425+ | CLOSETEMPLATEVAR { debugf ("textelementnobold#13 "); $$ = newNodeS (TextToken, "}}}"); }
 426+ | CLOSETEMPLATE { debugf ("textelementnobold#14 "); $$ = newNodeS (TextToken, "}}"); }
 427+ | comment { debugf ("textelementnobold#15 "); $$ = $1; }
 428+ | linketc { debugf ("textelementnobold#16 "); $$ = $1; }
 429+ | italicsnobold { debugf ("textelementnobold#17 "); $$ = $1; }
 430+ | template { debugf ("textelementnobold#18 "); $$ = $1; }
 431+ | templatevar { debugf ("textelementnobold#19 "); $$ = $1; }
414432
415433 textelementnoboit : TEXT { debugf ("textelementnoboit#1 "); $$ = $1; }
416434 | EXTENSION { debugf ("textelementnoboit#2 "); $$ = $1; }
@@ -420,14 +438,15 @@
421439 | TABLEROW { debugf ("textelementnoboit#7 "); $$ = convertTableRowToText ($1); }
422440 | TABLECELL { debugf ("textelementnoboit#8 "); $$ = convertTableCellToText ($1); }
423441 | TABLEHEAD { debugf ("textelementnoboit#9 "); $$ = convertTableHeadToText ($1); }
424 - | ATTRIBUTE { debugf ("textelementnoital#10 "); $$ = convertAttributeDataToText ($1); }
425 - | CLOSEPENTUPLECURLY { debugf ("textelementnobold#11 "); $$ = newNodeS (TextToken, "}}}}}"); }
426 - | CLOSETEMPLATEVAR { debugf ("textelementnobold#12 "); $$ = newNodeS (TextToken, "}}}"); }
427 - | CLOSETEMPLATE { debugf ("textelementnobold#13 "); $$ = newNodeS (TextToken, "}}"); }
428 - | comment { debugf ("textelementnoboit#14 "); $$ = $1; }
429 - | linketc { debugf ("textelementnoboit#15 "); $$ = $1; }
430 - | template { debugf ("textelementnoboit#16 "); $$ = $1; }
431 - | templatevar { debugf ("textelementnoboit#17 "); $$ = $1; }
 442+ | TABLECAPTION { debugf ("textelementnoboit#10 "); $$ = convertTableCaptionToText ($1); }
 443+ | ATTRIBUTE { debugf ("textelementnoboit#11 "); $$ = convertAttributeDataToText ($1); }
 444+ | CLOSEPENTUPLECURLY { debugf ("textelementnobold#12 "); $$ = newNodeS (TextToken, "}}}}}"); }
 445+ | CLOSETEMPLATEVAR { debugf ("textelementnobold#13 "); $$ = newNodeS (TextToken, "}}}"); }
 446+ | CLOSETEMPLATE { debugf ("textelementnobold#14 "); $$ = newNodeS (TextToken, "}}"); }
 447+ | comment { debugf ("textelementnoboit#15 "); $$ = $1; }
 448+ | linketc { debugf ("textelementnoboit#16 "); $$ = $1; }
 449+ | template { debugf ("textelementnoboit#17 "); $$ = $1; }
 450+ | templatevar { debugf ("textelementnoboit#18 "); $$ = $1; }
432451
433452 textelementintbl : TEXT { debugf ("textelementintbl#1 "); $$ = $1; }
434453 | EXTENSION { debugf ("textelementintbl#2 "); $$ = $1; }
@@ -457,15 +476,16 @@
458477 | TABLEROW { debugf ("textelementinlink#9 "); $$ = convertTableRowToText ($1); }
459478 | TABLECELL { debugf ("textelementinlink#10 "); $$ = convertTableCellToText ($1); }
460479 | TABLEHEAD { debugf ("textelementinlink#11 "); $$ = convertTableHeadToText ($1); }
461 - | ATTRIBUTE { debugf ("textelementinlink#12 "); $$ = convertAttributeDataToText ($1); }
462 - | CLOSEPENTUPLECURLY { debugf ("textelementinlink#13 "); $$ = newNodeS (TextToken, "}}}}}"); }
463 - | CLOSETEMPLATEVAR { debugf ("textelementinlink#14 "); $$ = newNodeS (TextToken, "}}}"); }
464 - | CLOSETEMPLATE { debugf ("textelementinlink#15 "); $$ = newNodeS (TextToken, "}}"); }
465 - | comment { debugf ("textelementinlink#16 "); $$ = $1; }
466 - | linketc { debugf ("textelementinlink#17 "); $$ = $1; }
467 - | italicsorbold { debugf ("textelementinlink#18 "); $$ = $1; }
468 - | template { debugf ("textelementinlink#19 "); $$ = $1; }
469 - | templatevar { debugf ("textelementinlink#20 "); $$ = $1; }
 480+ | TABLECAPTION { debugf ("textelementinlink#12 "); $$ = convertTableCaptionToText ($1); }
 481+ | ATTRIBUTE { debugf ("textelementinlink#13 "); $$ = convertAttributeDataToText ($1); }
 482+ | CLOSEPENTUPLECURLY { debugf ("textelementinlink#14 "); $$ = newNodeS (TextToken, "}}}}}"); }
 483+ | CLOSETEMPLATEVAR { debugf ("textelementinlink#15 "); $$ = newNodeS (TextToken, "}}}"); }
 484+ | CLOSETEMPLATE { debugf ("textelementinlink#16 "); $$ = newNodeS (TextToken, "}}"); }
 485+ | comment { debugf ("textelementinlink#17 "); $$ = $1; }
 486+ | linketc { debugf ("textelementinlink#18 "); $$ = $1; }
 487+ | italicsorbold { debugf ("textelementinlink#19 "); $$ = $1; }
 488+ | template { debugf ("textelementinlink#20 "); $$ = $1; }
 489+ | templatevar { debugf ("textelementinlink#21 "); $$ = $1; }
470490
471491 textelementintmpl : TEXT { debugf ("textelementintmpl#1 "); $$ = $1; }
472492 | EXTENSION { debugf ("textelementintmpl#2 "); $$ = $1; }
@@ -480,12 +500,13 @@
481501 | TABLEROW { debugf ("textelementintmpl#11 "); $$ = convertTableRowToText ($1); }
482502 | TABLECELL { debugf ("textelementintmpl#12 "); $$ = convertTableCellToText ($1); }
483503 | TABLEHEAD { debugf ("textelementintmpl#13 "); $$ = convertTableHeadToText ($1); }
484 - | ATTRIBUTE { debugf ("textelementintmpl#14 "); $$ = convertAttributeDataToText ($1); }
485 - | comment { debugf ("textelementintmpl#15 "); $$ = $1; }
486 - | linketc { debugf ("textelementintmpl#16 "); $$ = $1; }
487 - | italicsorbold { debugf ("textelementintmpl#17 "); $$ = $1; }
488 - | template { debugf ("textelementintmpl#18 "); $$ = $1; }
489 - | templatevar { debugf ("textelementintmpl#19 "); $$ = $1; }
 504+ | TABLECAPTION { debugf ("textelementintmpl#14 "); $$ = convertTableCaptionToText ($1); }
 505+ | ATTRIBUTE { debugf ("textelementintmpl#15 "); $$ = convertAttributeDataToText ($1); }
 506+ | comment { debugf ("textelementintmpl#16 "); $$ = $1; }
 507+ | linketc { debugf ("textelementintmpl#17 "); $$ = $1; }
 508+ | italicsorbold { debugf ("textelementintmpl#18 "); $$ = $1; }
 509+ | template { debugf ("textelementintmpl#19 "); $$ = $1; }
 510+ | templatevar { debugf ("textelementintmpl#20 "); $$ = $1; }
490511
491512 template : OPENTEMPLATE textintmpl CLOSETEMPLATE
492513 { debugf ("template#1 "); $$ = nodeAddChild (newNode (Template), $2); }
Index: trunk/flexbisonparse/wikilex.l
@@ -105,9 +105,10 @@
106106 "{|"" "* { BEGIN(attributes); debuglex ("TABLEBEGIN "); yylval.num = yyleng-2; return TABLEBEGIN; }
107107 "||"" "* { yylval.num = 2*(yyleng-2); BEGIN(attributes); debuglex2 ("TABLECELL(%u) ", yylval.num); return TABLECELL; }
108108 ^"|"" "* { yylval.num = 2*(yyleng-1)+1; BEGIN(attributes); debuglex2 ("TABLECELL(%u) ", yylval.num); return TABLECELL; }
109 -"!!"" "* { BEGIN(attributes); debuglex ("TABLEHEAD "); yylval.num = 2*(yyleng-2); return TABLEHEAD; }
110 -^"!"" "* { BEGIN(attributes); debuglex ("TABLEHEAD "); yylval.num = 2*(yyleng-1)+1; return TABLEHEAD; }
111 -"|""-"+" "* { BEGIN(attributes); debuglex ("TABLEROW "); yylval.num = encodeTableRowInfo (yytext, yyleng); return TABLEROW; }
 109+"!!"" "* { BEGIN(attributes); debuglex ("TABLEHEAD "); yylval.num = 2*(yyleng-2); return TABLEHEAD; }
 110+^"!"" "* { BEGIN(attributes); debuglex ("TABLEHEAD "); yylval.num = 2*(yyleng-1)+1; return TABLEHEAD; }
 111+"|""-"+" "* { BEGIN(attributes); debuglex ("TABLEROW "); yylval.num = encodeTableRowInfo (yytext, yyleng); return TABLEROW; }
 112+"|+"" "* { BEGIN(attributes); debuglex ("TABLECAPTION "); yylval.num = yyleng-2; return TABLECAPTION; }
112113 "|}" { BEGIN(cannotbelistorheadingorpre); debuglex ("TABLEEND "); return TABLEEND; }
113114
114115 <attributes>[-a-zA-Z:_]+" "* {
Index: trunk/flexbisonparse/parsetree.c
@@ -575,6 +575,11 @@
576576 return newNodeS (TextToken, addSpaces (info % 2 ? "!" : "!!", info/2));
577577 }
578578
 579+Node convertTableCaptionToText (int info)
 580+{
 581+ return newNodeS (TextToken, addSpaces ("|+", info));
 582+}
 583+
579584 Node convertHeadingToText (int info)
580585 {
581586 int i;
@@ -756,6 +761,7 @@
757762 node->type == TableRow ? "tablerow" :
758763 node->type == TableCell ? "tablecell" :
759764 node->type == TableHead ? "tablehead" :
 765+ node->type == TableCaption ? "caption" :
760766 node->type == AttributeGroup? "attrs" :
761767
762768 /* Fallback value */
Index: trunk/flexbisonparse/test.txt
@@ -8,8 +8,9 @@
99 ** graphics
1010 ** sound
1111
12 -{| || Version 1 || not bad
13 -|- || Version 2 || much better |}
 12+{| !! Version 1 || not bad
 13+|- !! Version 2 || much better
 14+|+ An informative table |}
1415
1516 This is a || token in the middle of text.
1617

Status & tagging log