r111921 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111920‎ | r111921 | r111922 >
Date:11:07, 20 February 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Set up token stream transformers from a map of phases per input content type.
Not yet applied to attribute pipeline creation. 249 tests passing.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js
@@ -47,6 +47,7 @@
4848 // others for serialized tokens etc
4949 inputType = 'text/wiki';
5050 }
 51+ this.inputType = inputType;
5152
5253
5354 // XXX: create a full-fledged environment based on
@@ -58,11 +59,10 @@
5960 }
6061
6162 // set up a sub-pipeline cache
62 - this.pipelineCache = {
63 - 'text/wiki': {
64 - 'input': [],
65 - 'attribute': []
66 - }
 63+ this.pipelineCache = {};
 64+ this.pipelineCache[this.inputType] = {
 65+ 'input': [],
 66+ 'attribute': []
6767 };
6868
6969 // Create an input pipeline for the given input type.
@@ -76,9 +76,10 @@
7777
7878
7979 // Add token transformations..
80 - new QuoteTransformer( this.tokenPostProcessor );
81 - new PostExpandParagraphHandler( this.tokenPostProcessor );
82 - new Sanitizer( this.tokenPostProcessor );
 80+ this._addTransformers( this.inputType, 'sync23', this.tokenPostProcessor, false );
 81+ //new QuoteTransformer( this.tokenPostProcessor );
 82+ //new PostExpandParagraphHandler( this.tokenPostProcessor );
 83+ //new Sanitizer( this.tokenPostProcessor );
8384
8485 //var citeExtension = new Cite( this.tokenTransformer );
8586
@@ -128,7 +129,59 @@
129130 ParserPipeline.prototype = new events.EventEmitter();
130131 ParserPipeline.prototype.constructor = ParserPipeline;
131132
 133+
 134+/**
 135+ * Token stream transformations to register by type and per phase. The
 136+ * possible ranks for individual transformation registrations are [0,1)
 137+ * (excluding 1.0) for sync01, [1,2) for async12 and [2,3) for sync23.
 138+ */
 139+ParserPipeline.prototype._transformers = {
 140+ 'text/wiki': {
 141+ // Synchronous in-order per input
 142+ sync01:
 143+ [
 144+ IncludeOnly,
 145+ NoInclude
 146+ ],
 147+ // Asynchronous out-of-order per input
 148+ async12:
 149+ [
 150+ TemplateHandler,
 151+ AttributeExpander
 152+ ],
 153+ // Synchronous in-order on fully expanded token stream (including
 154+ // expanded templates etc).
 155+ sync23:
 156+ [
 157+ QuoteTransformer,
 158+ PostExpandParagraphHandler,
 159+ /* Cite, */
 160+ Sanitizer
 161+ ]
 162+ }
 163+};
 164+
132165 /**
 166+ * Add all transformers to a token transform manager for a given input type
 167+ * and phase.
 168+ */
 169+ParserPipeline.prototype._addTransformers = function ( type, phase, manager, isInclude )
 170+{
 171+ var transformers;
 172+ try {
 173+ transformers = this._transformers[type][phase];
 174+ } catch ( e ) {
 175+ console.warn( 'Error while looking for token transformers for ' +
 176+ type + ' and phase ' + phase );
 177+ transformers = [];
 178+ }
 179+ for ( var i = 0, l = transformers.length; i < l; i++ ) {
 180+ new transformers[i]( manager, isInclude );
 181+ }
 182+};
 183+
 184+
 185+/**
133186 * Factory method for the input (up to async token transforms / phase two)
134187 * parts of the parser pipeline.
135188 *
@@ -163,10 +216,10 @@
164217 var tokenPreProcessor = new TokenTransformManager.SyncTokenTransformManager ( this.env );
165218 tokenPreProcessor.listenForTokensFrom ( wikiTokenizer );
166219
167 - new IncludeOnly( tokenPreProcessor, ! isNoInclude );
168 - // Add noinclude transform for now
169 - new NoInclude( tokenPreProcessor, ! isNoInclude );
 220+ this._addTransformers( 'text/wiki', 'sync01',
 221+ tokenPreProcessor, ! isNoInclude );
170222
 223+
171224 var tokenExpander = new TokenTransformManager.AsyncTokenTransformManager (
172225 {
173226 'input': this.makeInputPipeline.bind( this ),
@@ -176,8 +229,10 @@
177230 );
178231
179232 // Register template expansion extension
180 - new TemplateHandler( tokenExpander );
181 - new AttributeExpander( tokenExpander );
 233+ this._addTransformers( 'text/wiki', 'async12',
 234+ tokenExpander, ! isNoInclude );
 235+ //new TemplateHandler( tokenExpander );
 236+ //new AttributeExpander( tokenExpander );
182237
183238 tokenExpander.listenForTokensFrom ( tokenPreProcessor );
184239 // XXX: hack.

Status & tagging log