r110838 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110837‎ | r110838 | r110839 >
Date:11:53, 7 February 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Clean up transform callback interface
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.PostExpandParagraphHandler.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.QuoteTransformer.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.util.TokenCollector.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/ext.core.QuoteTransformer.js
@@ -54,17 +54,15 @@
5555 // the length of quote string. Actual analysis and conversion to the
5656 // appropriate tag tokens is deferred until the next NEWLINE token triggers
5757 // onNewLine.
58 -QuoteTransformer.prototype.onQuote = function ( token, cb, frame, prevToken ) {
 58+QuoteTransformer.prototype.onQuote = function ( token, frame, prevToken ) {
5959 var qlen = token.value.length,
6060 tokens = [], // output tokens
6161 ctx = {
6262 token: token,
63 - cb: cb,
6463 frame: frame,
6564 prevToken: prevToken
6665 },
6766 ctx2 = {
68 - cb: cb,
6967 frame: frame,
7068 prevToken: prevToken
7169 };
@@ -122,7 +120,7 @@
123121 return {};
124122 };
125123
126 -QuoteTransformer.prototype.onAny = function ( token, cb, frame, prevToken ) {
 124+QuoteTransformer.prototype.onAny = function ( token, frame, prevToken ) {
127125 //console.log('qt onAny: ' + JSON.stringify(token, null, 2));
128126 this.currentChunk.push( token );
129127 return {};
@@ -130,7 +128,7 @@
131129
132130 // Handle NEWLINE tokens, which trigger the actual quote analysis on the
133131 // collected quote tokens so far.
134 -QuoteTransformer.prototype.onNewLine = function ( token, cb, frame, prevToken ) {
 132+QuoteTransformer.prototype.onNewLine = function ( token, frame, prevToken ) {
135133 var res;
136134
137135 if( ! this.isActive ) {
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
@@ -199,7 +199,7 @@
200200 * processed tokens.
201201 * @returns {Object} Token(s) and async indication.
202202 */
203 -TokenTransformManager.prototype._transformTagToken = function ( token, cb, phaseEndRank ) {
 203+TokenTransformManager.prototype._transformTagToken = function ( token, phaseEndRank, cbOrPrevToken ) {
204204 // prepend 'any' transformers
205205 var ts = this.transformers.any,
206206 res = { token: token },
@@ -225,7 +225,7 @@
226226 continue;
227227 }
228228 // Transform token with side effects
229 - res = transformer.transform( res.token, cb, this, this.prevToken );
 229+ res = transformer.transform( res.token, this, cbOrPrevToken );
230230 // XXX: Sync transform:
231231 // res = transformer.transform( res.token, this, this.prevToken );
232232 // XXX: Async transform:
@@ -269,7 +269,7 @@
270270 * @param {Array} ts List of token transformers for this token type.
271271 * @returns {Object} Token(s) and async indication.
272272 */
273 -TokenTransformManager.prototype._transformToken = function ( token, cb, phaseEndRank, ts ) {
 273+TokenTransformManager.prototype._transformToken = function ( token, phaseEndRank, ts, cbOrPrevToken ) {
274274 // prepend 'any' transformers
275275 var anyTrans = this.transformers.any;
276276 if ( anyTrans.length ) {
@@ -290,7 +290,7 @@
291291 // XXX: consider moving the rank out of the token itself to avoid
292292 // transformations messing with it in broken ways. Not sure if
293293 // some transformations need to manipulate it though. gwicke
294 - res = transformer.transform( res.token, cb, this, this.prevToken );
 294+ res = transformer.transform( res.token, this, cbOrPrevToken );
295295 if ( !res.token ||
296296 res.token.type !== token.type ) {
297297 this._resetTokenRank ( res, transformer );
@@ -489,26 +489,26 @@
490490
491491 switch ( token.constructor ) {
492492 case String:
493 - res = this._transformToken( token, cb, phaseEndRank, ts.text );
 493+ res = this._transformToken( token, phaseEndRank, ts.text, cb );
494494 break;
495495 case NlTk:
496 - res = this._transformToken( token, cb, phaseEndRank, ts.newline );
 496+ res = this._transformToken( token, phaseEndRank, ts.newline, cb );
497497 break;
498498 case TagTk:
499499 case EndTagTk:
500500 case SelfclosingTagTk:
501 - res = this._transformTagToken( token, cb, phaseEndRank );
 501+ res = this._transformTagToken( token, phaseEndRank, cb );
502502 break;
503503 default:
504504 switch( token.type ) {
505505 case 'COMMENT':
506 - res = this._transformToken( token, cb, phaseEndRank, ts.comment);
 506+ res = this._transformToken( token, phaseEndRank, ts.comment, cb );
507507 break;
508508 case 'END':
509 - res = this._transformToken( token, cb, phaseEndRank, ts.end );
 509+ res = this._transformToken( token, phaseEndRank, ts.end, cb );
510510 break;
511511 default:
512 - res = this._transformToken( token, cb, phaseEndRank, ts.martian );
 512+ res = this._transformToken( token, phaseEndRank, ts.martian, cb );
513513 break;
514514 }
515515 break;
@@ -670,27 +670,27 @@
671671
672672 switch( token.constructor ) {
673673 case String:
674 - res = this._transformToken( token, cb, this.phaseEndRank,
675 - ts.text );
 674+ res = this._transformToken( token, this.phaseEndRank,
 675+ ts.text, this.prevToken );
676676 break;
677677 case NlTk:
678 - res = this._transformToken( token, cb, this.phaseEndRank, ts.newline );
 678+ res = this._transformToken( token, this.phaseEndRank, ts.newline, this.prevToken );
679679 break;
680680 case TagTk:
681681 case EndTagTk:
682682 case SelfclosingTagTk:
683 - res = this._transformTagToken( token, cb, this.phaseEndRank );
 683+ res = this._transformTagToken( token, this.phaseEndRank, this.prevToken );
684684 break;
685685 default:
686686 switch( token.type ) {
687687 case 'COMMENT':
688 - res = this._transformToken( token, cb, this.phaseEndRank, ts.comment );
 688+ res = this._transformToken( token, this.phaseEndRank, ts.comment, this.prevToken );
689689 break;
690690 case 'END':
691 - res = this._transformToken( token, cb, this.phaseEndRank, ts.end );
 691+ res = this._transformToken( token, this.phaseEndRank, ts.end, this.prevToken );
692692 break;
693693 default:
694 - res = this._transformToken( token, cb, this.phaseEndRank, ts.martian );
 694+ res = this._transformToken( token, this.phaseEndRank, ts.martian, this.prevToken );
695695 break;
696696 }
697697 }
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js
@@ -53,7 +53,7 @@
5454 * calls or sets up the callback to _expandTemplate, which then fetches and
5555 * processes the template.
5656 */
57 -TemplateHandler.prototype.onTemplate = function ( token, cb ) {
 57+TemplateHandler.prototype.onTemplate = function ( token, frame, cb ) {
5858 //console.log('onTemplate! ' + JSON.stringify( token, null, 2 ) +
5959 // ' args: ' + JSON.stringify( this.manager.args ));
6060
@@ -353,7 +353,7 @@
354354 /**
355355 * Expand template arguments with tokens from the containing frame.
356356 */
357 -TemplateHandler.prototype.onTemplateArg = function ( token, cb, frame ) {
 357+TemplateHandler.prototype.onTemplateArg = function ( token, frame, cb ) {
358358
359359 var attributes = [{k: token.argname, v: token.defaultvalue}];
360360
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.PostExpandParagraphHandler.js
@@ -31,7 +31,7 @@
3232 this.newlineRank, 'end' );
3333 };
3434
35 -PostExpandParagraphHandler.prototype.reset = function ( token, cb, frame, prevToken ) {
 35+PostExpandParagraphHandler.prototype.reset = function ( token, frame, cb ) {
3636 //console.log( 'PostExpandParagraphHandler.reset ' + JSON.stringify( this.tokens ) );
3737 if ( this.newLines ) {
3838 return { tokens: this._finish() };
@@ -55,7 +55,7 @@
5656
5757 // Handle NEWLINE tokens, which trigger the actual quote analysis on the
5858 // collected quote tokens so far.
59 -PostExpandParagraphHandler.prototype.onNewLine = function ( token, cb, frame, prevToken ) {
 59+PostExpandParagraphHandler.prototype.onNewLine = function ( token, frame, cb ) {
6060 //console.log( 'PostExpandParagraphHandler.onNewLine: ' + JSON.stringify( token, null , 2 ) );
6161 var res;
6262 this.tokens.push( token );
@@ -70,7 +70,7 @@
7171 };
7272
7373
74 -PostExpandParagraphHandler.prototype.onAny = function ( token, cb, frame, prevToken ) {
 74+PostExpandParagraphHandler.prototype.onAny = function ( token, frame, cb ) {
7575 //console.log( 'PostExpandParagraphHandler.onAny' );
7676 this.tokens.push( token );
7777 if ( token.type === 'COMMENT' ||
Index: trunk/extensions/VisualEditor/modules/parser/ext.util.TokenCollector.js
@@ -50,7 +50,7 @@
5151 * Handle the delimiter token.
5252 * XXX: Adjust to sync phase callback when that is modified!
5353 */
54 -TokenCollector.prototype._onDelimiterToken = function ( token, cb, frame ) {
 54+TokenCollector.prototype._onDelimiterToken = function ( token, frame, cb ) {
5555 var res;
5656 if ( this.isActive ) {
5757 // finish processing
@@ -93,7 +93,7 @@
9494 * encountering the delimiter token, and collects all tokens until the end
9595 * token is reached.
9696 */
97 -TokenCollector.prototype._onAnyToken = function ( token, cb, frame ) {
 97+TokenCollector.prototype._onAnyToken = function ( token, frame, cb ) {
9898 // Simply collect anything ordinary in between
9999 this.tokens.push( token );
100100 return { };

Status & tagging log