Index: trunk/flexbisonparse/wikilex.l |
— | — | @@ -102,13 +102,13 @@ |
103 | 103 | |
104 | 104 | /* For the table-related tokens, we need to remember enough information so that we can |
105 | 105 | * reliably turn things back into text. */ |
106 | | -"{|"" "* { BEGIN(attributes); debuglex ("TABLEBEGIN "); yylval.num = yyleng-2; return TABLEBEGIN; } |
107 | | -"||"" "* { yylval.num = 2*(yyleng-2); BEGIN(attributes); debuglex2 ("TABLECELL(%u) ", yylval.num); return TABLECELL; } |
108 | | -^"|"" "* { 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; } |
| 106 | +"{|"" "* { BEGIN(attributes); debuglex ("TABLEBEGIN "); yylval.num = yyleng-2; return TABLEBEGIN; } |
| 107 | +"||"" "* { BEGIN(attributes); debuglex ("TABLECELL "); yylval.num = 2*(yyleng-2); return TABLECELL; } |
| 108 | +^"|"" "* { BEGIN(attributes); debuglex ("TABLECELL "); yylval.num = 2*(yyleng-1)+1; 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 ("TABLECAPTION "); yylval.num = yyleng-2; return TABLECAPTION; } |
111 | 112 | "|""-"+" "* { BEGIN(attributes); debuglex ("TABLEROW "); yylval.num = encodeTableRowInfo (yytext, yyleng); return TABLEROW; } |
112 | | -"|+"" "* { BEGIN(attributes); debuglex ("TABLECAPTION "); yylval.num = yyleng-2; return TABLECAPTION; } |
113 | 113 | "|}" { BEGIN(cannotbelistorheadingorpre); debuglex ("TABLEEND "); return TABLEEND; } |
114 | 114 | |
115 | 115 | <attributes>[-a-zA-Z:_]+" "* { |
Index: trunk/flexbisonparse/fb_defines.h |
— | — | @@ -8,20 +8,35 @@ |
9 | 9 | ** Originally written 2004 by Timwi |
10 | 10 | **/ |
11 | 11 | |
| 12 | +/* - Lots of debug information |
12 | 13 | |
13 | | -/* Change these to |
14 | | - #define debuglex printf |
15 | | - #define debuglex2 printf |
16 | | - #define debuglex3 printf |
17 | | - to have the lexer output all the tokens generated. */ |
| 14 | +#define debuglex printf |
| 15 | +#define debuglex2 printf |
| 16 | +#define debuglex3 printf |
| 17 | +#define debugf printf |
| 18 | +#define debugpt_end debug_indent--; |
| 19 | +#define debugpt(x) \ |
| 20 | + debug_indent++; \ |
| 21 | + printf ("%s", addSpaces ("", 2*debug_indent)); \ |
| 22 | + printf (x); |
| 23 | +#define debugpt2(x,y) \ |
| 24 | + debug_indent++; \ |
| 25 | + printf ("%s", addSpaces ("", 2*debug_indent)); \ |
| 26 | + printf (x, y); |
| 27 | +#define debugpt3(x,y,z) \ |
| 28 | + debug_indent++; \ |
| 29 | + printf ("%s", addSpaces ("", 2*debug_indent)); \ |
| 30 | + printf (x, y, z); |
18 | 31 | |
| 32 | +/*/ |
| 33 | + |
19 | 34 | #define debuglex(x) |
20 | 35 | #define debuglex2(x,y) |
21 | 36 | #define debuglex3(x,y,z) |
| 37 | +#define debugf(x) |
| 38 | +#define debugpt_end |
| 39 | +#define debugpt(x) |
| 40 | +#define debugpt2(x,y) |
| 41 | +#define debugpt3(x,y,z) |
22 | 42 | |
23 | | - |
24 | | -/* Change this one to |
25 | | - #define debugf printf |
26 | | - to have the parser output all reductions. */ |
27 | | - |
28 | | -#define debugf(x) |
| 43 | +/**/ |
Index: trunk/flexbisonparse/parsetree.c |
— | — | @@ -13,6 +13,18 @@ |
14 | 14 | #include <string.h> |
15 | 15 | #include <stdio.h> |
16 | 16 | |
| 17 | +int debug_indent = 0; |
| 18 | +/* - use this only if you need debug info |
| 19 | +void freeNode (Node node) |
| 20 | +{ |
| 21 | + debugpt3 ("freeNode (%u, %u)\n", node, node->type); |
| 22 | + free (node); |
| 23 | + debugpt_end; |
| 24 | +} |
| 25 | +/*/ |
| 26 | +#define freeNode free |
| 27 | +/**/ |
| 28 | + |
17 | 29 | Node newNode (NodeType newType) |
18 | 30 | { |
19 | 31 | Node result = (Node) malloc (sizeof (struct NodeStruct)); |
— | — | @@ -108,6 +120,8 @@ |
109 | 121 | { |
110 | 122 | Node next, child = node->firstChild; |
111 | 123 | |
| 124 | + debugpt2 ("freeRecursively (%u)\n", node); |
| 125 | + |
112 | 126 | while (child) |
113 | 127 | { |
114 | 128 | next = child->nextSibling; |
— | — | @@ -115,7 +129,9 @@ |
116 | 130 | child = next; |
117 | 131 | } |
118 | 132 | |
119 | | - free (node); |
| 133 | + freeNode (node); |
| 134 | + |
| 135 | + debugpt_end; |
120 | 136 | } |
121 | 137 | |
122 | 138 | void freeRecursivelyWithSiblings (Node node) |
— | — | @@ -299,7 +315,7 @@ |
300 | 316 | examine->nextSibling = tmpnode; |
301 | 317 | } |
302 | 318 | /* Newlines nodes don't have children, no need for freeRecursively */ |
303 | | - free (newlinesnode); |
| 319 | + freeNode (newlinesnode); |
304 | 320 | } |
305 | 321 | examine = examine->nextSibling; |
306 | 322 | } |
— | — | @@ -332,7 +348,7 @@ |
333 | 349 | if (node->type == Paragraph && !node->nextSibling) |
334 | 350 | { |
335 | 351 | ret = node->firstChild; |
336 | | - free (node); |
| 352 | + freeNode (node); |
337 | 353 | return ret; |
338 | 354 | } |
339 | 355 | return node; |
— | — | @@ -416,7 +432,7 @@ |
417 | 433 | examine = examine->nextSibling; |
418 | 434 | /* Free the now-obsolete Italics node */ |
419 | 435 | /* We have attached its children elsewhere, so don't use freeRecursively */ |
420 | | - free (childSibling); |
| 436 | + freeNode (childSibling); |
421 | 437 | } |
422 | 438 | /* Any node that is not an Italics node needs to become attached to one. |
423 | 439 | * (In the above example, this is only Y.) */ |
— | — | @@ -454,7 +470,7 @@ |
455 | 471 | { |
456 | 472 | nodeAddChild (a, b->firstChild); |
457 | 473 | /* We have attached b's children elsewhere, so don't use freeRecursively */ |
458 | | - free (b); |
| 474 | + freeNode (b); |
459 | 475 | return a; |
460 | 476 | } |
461 | 477 | else if (a->type == TextBlock) |
— | — | @@ -475,7 +491,7 @@ |
476 | 492 | if (node->type != AttributeGroup) return 0; |
477 | 493 | |
478 | 494 | /* We've stored the first child in examine, so we can already free the parent */ |
479 | | - free (node); |
| 495 | + freeNode (node); |
480 | 496 | |
481 | 497 | while (examine) /* should be an Attribute node */ |
482 | 498 | { |
— | — | @@ -520,7 +536,7 @@ |
521 | 537 | } |
522 | 538 | prevExamine = examine; |
523 | 539 | examine = examine->nextSibling; |
524 | | - free (prevExamine); |
| 540 | + freeNode (prevExamine); |
525 | 541 | } |
526 | 542 | |
527 | 543 | return ret; |
— | — | @@ -535,16 +551,28 @@ |
536 | 552 | Node convertPipeSeriesToText (Node node) |
537 | 553 | { |
538 | 554 | Node result = 0; |
539 | | - Node nextNode; |
| 555 | + Node nextNode, child; |
540 | 556 | |
| 557 | + debugpt ("convertPipeSeriesToText()\n"); |
| 558 | + |
541 | 559 | while (node) |
542 | 560 | { |
543 | | - result = makeTextBlock2 (result, newNodeS (TextToken, "|"), node->firstChild); |
544 | 561 | nextNode = node->nextSibling; |
545 | | - freeRecursively (node); |
| 562 | + child = node->firstChild; |
| 563 | + |
| 564 | + /* Performance optimisation: Instead of freeing 'node' and creating a new |
| 565 | + * TextToken node, we'll reuse this one! */ |
| 566 | + node->type = TextToken; |
| 567 | + node->data.str = "|"; |
| 568 | + node->nextSibling = 0; |
| 569 | + node->firstChild = 0; |
| 570 | + |
| 571 | + result = makeTextBlock2 (result, node, child); |
546 | 572 | node = nextNode; |
547 | 573 | } |
548 | 574 | |
| 575 | + debugpt_end; |
| 576 | + |
549 | 577 | return result; |
550 | 578 | } |
551 | 579 | |