r5238 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r5237‎ | r5238 | r5239 >
Date:21:11, 15 September 2004
Author:timwi
Status:old
Tags:
Comment:
several bugfixes, esp. with apostrophes (bold/italics) and headings. The ENDHEADING
token now occurs only in the "right" places, so it needn't be text any longer.
Modified paths:
  • /trunk/flexbisonparse/parsetree.c (modified) (history)
  • /trunk/flexbisonparse/parsetree.h (modified) (history)
  • /trunk/flexbisonparse/wikilex.l (modified) (history)
  • /trunk/flexbisonparse/wikiparse.y (modified) (history)

Diff [purge]

Index: trunk/flexbisonparse/parsetree.h
@@ -115,6 +115,7 @@
116116 Node convertTableRowToText (int info);
117117 Node convertTableCellToText (int info);
118118 Node convertTableHeadToText (int info);
 119+Node convertHeadingToText (int info);
119120
120121 /* Parameter must be a TextBlock. Turns something like
121122 * <italics>X<italics>Y</italics>Z</italics> into
Index: trunk/flexbisonparse/wikiparse.y
@@ -89,6 +89,13 @@
9090 | table zeroormorenewlines { debugf ("blocknotbl#5 "); $$ = $1; }
9191 | comment zeroormorenewlines { debugf ("blocknotbl#6 "); $$ = $1; }
9292
 93+heading : HEADING text ENDHEADING
 94+ { debugf ("heading#1 "); $$ = nodeAddChild (newNodeI (Heading, $1), $2); }
 95+ | HEADING text /* for eof */
 96+ { debugf ("heading#2 "); $$ = nodeAddChild (newNode (Paragraph), makeTextBlock (convertHeadingToText ($1), $2)); }
 97+ | HEADING
 98+ { debugf ("heading#3 "); $$ = nodeAddChild (newNode (Paragraph), convertHeadingToText ($1)); }
 99+
93100 preblock : preline { debugf ("preblock#1 "); $$ = nodeAddChild (newNode (PreBlock), $1); }
94101 | preblock preline { debugf ("preblock#2 "); $$ = nodeAddChild ($1, $2); }
95102
@@ -225,20 +232,29 @@
226233 (TextToken, "'"), nodeAddChild (newNode (Italics), $2))); }
227234 | APO3 textnobold
228235 { debugf ("italicsorbold#9 "); $$ = makeTextBlock (newNodeS (TextToken, "'''"), $2); }
 236+ | APO5 textnoboit APO5
 237+ { debugf ("italicsorbold#10 "); $$ = nodeAddChild (newNode (Italics),
 238+ nodeAddChild (newNode (Bold), $2)); }
229239 | APO5 textnoboit APO3 textnoital APO2
230 - { debugf ("italicsorbold#10 "); $$ = nodeAddChild (newNode (Italics),
 240+ { debugf ("italicsorbold#11 "); $$ = nodeAddChild (newNode (Italics),
231241 makeTextBlock (nodeAddChild (newNode (Bold), $2), $4)); }
232 - | APO5 textnoboit APO2 textnobold APO3
233 - { debugf ("italicsorbold#11 "); $$ = nodeAddChild (newNode (Bold),
234 - makeTextBlock (nodeAddChild (newNode (Italics), $2), $4)); }
235242 | APO5 textnoboit APO3 textnoital
236243 { debugf ("italicsorbold#12 "); $$ = makeTextBlock2 (newNodeS (TextToken, "''"),
237244 nodeAddChild (newNode (Bold), $2), $4); }
 245+ | APO5 textnoboit APO3
 246+ { debugf ("italicsorbold#13 "); $$ = makeTextBlock (newNodeS (TextToken, "''"),
 247+ nodeAddChild (newNode (Bold), $2)); }
 248+ | APO5 textnoboit APO2 textnobold APO3
 249+ { debugf ("italicsorbold#14 "); $$ = nodeAddChild (newNode (Bold),
 250+ makeTextBlock (nodeAddChild (newNode (Italics), $2), $4)); }
238251 | APO5 textnoboit APO2 textnobold
239 - { debugf ("italicsorbold#13 "); $$ = makeTextBlock2 (newNodeS (TextToken, "'''"),
 252+ { debugf ("italicsorbold#15 "); $$ = makeTextBlock2 (newNodeS (TextToken, "'''"),
240253 nodeAddChild (newNode (Italics), $2), $4); }
 254+ | APO5 textnoboit APO2
 255+ { debugf ("italicsorbold#16 "); $$ = makeTextBlock (newNodeS (TextToken, "'''"),
 256+ nodeAddChild (newNode (Italics), $2)); }
241257 | APO5 textnoboit
242 - { debugf ("italicsorbold#14 ");
 258+ { debugf ("italicsorbold#17 ");
243259 $$ = makeTextBlock (newNodeS (TextToken, "'''''"), $2); }
244260
245261 italorboldnotbl : APO2 textnoitaltbl APO2
@@ -267,20 +283,29 @@
268284 (TextToken, "'"), nodeAddChild (newNode (Italics), $2))); }
269285 | APO3 textnoboldtbl
270286 { debugf ("italorboldnotbl#9 "); $$ = makeTextBlock (newNodeS (TextToken, "'''"), $2); }
 287+ | APO5 textnoboittbl APO5
 288+ { debugf ("italorboldnotbl#10 "); $$ = nodeAddChild (newNode (Italics),
 289+ nodeAddChild (newNode (Bold), $2)); }
271290 | APO5 textnoboittbl APO3 textnoitaltbl APO2
272 - { debugf ("italorboldnotbl#10 "); $$ = nodeAddChild (newNode (Italics),
 291+ { debugf ("italorboldnotbl#11 "); $$ = nodeAddChild (newNode (Italics),
273292 makeTextBlock (nodeAddChild (newNode (Bold), $2), $4)); }
274 - | APO5 textnoboittbl APO2 textnoboldtbl APO3
275 - { debugf ("italorboldnotbl#11 "); $$ = nodeAddChild (newNode (Bold),
276 - makeTextBlock (nodeAddChild (newNode (Italics), $2), $4)); }
277293 | APO5 textnoboittbl APO3 textnoitaltbl
278294 { debugf ("italorboldnotbl#12 "); $$ = makeTextBlock2 (newNodeS (TextToken, "''"),
279295 nodeAddChild (newNode (Bold), $2), $4); }
 296+ | APO5 textnoboittbl APO3
 297+ { debugf ("italorboldnotbl#13 "); $$ = makeTextBlock (newNodeS (TextToken, "''"),
 298+ nodeAddChild (newNode (Bold), $2)); }
 299+ | APO5 textnoboittbl APO2 textnoboldtbl APO3
 300+ { debugf ("italorboldnotbl#14 "); $$ = nodeAddChild (newNode (Bold),
 301+ makeTextBlock (nodeAddChild (newNode (Italics), $2), $4)); }
280302 | APO5 textnoboittbl APO2 textnoboldtbl
281 - { debugf ("italorboldnotbl#13 "); $$ = makeTextBlock2 (newNodeS (TextToken, "'''"),
 303+ { debugf ("italorboldnotbl#15 "); $$ = makeTextBlock2 (newNodeS (TextToken, "'''"),
282304 nodeAddChild (newNode (Italics), $2), $4); }
 305+ | APO5 textnoboittbl APO2
 306+ { debugf ("italorboldnotbl#16 "); $$ = makeTextBlock (newNodeS (TextToken, "'''"),
 307+ nodeAddChild (newNode (Italics), $2)); }
283308 | APO5 textnoboittbl
284 - { debugf ("italorboldnotbl#14 ");
 309+ { debugf ("italorboldnotbl#17 ");
285310 $$ = makeTextBlock (newNodeS (TextToken, "'''''"), $2); }
286311
287312 italicsnobold : APO2 textnoboit APO2
@@ -303,20 +328,6 @@
304329 | APO3 textnoboittbl
305330 { debugf ("boldnoitalics#2 "); $$ = makeTextBlock (newNodeS (TextToken, "'''"), $2); }
306331
307 -/* In order to resolve a reduce/reduce conflict correctly, heading must come before textelement. */
308 -heading : HEADING text ENDHEADING NEWLINE
309 - { debugf ("heading#1 "); $$ = nodeAddChild (newNodeI (Heading, $1), $2); }
310 - | HEADING text ENDHEADING /* for eof */
311 - { debugf ("heading#2 "); $$ = nodeAddChild (newNodeI (Heading, $1), $2); }
312 - | HEADING text NEWLINE
313 - { debugf ("heading#3 "); $$ = nodeAddChild (newNodeI (Heading, $1), $2); }
314 - | HEADING text /* for eof */
315 - { debugf ("heading#4 "); $$ = nodeAddChild (newNodeI (Heading, $1), $2); }
316 - | HEADING NEWLINE
317 - { debugf ("heading#5 "); $$ = nodeAddChild (newNodeI (Heading, $1), newNodeS (TextToken, "?")); }
318 - | HEADING
319 - { debugf ("heading#6 "); $$ = nodeAddChild (newNodeI (Heading, $1), newNodeS (TextToken, "?")); }
320 -
321332 table : TABLEBEGIN attributes tablerows TABLEEND
322333 { debugf ("table#1 "); $$ = nodeAddChild2 (newNode (Table), $2, $3); }
323334 | TABLEBEGIN attributes tablerows
@@ -418,7 +429,6 @@
419430 textelement : TEXT { debugf ("textelement#1 "); $$ = $1; }
420431 | EXTENSION { debugf ("textelement#2 "); $$ = $1; }
421432 | PIPE { debugf ("textelement#3 "); $$ = newNodeS (TextToken, "|"); }
422 - | ENDHEADING { debugf ("textelement#4 "); $$ = processEndHeadingInText ($1); }
423433 | APO2 { debugf ("textelement#5 "); $$ = newNodeS (TextToken, "''"); }
424434 | APO3 { debugf ("textelement#6 "); $$ = newNodeS (TextToken, "'''"); }
425435 | APO5 { debugf ("textelement#7 "); $$ = newNodeS (TextToken, "'''''"); }
@@ -436,7 +446,6 @@
437447 textelementnoital : TEXT { debugf ("textelementnoital#1 "); $$ = $1; }
438448 | EXTENSION { debugf ("textelementnoital#2 "); $$ = $1; }
439449 | PIPE { debugf ("textelementnoital#3 "); $$ = newNodeS (TextToken, "|"); }
440 - | ENDHEADING { debugf ("textelementnoital#4 "); $$ = processEndHeadingInText ($1); }
441450 | TABLEBEGIN { debugf ("textelementnoital#5 "); $$ = newNodeS (TextToken, addSpaces ("{|", $1)); }
442451 | TABLEEND { debugf ("textelementnoital#6 "); $$ = newNodeS (TextToken, "|}"); }
443452 | TABLEROW { debugf ("textelementnoital#7 "); $$ = convertTableRowToText ($1); }
@@ -449,7 +458,6 @@
450459 textelementnobold : TEXT { debugf ("textelementnobold#1 "); $$ = $1; }
451460 | EXTENSION { debugf ("textelementnobold#2 "); $$ = $1; }
452461 | PIPE { debugf ("textelementnobold#3 "); $$ = newNodeS (TextToken, "|"); }
453 - | ENDHEADING { debugf ("textelementnobold#4 "); $$ = processEndHeadingInText ($1); }
454462 | TABLEBEGIN { debugf ("textelementnobold#5 "); $$ = newNodeS (TextToken, addSpaces ("{|", $1)); }
455463 | TABLEEND { debugf ("textelementnobold#6 "); $$ = newNodeS (TextToken, "|}"); }
456464 | TABLEROW { debugf ("textelementnobold#7 "); $$ = convertTableRowToText ($1); }
@@ -462,7 +470,6 @@
463471 textelementnoboit : TEXT { debugf ("textelementnoboit#1 "); $$ = $1; }
464472 | EXTENSION { debugf ("textelementnoboit#2 "); $$ = $1; }
465473 | PIPE { debugf ("textelementnoboit#3 "); $$ = newNodeS (TextToken, "|"); }
466 - | ENDHEADING { debugf ("textelementnoboit#4 "); $$ = processEndHeadingInText ($1); }
467474 | TABLEBEGIN { debugf ("textelementnoboit#5 "); $$ = newNodeS (TextToken, addSpaces ("{|", $1)); }
468475 | TABLEEND { debugf ("textelementnoboit#6 "); $$ = newNodeS (TextToken, "|}"); }
469476 | TABLEROW { debugf ("textelementnoboit#7 "); $$ = convertTableRowToText ($1); }
@@ -474,7 +481,6 @@
475482 textelementnotbl : TEXT { debugf ("textelementnotbl#1 "); $$ = $1; }
476483 | EXTENSION { debugf ("textelementnotbl#2 "); $$ = $1; }
477484 | PIPE { debugf ("textelementnotbl#3 "); $$ = newNodeS (TextToken, "|"); }
478 - | ENDHEADING { debugf ("textelementnotbl#4 "); $$ = processEndHeadingInText ($1); }
479485 | APO2 { debugf ("textelementnotbl#5 "); $$ = newNodeS (TextToken, "''"); }
480486 | APO3 { debugf ("textelementnotbl#6 "); $$ = newNodeS (TextToken, "'''"); }
481487 | APO5 { debugf ("textelementnotbl#7 "); $$ = newNodeS (TextToken, "'''''"); }
@@ -486,7 +492,6 @@
487493 textelementnoitaltbl: TEXT { debugf ("textelementnoitaltbl#1 "); $$ = $1; }
488494 | EXTENSION { debugf ("textelementnoitaltbl#2 "); $$ = $1; }
489495 | PIPE { debugf ("textelementnoitaltbl#3 "); $$ = newNodeS (TextToken, "|"); }
490 - | ENDHEADING { debugf ("textelementnoitaltbl#4 "); $$ = processEndHeadingInText ($1); }
491496 | comment { debugf ("textelementnoitaltbl#5 "); $$ = $1; }
492497 | linketcnotbl { debugf ("textelementnoitaltbl#6 "); $$ = $1; }
493498 | boldnoitalicstbl{ debugf ("textelementnoitaltbl#7 "); $$ = $1; }
@@ -494,7 +499,6 @@
495500 textelementnoboldtbl: TEXT { debugf ("textelementnoboldtbl#1 "); $$ = $1; }
496501 | EXTENSION { debugf ("textelementnoboldtbl#2 "); $$ = $1; }
497502 | PIPE { debugf ("textelementnoboldtbl#3 "); $$ = newNodeS (TextToken, "|"); }
498 - | ENDHEADING { debugf ("textelementnoboldtbl#4 "); $$ = processEndHeadingInText ($1); }
499503 | comment { debugf ("textelementnoboldtbl#5 "); $$ = $1; }
500504 | linketcnotbl { debugf ("textelementnoboldtbl#6 "); $$ = $1; }
501505 | italicsnoboldtbl{ debugf ("textelementnoboldtbl#7 "); $$ = $1; }
@@ -502,7 +506,6 @@
503507 textelementnoboittbl: TEXT { debugf ("textelementnoboittbl#1 "); $$ = $1; }
504508 | EXTENSION { debugf ("textelementnoboittbl#2 "); $$ = $1; }
505509 | PIPE { debugf ("textelementnoboittbl#3 "); $$ = newNodeS (TextToken, "|"); }
506 - | ENDHEADING { debugf ("textelementnoboittbl#4 "); $$ = processEndHeadingInText ($1); }
507510 | comment { debugf ("textelementnoboittbl#5 "); $$ = $1; }
508511 | linketcnotbl { debugf ("textelementnoboittbl#6 "); $$ = $1; }
509512
Index: trunk/flexbisonparse/wikilex.l
@@ -29,13 +29,28 @@
3030 {
3131 int i = 1;
3232 while (input[i] == '-') i++;
33 - return ((i-1)*0x10000 + (initleng-i));
 33+ return (((i-1) << 16) | (initleng-i));
3434 }
3535
3636 #define COMMONTOKENS \
3737 if (YY_START != inattributeapo && YY_START != inattributeq && YY_START != canbeheading) \
3838 BEGIN (cannotbelistorheadingorpre);
3939
 40+#define APOSTROPHE_CATASTROPHE(len,debugstr,token) \
 41+ if (yytext[len] == '\'') \
 42+ { \
 43+ yyless (1); \
 44+ yylval.node = newNodeS (TextToken, "'"); \
 45+ debuglex2 ("TEXT(%s) ", "'"); \
 46+ return TEXT; \
 47+ } \
 48+ else \
 49+ { \
 50+ yyless (len); \
 51+ debuglex (debugstr); \
 52+ return token; \
 53+ }
 54+
4055 %}
4156
4257 /* inclusive start conditions */
@@ -122,9 +137,12 @@
123138 \}\}\} { COMMONTOKENS; debuglex ("CLOSETEMPLATEVAR "); return CLOSETEMPLATEVAR; }
124139 \{\{ { COMMONTOKENS; debuglex ("OPENTEMPLATE "); return OPENTEMPLATE; }
125140 \}\} { COMMONTOKENS; debuglex ("CLOSETEMPLATE "); return CLOSETEMPLATE; }
126 -'''''/[^'] { COMMONTOKENS; debuglex ("APO5 "); return APO5; }
127 -'''/[^'] { COMMONTOKENS; debuglex ("APO3 "); return APO3; }
128 -''/[^'] { COMMONTOKENS; debuglex ("APO2 "); return APO2; }
 141+''''' { COMMONTOKENS; debuglex ("APO5 "); return APO5; }
 142+''' { COMMONTOKENS; debuglex ("APO3 "); return APO3; }
 143+'' { COMMONTOKENS; debuglex ("APO2 "); return APO2; }
 144+'''''. { COMMONTOKENS; APOSTROPHE_CATASTROPHE (5, "APO5 ", APO5); }
 145+'''. { COMMONTOKENS; APOSTROPHE_CATASTROPHE (3, "APO3 ", APO3); }
 146+''. { COMMONTOKENS; APOSTROPHE_CATASTROPHE (2, "APO2 ", APO2); }
129147 \n { BEGIN (INITIAL); debuglex ("NEWLINE\n"); return NEWLINE; }
130148 \r { /* ignore this one */ debuglex ("<13> "); }
131149
@@ -140,10 +158,12 @@
141159 debuglex2 ("HEADING(%d) ", yylval.num);
142160 return HEADING;
143161 }
144 -<canbeheading>"="+" "* {
 162+<canbeheading>"="+" "*\r\n |
 163+<canbeheading>"="+" "*\n {
145164 yylval.num = 0;
146165 while (yytext [ yylval.num ] == '=')
147166 yylval.num++;
 167+ yylval.num |= (yyleng-yylval.num) << 16;
148168 debuglex2 ("ENDHEADING(%d) ", yylval.num);
149169 return ENDHEADING;
150170 }
Index: trunk/flexbisonparse/parsetree.c
@@ -295,14 +295,18 @@
296296 Node processEndHeadingInText (int n)
297297 {
298298 char* ret;
 299+ int equalses, spaces, i;
299300
300 - if (n < 1) return 0;
301 - /* Performance optimisation */
302 - if (n == 1) return newNodeS (TextToken, "=");
 301+ equalses = n % 0x10000;
 302+ spaces = n >> 16;
303303
304 - ret = (char*) malloc ((n+1) * sizeof (char));
305 - ret[n] = '\0';
306 - while (n) ret[--n] = '=';
 304+ if (equalses + spaces < 1) return 0;
 305+
 306+ ret = (char*) malloc ((equalses + spaces + 1) * sizeof (char));
 307+ i = 0;
 308+ while (equalses--) ret[i++] = '=';
 309+ while (spaces--) ret[i++] = ' ';
 310+ ret[i] = '\0';
307311 return newNodeS (TextToken, ret);
308312 }
309313
@@ -557,6 +561,18 @@
558562 return newNodeS (TextToken, addSpaces (info % 2 ? "!" : "!!", info/2));
559563 }
560564
 565+Node convertHeadingToText (int info)
 566+{
 567+ int i;
 568+ char* text;
 569+
 570+ text = (char*) malloc ((info + 1) * sizeof (char));
 571+ i = 0;
 572+ while (info--) text[i++] = '=';
 573+ text[i] = '\0';
 574+ return newNodeS (TextToken, text);
 575+}
 576+
561577 char* addSpaces (char* src, int spaces)
562578 {
563579 char* ret;

Status & tagging log