r109781 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109780‎ | r109781 | r109782 >
Date:23:21, 22 January 2012
Author:gwicke
Status:deferred
Tags:
Comment:
* Emit token chunks for top-level block elements by patching the source of the
tokenizer
* Fix a bug uncovered by this
* Increase the number of outstanding listeners on a single download to 10000
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.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/mediawiki.TokenTransformManager.js
@@ -417,7 +417,7 @@
418418 if ( ! this.tailAccumulator ) {
419419 this.emit( 'chunk', res.tokens );
420420 } else {
421 - this.tailAccumulator.push( res.tokens );
 421+ this.tailAccumulator.append( res.tokens );
422422 }
423423
424424 if ( res.async ) {
@@ -932,7 +932,17 @@
933933 return this.accum.push(token);
934934 };
935935
 936+/**
 937+ * Append tokens to an accumulator
 938+ *
 939+ * @method
 940+ * @param {Object} token
 941+ */
 942+TokenAccumulator.prototype.append = function ( token ) {
 943+ this.accum = this.accum.concat( token );
 944+};
936945
 946+
937947 /**
938948 * Loop check helper class for AsyncTokenTransformManager.
939949 *
Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -263,7 +263,8 @@
264264 // be part of a stream, only when tokenizing complete
265265 // texts)
266266 //console.log( pp( flatten ( e ) ) );
267 - return flatten(e);
 267+ __parseArgs[2]( [ { type: 'END' } ] );
 268+ return []; //flatten(e);
268269 }
269270
270271
@@ -397,19 +398,21 @@
398399 = & { blockStart = pos; return true; } b:block {
399400 b = flatten(b);
400401 var bs = b[0];
401 - //dp('toplevelblock:' + pp(b));
402 - if (bs.attribs === undefined) {
403 - bs.attribs = [];
 402+ if ( b.length ) {
 403+ //dp('toplevelblock:' + pp(b));
 404+ if (bs.attribs === undefined) {
 405+ bs.attribs = [];
 406+ }
 407+ bs.attribs.push(['data-sourcePos', blockStart + ':' + pos]);
404408 }
405 - bs.attribs.push(['data-sourcePos', blockStart + ':' + pos]);
406409 // XXX: only run this for lines that actually need it!
407410 //b.push({type: 'NEWLINE'});
408411 // Move this to a token stream transform!
409412 //console.log('about to emit' + pp(self));
410 - //console.log( pp( result._tokenizer ));
411 - //console.log('emitted chunk' + pp(b));
 413+ //console.log( '__parseArgs call: ' + pp( b ));
 414+ __parseArgs[2]( flatten( b ) );
412415 //return [];
413 - return b;
 416+ return true;
414417 }
415418
416419 block
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js
@@ -27,7 +27,11 @@
2828 var out, err;
2929 if ( !this.parser ) {
3030 // Only create a single parser, as parse() is a static method.
31 - PegTokenizer.prototype.parser = PEG.buildParser(this.src);
 31+ var parserSource = PEG.buildParser(this.src).toSource();
 32+ parserSource = parserSource.replace( 'parse: function(input, startRule) {',
 33+ 'parse: function(input, startRule) { var __parseArgs = arguments;' );
 34+ //console.log( parserSource );
 35+ PegTokenizer.prototype.parser = eval( parserSource );
3236 // add reference to this for event emission
3337 // XXX: pass a cb into parse() instead, but need to modify pegjs a bit
3438 // for that.
@@ -46,10 +50,10 @@
4751 // reasonable traces. Calling a trace on the extension does not really cut
4852 // it.
4953 //try {
50 - out = this.parser.parse(text);
 54+ this.parser.parse(text, 'start', this.emit.bind( this, 'chunk' ));
5155 // emit tokens here until we get that to work per toplevelblock in the
5256 // actual tokenizer
53 - this.emit('chunk', out.concat( [{ type: 'END' }] ) );
 57+ //this.emit('chunk', out.concat( [{ type: 'END' }] ) );
5458 this.emit('end');
5559 //} catch (e) {
5660 //err = e;
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js
@@ -417,7 +417,7 @@
418418
419419 function TemplateRequest ( manager, title ) {
420420 // Increase the number of maximum listeners a bit..
421 - this.setMaxListeners( 1000 );
 421+ this.setMaxListeners( 10000 );
422422 var self = this,
423423 url = manager.env.wgScriptPath + '/api' +
424424 manager.env.wgScriptExtension +

Status & tagging log