Index: trunk/extensions/VisualEditor/tests/parser/parserTests.js |
— | — | @@ -58,8 +58,8 @@ |
59 | 59 | |
60 | 60 | var testWhiteList = require('./parserTests-whitelist.js').testWhiteList; |
61 | 61 | |
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']); |
64 | 64 | |
65 | 65 | // WikiDom and serializers |
66 | 66 | //_require(pj('es', 'es.js')); |
— | — | @@ -365,7 +365,7 @@ |
366 | 366 | |
367 | 367 | |
368 | 368 | |
369 | | -ParserTests.prototype.processTest = function (item, pThingy) { |
| 369 | +ParserTests.prototype.processTest = function (item, parserPipeline) { |
370 | 370 | if (!('title' in item)) { |
371 | 371 | console.log(item); |
372 | 372 | throw new Error('Missing title from test case.'); |
— | — | @@ -382,8 +382,8 @@ |
383 | 383 | this.currentItem = item; |
384 | 384 | |
385 | 385 | // Tokenize the input |
386 | | - pThingy.parse(item.input); |
387 | | - var doc = pThingy.document; |
| 386 | + parserPipeline.parse(item.input); |
| 387 | + var doc = parserPipeline.document; |
388 | 388 | |
389 | 389 | // Check for errors |
390 | 390 | if (doc.err) { |
— | — | @@ -396,7 +396,7 @@ |
397 | 397 | |
398 | 398 | if ( this.argv.wikidom ) { |
399 | 399 | // Test HTML DOM -> WikiDOM conversion |
400 | | - this.printWikiDom( pThingy.getWikiDom() ); |
| 400 | + this.printWikiDom( parserPipeline.getWikiDom() ); |
401 | 401 | } |
402 | 402 | |
403 | 403 | } |
— | — | @@ -556,7 +556,7 @@ |
557 | 557 | var config = { |
558 | 558 | parserEnv: {} |
559 | 559 | }; |
560 | | - var pThingy = new ParseThingy(config); |
| 560 | + var parserPipeline = new ParserPipeline( config ); |
561 | 561 | |
562 | 562 | var comments = [], |
563 | 563 | pt = this; |
— | — | @@ -576,7 +576,7 @@ |
577 | 577 | // Add comments to following test. |
578 | 578 | item.comments = comments; |
579 | 579 | comments = []; |
580 | | - pt.processTest(item, pThingy); |
| 580 | + pt.processTest(item, parserPipeline); |
581 | 581 | break; |
582 | 582 | case 'comment': |
583 | 583 | comments.push(item.comment); |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.HTML5TreeBuilder.node.js |
— | — | @@ -3,8 +3,8 @@ |
4 | 4 | * processToken, and it will build you a DOM tree retrievable using .document |
5 | 5 | * or .body(). */ |
6 | 6 | |
7 | | -var events = require('events'); |
8 | | -var HTML5 = require('./html5/index'); |
| 7 | +var events = require('events'), |
| 8 | + HTML5 = require('./html5/index'); |
9 | 9 | |
10 | 10 | FauxHTML5 = {}; |
11 | 11 | |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | var PEG = require('pegjs'), |
11 | 11 | path = require('path'), |
12 | 12 | fs = require('fs'), |
| 13 | + $ = require('jquery'), |
13 | 14 | events = require('events'); |
14 | 15 | |
15 | 16 | function PegTokenizer() { |
Index: trunk/extensions/VisualEditor/modules/parser/parse.js |
— | — | @@ -6,10 +6,10 @@ |
7 | 7 | |
8 | 8 | ( function() { |
9 | 9 | |
10 | | - var ParseThingy = require('./mediawiki.parser.js').ParseThingy, |
| 10 | + var ParserPipeline = require('./mediawiki.parser.js').ParserPipeline, |
11 | 11 | optimist = require('optimist'); |
12 | 12 | |
13 | | - var parser = new ParseThingy(); |
| 13 | + var parser = new ParserPipeline(); |
14 | 14 | |
15 | 15 | |
16 | 16 | process.stdin.resume(); |
— | — | @@ -22,25 +22,10 @@ |
23 | 23 | |
24 | 24 | process.stdin.on( 'end', function() { |
25 | 25 | var input = inputChunks.join(''); |
26 | | - var output = getOutput(parser, input); |
| 26 | + parser.parse( input ); |
| 27 | + var output = parser.getWikiDom(); |
27 | 28 | process.stdout.write( output ); |
28 | 29 | process.exit(0); |
29 | 30 | } ); |
30 | 31 | |
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 | | - |
47 | 32 | } )(); |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js |
— | — | @@ -6,6 +6,10 @@ |
7 | 7 | * @author Neil Kandalgaonkar <neilk@wikimedia.org> |
8 | 8 | */ |
9 | 9 | |
| 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 | + |
10 | 14 | var fs = require('fs'), |
11 | 15 | path = require('path'), |
12 | 16 | PegTokenizer = require('./mediawiki.tokenizer.peg.js').PegTokenizer, |
— | — | @@ -16,7 +20,7 @@ |
17 | 21 | DOMPostProcessor = require('./mediawiki.DOMPostProcessor.js').DOMPostProcessor, |
18 | 22 | DOMConverter = require('./mediawiki.DOMConverter.js').DOMConverter; |
19 | 23 | |
20 | | -function ParseThingy( config ) { |
| 24 | +function ParserPipeline( config ) { |
21 | 25 | // Set up a simple parser pipeline. |
22 | 26 | |
23 | 27 | if ( !config ) { |
— | — | @@ -53,24 +57,27 @@ |
54 | 58 | this.DOMConverter = new DOMConverter(); |
55 | 59 | } |
56 | 60 | |
57 | | -ParseThingy.prototype.parse = function ( text ) { |
| 61 | +ParserPipeline.prototype.parse = function ( text ) { |
58 | 62 | // Set the pipeline in motion by feeding the tokenizer |
59 | 63 | this.wikiTokenizer.tokenize( text ); |
60 | 64 | |
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. |
62 | 69 | this.document = this.treeBuilder.document; |
63 | 70 | |
64 | 71 | //console.log(this.document.body.innerHTML); |
65 | 72 | |
66 | 73 | // 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' |
68 | 75 | // event) |
69 | 76 | this.postProcessor.doPostProcess( this.document ); |
70 | 77 | }; |
71 | 78 | |
72 | | -ParseThingy.prototype.getWikiDom = function () { |
| 79 | +ParserPipeline.prototype.getWikiDom = function () { |
73 | 80 | return JSON.stringify( |
74 | | - pthingy.DOMConverter.HTMLtoWiki( this.document.body ), |
| 81 | + this.DOMConverter.HTMLtoWiki( this.document.body ), |
75 | 82 | null, |
76 | 83 | 2 |
77 | 84 | ); |
— | — | @@ -78,5 +85,5 @@ |
79 | 86 | |
80 | 87 | |
81 | 88 | if (typeof module == "object") { |
82 | | - module.exports.ParseThingy = ParseThingy; |
| 89 | + module.exports.ParserPipeline = ParserPipeline; |
83 | 90 | } |