r105432 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105431‎ | r105432 | r105433 >
Date:15:39, 7 December 2011
Author:gwicke
Status:deferred
Tags:
Comment:
Convert template argument production to generic inline with syntactic stop.
Fix a bug in generic inline production. Nested multi-line templates are now
parsed okayish.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/pegParser.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/pegParser.pegjs.txt
@@ -588,26 +588,29 @@
589589 / & { return syntaxFlags['extlink']; } "]" { return true; }
590590 / & { return syntaxFlags['linkdesc']; } link_end { return true; }
591591 / & { return syntaxFlags['h']; } '='+ space* newline { return true; }
 592+ / & { return syntaxFlags['template']; } ('|' / '}}') { return true; }
592593
593594 inline
594 - = c:(urltext / inline_element / (!inline_breaks ch:. { return ch; }))+ {
 595+ = c:(urltext / (! inline_breaks (inline_element / . )))+ {
595596 var out = [];
596597 var text = [];
597598 c = flatten(c);
598 - for (var i = 0; i < c.length; i++) {
599 - if (typeof c[i] == 'string') {
600 - text.push(c[i]);
 599+ for (var i = 0, l = c.length; i < l; i++) {
 600+ var ci = c[i];
 601+ if (typeof ci == 'string') {
 602+ text.push(ci);
601603 } else {
602604 if (text.length) {
603605 out.push({ type: "TEXT", value: text.join('') });
604606 text = [];
605607 }
606 - out.concat(c[i]);
 608+ out.push(ci);
607609 }
608610 }
609611 if (text.length) {
610612 out.push({ type: 'TEXT', value: text.join('') });
611613 }
 614+ //dp('inline out:' + pp(out));
612615 return out;
613616 }
614617
@@ -618,20 +621,21 @@
619622 var text = [];
620623 c = flatten(c);
621624 for (var i = 0; i < c.length; i++) {
622 - if (typeof c[i] == 'string') {
623 - text.push(c[i]);
 625+ var ci = c[i]
 626+ if (typeof ci == 'string') {
 627+ text.push(ci);
624628 } else {
625629 if (text.length) {
626630 out.push({type: 'TEXT', value: text.join('')});
627631 text = [];
628632 }
629 - out.push(c[i]);
 633+ out.push(ci);
630634 }
631635 }
632636 if (text.length) {
633637 out.push({type: 'TEXT', value: text.join('')});
634638 }
635 - dp('inlineline out:', pp(out));
 639+ //dp('inlineline out:' + pp(out));
636640 return out;
637641 }
638642
@@ -775,7 +779,9 @@
776780 //[^][<>"\\x00-\\x20\\x7F\p{Zs}]
777781
778782 template
779 - = "{{" target:template_target params:("|" p:template_param { return p })* "}}" {
 783+ = "{{" target:template_target
 784+ params:(newline? "|" newline? p:template_param { return p })*
 785+ "}}" {
780786 var obj = { type: 'TAG', name: 'template',
781787 attribs: [['target', target]],
782788 args: {}}
@@ -798,29 +804,28 @@
799805 // parser only recognizes known self-closing tags for now, so use an
800806 // explicit end tag for now.
801807 //console.log(pp(obj));
802 - return [obj, {type: 'ENDTAG', name: 'template'}];
 808+ return obj;
803809 }
804810
805811 template_target
806812 = h:( !"}}" x:([^|\n]) { return x } )* { return h.join(''); }
807813
808 -/* XXX: pass these as convenient js structures to later stages, but serialize
809 - * (to json) before passing remaining args to the tree builder */
810814 template_param
811 - = name:template_param_name "=" c:template_param_text {
 815+ = name:template_param_name space* "=" space* c:template_param_text {
812816 return [name, c];
813817 } / c:template_param_text {
814818 return [null, c];
815819 }
816820
817821 tplarg
818 - = "{{{" name:link_target params:("|" ! "}}}" p:template_param { return p })* "}}}" {
 822+ = "{{{" name:link_target params:("|" p:template_param { return p })* "}}}" {
819823 var obj = {
820824 type: 'SELFCLOSINGTAG',
821825 name: 'templatearg',
822826 attribs: [['argname', name]]
823827 };
824828 if (params && params.length) {
 829+ // HACK, not final.
825830 obj.attribs.push(['data-args', JSON.stringify(params)]);
826831 }
827832 return obj;
@@ -829,23 +834,24 @@
830835 template_param_name
831836 = h:( !"}}" x:([^=|\n]) { return x } )* { return h.join(''); }
832837
 838+// XXX: convert to inlineline with syntactic stop on "}}"
833839 template_param_text
834 - = tcs:template_param_text_chunk* { return JSON.stringify(tcs); }
835 - //= h:( !"}}" x:([^|]) { return x } )* { return h.join(''); }
 840+ = & { return setFlag('template') }
 841+ il:inline+ {
 842+ clearFlag('template');
 843+ return il;
 844+ }
 845+ / & { clearFlag('template'); return false; }
 846+// urltext
 847+// / xmlish_tag
 848+// / extlink
 849+// / template
 850+// / tplarg
 851+// / wikilink
 852+// / quote
 853+// / c:[^}|\n]+ {return {type: 'TEXT', value: c.join('')}}
 854+// / !"}}" x:([^|\n]) { return {type: 'TEXT', value: x} }
836855
837 -
838 -// XXX: convert to inlineline with syntactic stop on "}}"
839 -template_param_text_chunk
840 - = comment
841 - / xmlish_tag
842 - / extlink
843 - / template
844 - / tplarg
845 - / wikilink
846 - / quote
847 - / c:[^}|\n]+ {return {type: 'TEXT', value: c.join('')}}
848 - / !"}}" x:([^|\n]) { return {type: 'TEXT', value: x} }
849 -
850856 wikilink
851857 = "[["
852858 ! url

Status & tagging log