r113624 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113623‎ | r113624 | r113625 >
Date:14:31, 12 March 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Tolerate more newlines and spaces in templates, and support templates and
comments in urls.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -662,21 +662,25 @@
663663
664664 //[^][<>"\\x00-\\x20\\x7F\p{Zs}]
665665
666 -no_punctuation_char = [^ :\]\[\n"'<>\x00-\x20\x7f,.&%\u00A0\u1680\u180E\u2000-\u200A\u202F\u205F\u3000]
 666+// no punctiation, and '{<' to trigger directives
 667+no_punctuation_char = [^ :\]\[\n"'<>\x00-\x20\x7f,.&%\u00A0\u1680\u180E\u2000-\u200A\u202F\u205F\u3000{]
667668
668669 url
669670 = proto:url_protocol
670671 addr:( ipv6_address / ipv4_address )?
671 - rest:( ( !inline_breaks
 672+ path:( ( !inline_breaks
672673 c:no_punctuation_char
673674 { return c }
674675 )
675676 / s:[.:,] !(space / eolf) { return s }
 677+ / comment
 678+ / tplarg_or_template
676679 / htmlentity
677 - /// urlencoded_char
678 - / [&%] )+
 680+ / [&%{]
 681+ )+
679682 {
680 - return proto + addr + rest.join('');
 683+ //console.warn( "path: " + pp( flatten_stringlist( [proto + addr].concat( path ) ) ) );
 684+ return flatten_string( [proto + addr].concat( path ) );
681685 }
682686
683687 ipv4_address
@@ -710,9 +714,10 @@
711715 = "{{" (newline / space)* target:template_param_text
712716 params:(( newline / space )* "|"
713717 r:( &"|" { return new KV( '', '') } // empty argument
714 - / newline? p:template_param { return p }
 718+ / ( newline / space )* p:template_param { return p }
715719 ) { return r }
716720 )*
 721+ ( newline / space )*
717722 "}}" {
718723 // Insert target as first positional attribute, so that it can be
719724 // generically expanded. The TemplateHandler then needs to shift it out
@@ -730,7 +735,8 @@
731736 tplarg
732737 = "{{{"
733738 name:template_param_text
734 - params:( newline? "|" newline? p:template_param { return p })*
 739+ params:( ( space / newline )* "|" ( space / newline )* p:template_param { return p })*
 740+ ( space / newline )*
735741 "}}}" {
736742 name = flatten( name );
737743 params.unshift( { k: '', v: name } );
@@ -741,17 +747,23 @@
742748
743749 template_param
744750 = name:template_param_name
745 - s0:space*
746 - eq:"="?
747 - s1:space*
748 - value:template_param_value?
 751+ val:(
 752+ s0:space*
 753+ "="
 754+ s1:space*
 755+ value:template_param_value? {
 756+ return { s0: s0, s1: s1, value: value };
 757+ }
 758+ )?
749759
750760 {
751761 //console.warn( 'named template_param matched' + pp([name, value ]) );
752 - if ( value !== '' ) {
753 - return new KV( name, flatten( value ) );
754 - } else if ( eq !== '' ) {
755 - return new KV(flatten( name ), []);
 762+ if ( val !== '' ) {
 763+ if ( val.value !== '' ) {
 764+ return new KV( name, flatten( val.value ) );
 765+ } else {
 766+ return new KV(flatten( name ), []);
 767+ }
756768 } else {
757769 return new KV([], flatten(name));
758770 }

Status & tagging log