r107995 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107994‎ | r107995 | r107996 >
Date:08:39, 4 January 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Rename ParseThingy to ParserPipeline and fix up broken WikiDom generation and
commandline runner.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.HTML5TreeBuilder.node.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/parse.js (modified) (history)
  • /trunk/extensions/VisualEditor/tests/parser/parserTests.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/parser/parserTests.js
@@ -58,8 +58,8 @@
5959
6060 var testWhiteList = require('./parserTests-whitelist.js').testWhiteList;
6161
62 -_import(pj('parser', 'mediawiki.parser.environment.js'), ['MWParserEnvironment']);
63 -_import(pj('parser', 'mediawiki.parser.js'), ['ParseThingy']);
 62+//_import(pj('parser', 'mediawiki.parser.environment.js'), ['MWParserEnvironment']);
 63+_import(pj('parser', 'mediawiki.parser.js'), ['ParserPipeline']);
6464
6565 // WikiDom and serializers
6666 //_require(pj('es', 'es.js'));
@@ -365,7 +365,7 @@
366366
367367
368368
369 -ParserTests.prototype.processTest = function (item, pThingy) {
 369+ParserTests.prototype.processTest = function (item, parserPipeline) {
370370 if (!('title' in item)) {
371371 console.log(item);
372372 throw new Error('Missing title from test case.');
@@ -382,8 +382,8 @@
383383 this.currentItem = item;
384384
385385 // Tokenize the input
386 - pThingy.parse(item.input);
387 - var doc = pThingy.document;
 386+ parserPipeline.parse(item.input);
 387+ var doc = parserPipeline.document;
388388
389389 // Check for errors
390390 if (doc.err) {
@@ -396,7 +396,7 @@
397397
398398 if ( this.argv.wikidom ) {
399399 // Test HTML DOM -> WikiDOM conversion
400 - this.printWikiDom( pThingy.getWikiDom() );
 400+ this.printWikiDom( parserPipeline.getWikiDom() );
401401 }
402402
403403 }
@@ -556,7 +556,7 @@
557557 var config = {
558558 parserEnv: {}
559559 };
560 - var pThingy = new ParseThingy(config);
 560+ var parserPipeline = new ParserPipeline( config );
561561
562562 var comments = [],
563563 pt = this;
@@ -576,7 +576,7 @@
577577 // Add comments to following test.
578578 item.comments = comments;
579579 comments = [];
580 - pt.processTest(item, pThingy);
 580+ pt.processTest(item, parserPipeline);
581581 break;
582582 case 'comment':
583583 comments.push(item.comment);
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.HTML5TreeBuilder.node.js
@@ -3,8 +3,8 @@
44 * processToken, and it will build you a DOM tree retrievable using .document
55 * or .body(). */
66
7 -var events = require('events');
8 -var HTML5 = require('./html5/index');
 7+var events = require('events'),
 8+ HTML5 = require('./html5/index');
99
1010 FauxHTML5 = {};
1111
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js
@@ -9,6 +9,7 @@
1010 var PEG = require('pegjs'),
1111 path = require('path'),
1212 fs = require('fs'),
 13+ $ = require('jquery'),
1314 events = require('events');
1415
1516 function PegTokenizer() {
Index: trunk/extensions/VisualEditor/modules/parser/parse.js
@@ -6,10 +6,10 @@
77
88 ( function() {
99
10 - var ParseThingy = require('./mediawiki.parser.js').ParseThingy,
 10+ var ParserPipeline = require('./mediawiki.parser.js').ParserPipeline,
1111 optimist = require('optimist');
1212
13 - var parser = new ParseThingy();
 13+ var parser = new ParserPipeline();
1414
1515
1616 process.stdin.resume();
@@ -22,25 +22,10 @@
2323
2424 process.stdin.on( 'end', function() {
2525 var input = inputChunks.join('');
26 - var output = getOutput(parser, input);
 26+ parser.parse( input );
 27+ var output = parser.getWikiDom();
2728 process.stdout.write( output );
2829 process.exit(0);
2930 } );
3031
31 - /**
32 - * @param {ParseThingy} parser
33 - * @param {String} text
34 - */
35 - function getOutput( parser, input ) {
36 - var res = parser.wikiTokenizer.tokenize(input);
37 - if (res.err) {
38 - console.log('PARSE FAIL', res.err);
39 - process.exit(1);
40 - }
41 -
42 - parser.tokenDispatcher.transformTokens( res.tokens );
43 -
44 - return parser.getWikiDom();
45 - }
46 -
4732 } )();
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js
@@ -6,6 +6,10 @@
77 * @author Neil Kandalgaonkar <neilk@wikimedia.org>
88 */
99
 10+// make this global for now
 11+// XXX: figure out a way to get away without a global for PEG actions!
 12+$ = require('jquery');
 13+
1014 var fs = require('fs'),
1115 path = require('path'),
1216 PegTokenizer = require('./mediawiki.tokenizer.peg.js').PegTokenizer,
@@ -16,7 +20,7 @@
1721 DOMPostProcessor = require('./mediawiki.DOMPostProcessor.js').DOMPostProcessor,
1822 DOMConverter = require('./mediawiki.DOMConverter.js').DOMConverter;
1923
20 -function ParseThingy( config ) {
 24+function ParserPipeline( config ) {
2125 // Set up a simple parser pipeline.
2226
2327 if ( !config ) {
@@ -53,24 +57,27 @@
5458 this.DOMConverter = new DOMConverter();
5559 }
5660
57 -ParseThingy.prototype.parse = function ( text ) {
 61+ParserPipeline.prototype.parse = function ( text ) {
5862 // Set the pipeline in motion by feeding the tokenizer
5963 this.wikiTokenizer.tokenize( text );
6064
61 - // XXX: this will have to happen in a callback!
 65+ // XXX: Convert parse to an async pipeline as well!
 66+ // The remaining processing below will have to happen in a callback,
 67+ // triggered on the treeBuilder 'end' event, followed by an event emission
 68+ // or callback calling instead of returning.
6269 this.document = this.treeBuilder.document;
6370
6471 //console.log(this.document.body.innerHTML);
6572
6673 // Perform synchronous post-processing on DOM.
67 - // XXX: convert to event listener (listening on treeBuilder 'finished'
 74+ // XXX: convert to event listener (listening on treeBuilder 'end'
6875 // event)
6976 this.postProcessor.doPostProcess( this.document );
7077 };
7178
72 -ParseThingy.prototype.getWikiDom = function () {
 79+ParserPipeline.prototype.getWikiDom = function () {
7380 return JSON.stringify(
74 - pthingy.DOMConverter.HTMLtoWiki( this.document.body ),
 81+ this.DOMConverter.HTMLtoWiki( this.document.body ),
7582 null,
7683 2
7784 );
@@ -78,5 +85,5 @@
7986
8087
8188 if (typeof module == "object") {
82 - module.exports.ParseThingy = ParseThingy;
 89+ module.exports.ParserPipeline = ParserPipeline;
8390 }

Status & tagging log