Index: trunk/flexbisonparse/parsetree.h |
— | — | @@ -115,6 +115,7 @@ |
116 | 116 | Node convertTableRowToText (int info); |
117 | 117 | Node convertTableCellToText (int info); |
118 | 118 | Node convertTableHeadToText (int info); |
| 119 | +Node convertHeadingToText (int info); |
119 | 120 | |
120 | 121 | /* Parameter must be a TextBlock. Turns something like |
121 | 122 | * <italics>X<italics>Y</italics>Z</italics> into |
Index: trunk/flexbisonparse/wikiparse.y |
— | — | @@ -89,6 +89,13 @@ |
90 | 90 | | table zeroormorenewlines { debugf ("blocknotbl#5 "); $$ = $1; } |
91 | 91 | | comment zeroormorenewlines { debugf ("blocknotbl#6 "); $$ = $1; } |
92 | 92 | |
| 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 | + |
93 | 100 | preblock : preline { debugf ("preblock#1 "); $$ = nodeAddChild (newNode (PreBlock), $1); } |
94 | 101 | | preblock preline { debugf ("preblock#2 "); $$ = nodeAddChild ($1, $2); } |
95 | 102 | |
— | — | @@ -225,20 +232,29 @@ |
226 | 233 | (TextToken, "'"), nodeAddChild (newNode (Italics), $2))); } |
227 | 234 | | APO3 textnobold |
228 | 235 | { debugf ("italicsorbold#9 "); $$ = makeTextBlock (newNodeS (TextToken, "'''"), $2); } |
| 236 | + | APO5 textnoboit APO5 |
| 237 | + { debugf ("italicsorbold#10 "); $$ = nodeAddChild (newNode (Italics), |
| 238 | + nodeAddChild (newNode (Bold), $2)); } |
229 | 239 | | APO5 textnoboit APO3 textnoital APO2 |
230 | | - { debugf ("italicsorbold#10 "); $$ = nodeAddChild (newNode (Italics), |
| 240 | + { debugf ("italicsorbold#11 "); $$ = nodeAddChild (newNode (Italics), |
231 | 241 | 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)); } |
235 | 242 | | APO5 textnoboit APO3 textnoital |
236 | 243 | { debugf ("italicsorbold#12 "); $$ = makeTextBlock2 (newNodeS (TextToken, "''"), |
237 | 244 | 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)); } |
238 | 251 | | APO5 textnoboit APO2 textnobold |
239 | | - { debugf ("italicsorbold#13 "); $$ = makeTextBlock2 (newNodeS (TextToken, "'''"), |
| 252 | + { debugf ("italicsorbold#15 "); $$ = makeTextBlock2 (newNodeS (TextToken, "'''"), |
240 | 253 | nodeAddChild (newNode (Italics), $2), $4); } |
| 254 | + | APO5 textnoboit APO2 |
| 255 | + { debugf ("italicsorbold#16 "); $$ = makeTextBlock (newNodeS (TextToken, "'''"), |
| 256 | + nodeAddChild (newNode (Italics), $2)); } |
241 | 257 | | APO5 textnoboit |
242 | | - { debugf ("italicsorbold#14 "); |
| 258 | + { debugf ("italicsorbold#17 "); |
243 | 259 | $$ = makeTextBlock (newNodeS (TextToken, "'''''"), $2); } |
244 | 260 | |
245 | 261 | italorboldnotbl : APO2 textnoitaltbl APO2 |
— | — | @@ -267,20 +283,29 @@ |
268 | 284 | (TextToken, "'"), nodeAddChild (newNode (Italics), $2))); } |
269 | 285 | | APO3 textnoboldtbl |
270 | 286 | { debugf ("italorboldnotbl#9 "); $$ = makeTextBlock (newNodeS (TextToken, "'''"), $2); } |
| 287 | + | APO5 textnoboittbl APO5 |
| 288 | + { debugf ("italorboldnotbl#10 "); $$ = nodeAddChild (newNode (Italics), |
| 289 | + nodeAddChild (newNode (Bold), $2)); } |
271 | 290 | | APO5 textnoboittbl APO3 textnoitaltbl APO2 |
272 | | - { debugf ("italorboldnotbl#10 "); $$ = nodeAddChild (newNode (Italics), |
| 291 | + { debugf ("italorboldnotbl#11 "); $$ = nodeAddChild (newNode (Italics), |
273 | 292 | 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)); } |
277 | 293 | | APO5 textnoboittbl APO3 textnoitaltbl |
278 | 294 | { debugf ("italorboldnotbl#12 "); $$ = makeTextBlock2 (newNodeS (TextToken, "''"), |
279 | 295 | 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)); } |
280 | 302 | | APO5 textnoboittbl APO2 textnoboldtbl |
281 | | - { debugf ("italorboldnotbl#13 "); $$ = makeTextBlock2 (newNodeS (TextToken, "'''"), |
| 303 | + { debugf ("italorboldnotbl#15 "); $$ = makeTextBlock2 (newNodeS (TextToken, "'''"), |
282 | 304 | nodeAddChild (newNode (Italics), $2), $4); } |
| 305 | + | APO5 textnoboittbl APO2 |
| 306 | + { debugf ("italorboldnotbl#16 "); $$ = makeTextBlock (newNodeS (TextToken, "'''"), |
| 307 | + nodeAddChild (newNode (Italics), $2)); } |
283 | 308 | | APO5 textnoboittbl |
284 | | - { debugf ("italorboldnotbl#14 "); |
| 309 | + { debugf ("italorboldnotbl#17 "); |
285 | 310 | $$ = makeTextBlock (newNodeS (TextToken, "'''''"), $2); } |
286 | 311 | |
287 | 312 | italicsnobold : APO2 textnoboit APO2 |
— | — | @@ -303,20 +328,6 @@ |
304 | 329 | | APO3 textnoboittbl |
305 | 330 | { debugf ("boldnoitalics#2 "); $$ = makeTextBlock (newNodeS (TextToken, "'''"), $2); } |
306 | 331 | |
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 | | - |
321 | 332 | table : TABLEBEGIN attributes tablerows TABLEEND |
322 | 333 | { debugf ("table#1 "); $$ = nodeAddChild2 (newNode (Table), $2, $3); } |
323 | 334 | | TABLEBEGIN attributes tablerows |
— | — | @@ -418,7 +429,6 @@ |
419 | 430 | textelement : TEXT { debugf ("textelement#1 "); $$ = $1; } |
420 | 431 | | EXTENSION { debugf ("textelement#2 "); $$ = $1; } |
421 | 432 | | PIPE { debugf ("textelement#3 "); $$ = newNodeS (TextToken, "|"); } |
422 | | - | ENDHEADING { debugf ("textelement#4 "); $$ = processEndHeadingInText ($1); } |
423 | 433 | | APO2 { debugf ("textelement#5 "); $$ = newNodeS (TextToken, "''"); } |
424 | 434 | | APO3 { debugf ("textelement#6 "); $$ = newNodeS (TextToken, "'''"); } |
425 | 435 | | APO5 { debugf ("textelement#7 "); $$ = newNodeS (TextToken, "'''''"); } |
— | — | @@ -436,7 +446,6 @@ |
437 | 447 | textelementnoital : TEXT { debugf ("textelementnoital#1 "); $$ = $1; } |
438 | 448 | | EXTENSION { debugf ("textelementnoital#2 "); $$ = $1; } |
439 | 449 | | PIPE { debugf ("textelementnoital#3 "); $$ = newNodeS (TextToken, "|"); } |
440 | | - | ENDHEADING { debugf ("textelementnoital#4 "); $$ = processEndHeadingInText ($1); } |
441 | 450 | | TABLEBEGIN { debugf ("textelementnoital#5 "); $$ = newNodeS (TextToken, addSpaces ("{|", $1)); } |
442 | 451 | | TABLEEND { debugf ("textelementnoital#6 "); $$ = newNodeS (TextToken, "|}"); } |
443 | 452 | | TABLEROW { debugf ("textelementnoital#7 "); $$ = convertTableRowToText ($1); } |
— | — | @@ -449,7 +458,6 @@ |
450 | 459 | textelementnobold : TEXT { debugf ("textelementnobold#1 "); $$ = $1; } |
451 | 460 | | EXTENSION { debugf ("textelementnobold#2 "); $$ = $1; } |
452 | 461 | | PIPE { debugf ("textelementnobold#3 "); $$ = newNodeS (TextToken, "|"); } |
453 | | - | ENDHEADING { debugf ("textelementnobold#4 "); $$ = processEndHeadingInText ($1); } |
454 | 462 | | TABLEBEGIN { debugf ("textelementnobold#5 "); $$ = newNodeS (TextToken, addSpaces ("{|", $1)); } |
455 | 463 | | TABLEEND { debugf ("textelementnobold#6 "); $$ = newNodeS (TextToken, "|}"); } |
456 | 464 | | TABLEROW { debugf ("textelementnobold#7 "); $$ = convertTableRowToText ($1); } |
— | — | @@ -462,7 +470,6 @@ |
463 | 471 | textelementnoboit : TEXT { debugf ("textelementnoboit#1 "); $$ = $1; } |
464 | 472 | | EXTENSION { debugf ("textelementnoboit#2 "); $$ = $1; } |
465 | 473 | | PIPE { debugf ("textelementnoboit#3 "); $$ = newNodeS (TextToken, "|"); } |
466 | | - | ENDHEADING { debugf ("textelementnoboit#4 "); $$ = processEndHeadingInText ($1); } |
467 | 474 | | TABLEBEGIN { debugf ("textelementnoboit#5 "); $$ = newNodeS (TextToken, addSpaces ("{|", $1)); } |
468 | 475 | | TABLEEND { debugf ("textelementnoboit#6 "); $$ = newNodeS (TextToken, "|}"); } |
469 | 476 | | TABLEROW { debugf ("textelementnoboit#7 "); $$ = convertTableRowToText ($1); } |
— | — | @@ -474,7 +481,6 @@ |
475 | 482 | textelementnotbl : TEXT { debugf ("textelementnotbl#1 "); $$ = $1; } |
476 | 483 | | EXTENSION { debugf ("textelementnotbl#2 "); $$ = $1; } |
477 | 484 | | PIPE { debugf ("textelementnotbl#3 "); $$ = newNodeS (TextToken, "|"); } |
478 | | - | ENDHEADING { debugf ("textelementnotbl#4 "); $$ = processEndHeadingInText ($1); } |
479 | 485 | | APO2 { debugf ("textelementnotbl#5 "); $$ = newNodeS (TextToken, "''"); } |
480 | 486 | | APO3 { debugf ("textelementnotbl#6 "); $$ = newNodeS (TextToken, "'''"); } |
481 | 487 | | APO5 { debugf ("textelementnotbl#7 "); $$ = newNodeS (TextToken, "'''''"); } |
— | — | @@ -486,7 +492,6 @@ |
487 | 493 | textelementnoitaltbl: TEXT { debugf ("textelementnoitaltbl#1 "); $$ = $1; } |
488 | 494 | | EXTENSION { debugf ("textelementnoitaltbl#2 "); $$ = $1; } |
489 | 495 | | PIPE { debugf ("textelementnoitaltbl#3 "); $$ = newNodeS (TextToken, "|"); } |
490 | | - | ENDHEADING { debugf ("textelementnoitaltbl#4 "); $$ = processEndHeadingInText ($1); } |
491 | 496 | | comment { debugf ("textelementnoitaltbl#5 "); $$ = $1; } |
492 | 497 | | linketcnotbl { debugf ("textelementnoitaltbl#6 "); $$ = $1; } |
493 | 498 | | boldnoitalicstbl{ debugf ("textelementnoitaltbl#7 "); $$ = $1; } |
— | — | @@ -494,7 +499,6 @@ |
495 | 500 | textelementnoboldtbl: TEXT { debugf ("textelementnoboldtbl#1 "); $$ = $1; } |
496 | 501 | | EXTENSION { debugf ("textelementnoboldtbl#2 "); $$ = $1; } |
497 | 502 | | PIPE { debugf ("textelementnoboldtbl#3 "); $$ = newNodeS (TextToken, "|"); } |
498 | | - | ENDHEADING { debugf ("textelementnoboldtbl#4 "); $$ = processEndHeadingInText ($1); } |
499 | 503 | | comment { debugf ("textelementnoboldtbl#5 "); $$ = $1; } |
500 | 504 | | linketcnotbl { debugf ("textelementnoboldtbl#6 "); $$ = $1; } |
501 | 505 | | italicsnoboldtbl{ debugf ("textelementnoboldtbl#7 "); $$ = $1; } |
— | — | @@ -502,7 +506,6 @@ |
503 | 507 | textelementnoboittbl: TEXT { debugf ("textelementnoboittbl#1 "); $$ = $1; } |
504 | 508 | | EXTENSION { debugf ("textelementnoboittbl#2 "); $$ = $1; } |
505 | 509 | | PIPE { debugf ("textelementnoboittbl#3 "); $$ = newNodeS (TextToken, "|"); } |
506 | | - | ENDHEADING { debugf ("textelementnoboittbl#4 "); $$ = processEndHeadingInText ($1); } |
507 | 510 | | comment { debugf ("textelementnoboittbl#5 "); $$ = $1; } |
508 | 511 | | linketcnotbl { debugf ("textelementnoboittbl#6 "); $$ = $1; } |
509 | 512 | |
Index: trunk/flexbisonparse/wikilex.l |
— | — | @@ -29,13 +29,28 @@ |
30 | 30 | { |
31 | 31 | int i = 1; |
32 | 32 | while (input[i] == '-') i++; |
33 | | - return ((i-1)*0x10000 + (initleng-i)); |
| 33 | + return (((i-1) << 16) | (initleng-i)); |
34 | 34 | } |
35 | 35 | |
36 | 36 | #define COMMONTOKENS \ |
37 | 37 | if (YY_START != inattributeapo && YY_START != inattributeq && YY_START != canbeheading) \ |
38 | 38 | BEGIN (cannotbelistorheadingorpre); |
39 | 39 | |
| 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 | + |
40 | 55 | %} |
41 | 56 | |
42 | 57 | /* inclusive start conditions */ |
— | — | @@ -122,9 +137,12 @@ |
123 | 138 | \}\}\} { COMMONTOKENS; debuglex ("CLOSETEMPLATEVAR "); return CLOSETEMPLATEVAR; } |
124 | 139 | \{\{ { COMMONTOKENS; debuglex ("OPENTEMPLATE "); return OPENTEMPLATE; } |
125 | 140 | \}\} { 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); } |
129 | 147 | \n { BEGIN (INITIAL); debuglex ("NEWLINE\n"); return NEWLINE; } |
130 | 148 | \r { /* ignore this one */ debuglex ("<13> "); } |
131 | 149 | |
— | — | @@ -140,10 +158,12 @@ |
141 | 159 | debuglex2 ("HEADING(%d) ", yylval.num); |
142 | 160 | return HEADING; |
143 | 161 | } |
144 | | -<canbeheading>"="+" "* { |
| 162 | +<canbeheading>"="+" "*\r\n | |
| 163 | +<canbeheading>"="+" "*\n { |
145 | 164 | yylval.num = 0; |
146 | 165 | while (yytext [ yylval.num ] == '=') |
147 | 166 | yylval.num++; |
| 167 | + yylval.num |= (yyleng-yylval.num) << 16; |
148 | 168 | debuglex2 ("ENDHEADING(%d) ", yylval.num); |
149 | 169 | return ENDHEADING; |
150 | 170 | } |
Index: trunk/flexbisonparse/parsetree.c |
— | — | @@ -295,14 +295,18 @@ |
296 | 296 | Node processEndHeadingInText (int n) |
297 | 297 | { |
298 | 298 | char* ret; |
| 299 | + int equalses, spaces, i; |
299 | 300 | |
300 | | - if (n < 1) return 0; |
301 | | - /* Performance optimisation */ |
302 | | - if (n == 1) return newNodeS (TextToken, "="); |
| 301 | + equalses = n % 0x10000; |
| 302 | + spaces = n >> 16; |
303 | 303 | |
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'; |
307 | 311 | return newNodeS (TextToken, ret); |
308 | 312 | } |
309 | 313 | |
— | — | @@ -557,6 +561,18 @@ |
558 | 562 | return newNodeS (TextToken, addSpaces (info % 2 ? "!" : "!!", info/2)); |
559 | 563 | } |
560 | 564 | |
| 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 | + |
561 | 577 | char* addSpaces (char* src, int spaces) |
562 | 578 | { |
563 | 579 | char* ret; |