r101029 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101028‎ | r101029 | r101030 >
Date:19:46, 27 October 2011
Author:gwicke
Status:deferred
Tags:parserplayground 
Comment:
Slowly starting WikiDomization of parser structure
Modified paths:
  • /trunk/extensions/ParserPlayground/modules/ext.parserPlayground.renderer.js (modified) (history)
  • /trunk/extensions/ParserPlayground/modules/pegParser.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.renderer.js
@@ -128,10 +128,10 @@
129129 case 'dd':
130130 case 'li':
131131 case 'table':
132 - case 'table_row':
133 - case 'table_caption':
134 - case 'table_data':
135 - case 'table_header':
 132+ case 'tableRow':
 133+ case 'tableCaption':
 134+ case 'tableCell':
 135+ case 'tableHeader':
136136 var $span = $('<' + tree.type + '>');
137137 if ('attrs' in tree) {
138138 $.map(tree.attrs, function(val, key) {
Index: trunk/extensions/ParserPlayground/modules/pegParser.pegjs.txt
@@ -539,26 +539,30 @@
540540 /* Tables */
541541
542542 table
543 - = table_start c:table_caption? b:table_body? table_end {
544 - var res = null;
 543+ = tas:table_start c:table_caption? b:table_body? table_end {
 544+ var res = {type: 'table'}
545545 var body = b !== '' ? b : [];
546546 if (c !== '') {
547 - res = {type: 'table', content: [c].concat(body)};
 547+ res.content = [c].concat(body);
548548 } else {
549 - res = {type: 'table', content: body };
 549+ res.content = body;
550550 }
551 - //console.log(print_r(res));
 551+ if (tas.length > 0) {
 552+ // FIXME: actually parse and build structure
 553+ res.attributes = { unparsed: tas }
 554+ }
 555+ console.log(print_r(res));
552556 return res;
553557 }
554558
555 -table_start = "{|" table_attribs* space* newline?
 559+table_start = "{|" ta:table_attribs* space* newline? { return ta }
556560
557561 table_attribs = anything
558562
559563 table_caption
560564 = "|+" c:(inline_element / anything / [^\n])* newline? {
561565 return {
562 - type: 'table_caption',
 566+ type: 'tableCaption',
563567 content: c
564568 }
565569 }
@@ -577,7 +581,7 @@
578582 table_firstrow
579583 = td:table_data+ {
580584 return {
581 - type: 'table_row',
 585+ type: 'tableRow',
582586 content: td
583587 };
584588 }
@@ -585,28 +589,33 @@
586590 table_row
587591 = "|-" space* newline? td:(table_data / table_header)* {
588592 return {
589 - type: 'table_row',
 593+ type: 'tableRow',
590594 content: td
591595 };
592596 }
593597
 598+/* TODO: Allow general block-level or inline elements, except if they span a
 599+ * source line starting with a pipe. To avoid duplicating all block-level
 600+ * productions, a quick check if a potential block-level match spanned a line
 601+ * starting with a pipe might be used. Checking this requires access to the
 602+ * matched source string. */
594603 table_data
595604 = t:table {
596 - console.log("recursive table result:" + print_r(t));
 605+ //console.log("recursive table result:" + print_r(t));
597606 return {
598 - type: 'table_data',
 607+ type: 'tableCell',
599608 content: [t]
600609 }
601610 }
602611 / "||" td_attr? td:[^|]* newline? {
603612 return {
604 - type: 'table_data',
 613+ type: 'tableCell',
605614 content: td.join('')
606615 };
607616 }
608617 / "|" ![}+-] td_attr? td:[^|\n]* newline? {
609618 return {
610 - type: 'table_data',
 619+ type: 'tableCell',
611620 content: td.join('')
612621 };
613622 }
@@ -616,15 +625,22 @@
617626 table_header
618627 = "!!" c:(block/ inline_element / text / ("!" !"!") / [^!\n])* newline? {
619628 return {
620 - type: 'table_header',
 629+ type: 'tableHeader',
621630 content: c
622631 }
623632 }
624633 / "!" c:(block/ inline_element / text / '!' !'!' / [^!\n])* newline? {
625634 return {
626 - type: 'table_header',
 635+ type: 'tableHeader',
627636 content: c
628637 }
629638 }
630639
631640 table_end = "|}" newline?
 641+
 642+
 643+/* Wikidom TODO:
 644+ * split off text into content nodes
 645+ * convert inlines into annotations
 646+ * change contents into children
 647+ */

Status & tagging log