r113366 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113365‎ | r113366 | r113367 >
Date:14:24, 8 March 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Temporary fix for template tokenization, especially needed for
[[Template:Cite core]].
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -669,8 +669,12 @@
670670 tplarg_or_template = & '{{{{{' template / tplarg / template
671671
672672 template
673 - = "{{" target:template_param_text
674 - params:(newline? "|" newline? p:template_param { return p })*
 673+ = "{{" (newline / space)* target:template_param_text
 674+ params:(( newline / space )* "|"
 675+ r:( &"|" { return new KV( '', '') } // empty argument
 676+ / newline? p:template_param { return p }
 677+ ) { return r }
 678+ )*
675679 "}}" {
676680 // Insert target as first positional attribute, so that it can be
677681 // generically expanded. The TemplateHandler then needs to shift it out
@@ -720,15 +724,15 @@
721725
722726 // FIXME: handle template args and templates in key! (or even parser functions?)
723727 template_param_name
724 - = & { return setFlag( 'equal' ) }
 728+ = & { return setFlag( 'equalTemplate' ) }
725729 tpt:template_param_text
726730 {
727 - clearFlag( 'equal' );
 731+ clearFlag( 'equalTemplate' );
728732 //console.warn( 'template param name matched: ' + pp( tpt ) );
729733 return tpt;
730734 }
731735
732 - / & { return clearFlag( 'equal' ) }
 736+ / & { return clearFlag( 'equalTemplate' ) }
733737 //= h:( !"}}" x:([^=|\n]) { return x } )* { return h.join(''); }
734738
735739 template_param_text
@@ -740,6 +744,7 @@
741745 }
742746 / & { return clearFlag('template'); }
743747
 748+
744749 // TODO: handle link prefixes as in al[[Razi]]
745750 wikilink
746751 = & { return posStack.push('wikilink' , pos); }
@@ -1101,6 +1106,7 @@
11021107 value:(( space / newline )*
11031108 v:generic_attribute_newline_value { return v })?
11041109 {
 1110+ //console.warn('generic_newline_attribute: ' + pp( name ))
11051111 if ( value !== '' ) {
11061112 return new KV( name, value );
11071113 } else {
@@ -1134,15 +1140,15 @@
11351141 // }
11361142
11371143 generic_attribute_name
1138 - = & { return setFlag( 'equal' ) }
 1144+ = & { return setFlag( 'equalAttrib' ) }
11391145 ! '/>'
11401146 name:attribute_preprocessor_text_line
11411147 {
1142 - clearFlag( 'equal' );
 1148+ clearFlag( 'equalAttrib' );
11431149 //console.warn( 'generic attribute name: ' + pp( name ) );
11441150 return name;
11451151 }
1146 - / & { return clearFlag( 'equal' ) }
 1152+ / & { return clearFlag( 'equalAttrib' ) }
11471153
11481154 // A generic attribute, possibly spanning multiple lines.
11491155 generic_attribute_newline_value
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js
@@ -106,7 +106,10 @@
107107 PegTokenizer.prototype.inline_breaks = function (input, pos, syntaxFlags ) {
108108 switch( input[pos] ) {
109109 case '=':
110 - return syntaxFlags.equal ||
 110+ return ( syntaxFlags.equalAttrib &&
 111+ (syntaxFlags.equalTemplate || ! syntaxFlags.template ) ) ||
 112+ (syntaxFlags.equalTemplate &&
 113+ (syntaxFlags.equalAttrib || syntaxFlags.template)) ||
111114 ( syntaxFlags.h &&
112115 input.substr( pos + 1, 200)
113116 .match(/[ \t]*[\r\n]/) !== null ) || null;
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js
@@ -244,7 +244,7 @@
245245 this.dp ( 'MWParserEnvironment.tokensToString, non-text token: ' +
246246 tstring + JSON.stringify( tokens, null, 2 ) );
247247 //console.trace();
248 - out.push( tstring );
 248+ //out.push( tstring );
249249 }
250250 }
251251 //console.warn( 'MWParserEnvironment.tokensToString result: ' + out.join('') );

Status & tagging log