r109200 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109199‎ | r109200 | r109201 >
Date:20:01, 17 January 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Clean up 'END' token handling a bit.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.Util.js (modified) (history)
  • /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/mediawiki.tokenizer.peg.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt (modified) (history)
  • /trunk/extensions/VisualEditor/tests/parser/parserTests-whitelist.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/parser/parserTests-whitelist.js
@@ -20,7 +20,11 @@
2121 // This is a rare edge case, and the new behavior is arguably more consistent
2222 testWhiteList["5 quotes, code coverage +1 line"] = "<p>'<i></i></p>";
2323
 24+// The comment in the test already suggests this result as correct, but
 25+// supplies the old result without preformatting.
 26+testWhiteList["Bug 6200: Preformatted in <blockquote>"] = "<blockquote data-sourcePos=\"0:12\"><pre>\nBlah</pre></blockquote>";
2427
 28+
2529 // empty table tags / with only a caption are legal in HTML5.
2630 testWhiteList["A table with no data."] = "<table></table>";
2731 testWhiteList["A table with nothing but a caption"] = "<table><caption> caption</caption></table>";
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.QuoteTransformer.js
@@ -38,8 +38,8 @@
3939 this.quoteAndNewlineRank, 'newline' );
4040 dispatcher.addTransform( this.onQuote.bind(this),
4141 this.quoteAndNewlineRank, 'tag', 'mw-quote' );
42 - // Reset internal state when we are done
43 - dispatcher.addTransform( this.reset.bind(this),
 42+ // Treat end-of-input just the same as a newline
 43+ dispatcher.addTransform( this.onNewLine.bind(this),
4444 this.quoteAndNewlineRank, 'end' );
4545 };
4646
Index: trunk/extensions/VisualEditor/modules/parser/ext.Util.js
@@ -1,5 +1,6 @@
22 /**
33 * General utilities for token transforms
 4+ * XXX: move this to MWParserEnvironment?
45 */
56
67 function Util () {
Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -769,7 +769,8 @@
770770 "]]"
771771 // XXX In real MediaWiki, this is a language-dependent positive character
772772 // class. Can we work out a static negative class instead?
773 - trail:(! [ \t(),.:-] tc:text_char { return tc })* {
 773+ // XXX: Exclude uppercase chars from non-latin languages too!
 774+ trail:(! [A-Z \t(),.:-] tc:text_char { return tc })* {
774775 var obj = {
775776 type: 'TAG',
776777 name: 'a',
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js
@@ -49,7 +49,7 @@
5050 out = this.parser.parse(text);
5151 // emit tokens here until we get that to work per toplevelblock in the
5252 // actual tokenizer
53 - this.emit('chunk', out);
 53+ this.emit('chunk', out.concat( [{ type: 'END' }] ) );
5454 this.emit('end');
5555 //} catch (e) {
5656 //err = e;
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.PostExpandParagraphHandler.js
@@ -32,7 +32,7 @@
3333 };
3434
3535 PostExpandParagraphHandler.prototype.reset = function ( token, cb, frame, prevToken ) {
36 - //console.log( 'PostExpandParagraphHandler.reset' );
 36+ //console.log( 'PostExpandParagraphHandler.reset ' + JSON.stringify( this.tokens ) );
3737 if ( this.newLines ) {
3838 return { tokens: this._finish() };
3939 } else {
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js
@@ -18,8 +18,9 @@
1919 this.register( manager );
2020 }
2121
22 -TemplateHandler.prototype.reset = function () {
 22+TemplateHandler.prototype.reset = function ( token ) {
2323 this.resultTokens = [];
 24+ return {token: token};
2425 };
2526
2627 // constants
@@ -34,8 +35,8 @@
3536 this.rank, 'tag', 'templatearg' );
3637
3738 // Reset internal state when the parser pipeline is done
38 - manager.addTransform( this.reset.bind(this),
39 - this.rank, 'end' );
 39+ //manager.addTransform( this.reset.bind(this),
 40+ // this.rank, 'end' );
4041 };
4142
4243
@@ -119,7 +120,20 @@
120121 tokens: [
121122 {
122123 type: 'TEXT',
123 - value: 'Template expansion loop detected!'
 124+ value: 'Template loop detected: '
 125+ },
 126+ {
 127+ type: 'TAG',
 128+ name: 'a',
 129+ attrib: [['href', target]]
 130+ },
 131+ {
 132+ type: 'TEXT',
 133+ value: target
 134+ },
 135+ {
 136+ type: 'ENDTAG',
 137+ name: 'a'
124138 }
125139 ]
126140 };
@@ -186,12 +200,18 @@
187201 };
188202
189203 /**
190 - * Handle the end event by calling our parentCB with notYetDone set to false.
 204+ * Handle the end event emitted by the parser pipeline by calling our parentCB
 205+ * with notYetDone set to false.
191206 */
192 -TemplateHandler.prototype._onEnd = function( ) {
 207+TemplateHandler.prototype._onEnd = function( token ) {
193208 // Encapsulate the template in a single token, which contains all the
194209 // information needed for the editor.
195210 var res = this.resultTokens;
 211+ // Remove 'end' token from end
 212+ if ( res.length && res[res.length - 1].type === 'END' ) {
 213+ res.pop();
 214+ }
 215+
196216 /*
197217 [{
198218 type: 'TAG',
@@ -209,7 +229,6 @@
210230
211231 if ( this.isAsync ) {
212232 this.parentCB( res, false );
213 - this.reset();
214233 } else {
215234 this.result = { tokens: res };
216235 this.reset();

Status & tagging log