Index: trunk/extensions/VisualEditor/tests/parser/parserTests.js |
— | — | @@ -183,7 +183,10 @@ |
184 | 184 | this.failOutputTests = 0; |
185 | 185 | |
186 | 186 | // Create a new parser environment |
187 | | - this.env = new MWParserEnvironment({ fetchTemplates: false }); |
| 187 | + this.env = new MWParserEnvironment({ |
| 188 | + fetchTemplates: false, |
| 189 | + debug: false |
| 190 | + }); |
188 | 191 | } |
189 | 192 | |
190 | 193 | |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.NoOnlyInclude.js |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | new TokenCollector( |
13 | 13 | manager, |
14 | 14 | function ( tokens ) { |
15 | | - //manager.env.dp( 'noinclude stripping', tokens ); |
| 15 | + manager.env.dp( 'noinclude stripping', tokens ); |
16 | 16 | return {}; |
17 | 17 | }, // just strip it all.. |
18 | 18 | true, // match the end-of-input if </noinclude> is missing |
Index: trunk/extensions/VisualEditor/modules/parser/parse.js |
— | — | @@ -20,7 +20,7 @@ |
21 | 21 | wgScriptExtension: ".php", |
22 | 22 | fetchTemplates: true, |
23 | 23 | // enable/disable debug output using this switch |
24 | | - debug: false |
| 24 | + debug: true |
25 | 25 | } ), |
26 | 26 | parser = new ParserPipeline( env ); |
27 | 27 | |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js |
— | — | @@ -16,8 +16,9 @@ |
17 | 17 | PegTokenizer = require('./mediawiki.tokenizer.peg.js').PegTokenizer, |
18 | 18 | TokenTransformManager = require('./mediawiki.TokenTransformManager.js'), |
19 | 19 | |
20 | | - NoInclude = require('./ext.core.NoOnlyInclude.js').NoInclude, |
21 | | - OnlyInclude = require('./ext.core.NoOnlyInclude.js').OnlyInclude, |
| 20 | + NoOnlyInclude = require('./ext.core.NoOnlyInclude.js'), |
| 21 | + OnlyInclude = NoOnlyInclude.OnlyInclude, |
| 22 | + NoInclude = NoOnlyInclude.NoInclude, |
22 | 23 | QuoteTransformer = require('./ext.core.QuoteTransformer.js').QuoteTransformer, |
23 | 24 | PostExpandParagraphHandler = require('./ext.core.PostExpandParagraphHandler.js') |
24 | 25 | .PostExpandParagraphHandler, |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js |
— | — | @@ -291,15 +291,15 @@ |
292 | 292 | TemplateHandler.prototype._fetchTemplateAndTitle = function ( title, callback, tplExpandData ) { |
293 | 293 | // @fixme normalize name? |
294 | 294 | var self = this; |
295 | | - if (this.manager.env.pageCache[title]) { |
296 | | - // Unroll the stack here |
| 295 | + if ( title in this.manager.env.pageCache ) { |
| 296 | + // Unwind the stack |
297 | 297 | process.nextTick( |
298 | 298 | function () { |
299 | 299 | callback( self.manager.env.pageCache[title], title ) |
300 | 300 | } |
301 | 301 | ); |
302 | 302 | } else if ( ! this.manager.env.fetchTemplates ) { |
303 | | - callback('Page/template fetching disabled, and no cache for ' + title); |
| 303 | + callback( 'Page/template fetching disabled, and no cache for ' + title, title ); |
304 | 304 | } else { |
305 | 305 | |
306 | 306 | // We are about to start an async request for a template, so mark this |
— | — | @@ -406,11 +406,8 @@ |
407 | 407 | //console.log( 'response for ' + title + ' :' + body + ':' ); |
408 | 408 | if(error) { |
409 | 409 | manager.env.dp(error); |
410 | | - callback('Page/template fetch failure for title ' + title, title); |
411 | | - return ; |
412 | | - } |
413 | | - |
414 | | - if(response.statusCode == 200) { |
| 410 | + self.emit('src', 'Page/template fetch failure for title ' + title, title); |
| 411 | + } else if(response.statusCode == 200) { |
415 | 412 | var src = ''; |
416 | 413 | try { |
417 | 414 | //console.log( 'body: ' + body ); |
— | — | @@ -438,9 +435,11 @@ |
439 | 436 | manager.env.pageCache[title] = src; |
440 | 437 | manager.env.dp(data); |
441 | 438 | self.emit( 'src', src, title ); |
442 | | - // Remove self from request queue |
443 | | - delete manager.env.requestQueue[title]; |
444 | 439 | } |
| 440 | + // XXX: handle other status codes |
| 441 | + |
| 442 | + // Remove self from request queue |
| 443 | + delete manager.env.requestQueue[title]; |
445 | 444 | }); |
446 | 445 | } |
447 | 446 | |
Index: trunk/extensions/VisualEditor/modules/parser/ext.util.TokenCollector.js |
— | — | @@ -51,28 +51,39 @@ |
52 | 52 | * XXX: Adjust to sync phase callback when that is modified! |
53 | 53 | */ |
54 | 54 | TokenCollector.prototype._onDelimiterToken = function ( token, cb, frame ) { |
55 | | - this.manager.addTransform( this._onAnyToken.bind ( this ), |
56 | | - this.rank + this._anyDelta, 'any' ); |
57 | | - this.tokens.push ( token ); |
58 | | - if ( ! this.isActive ) { |
59 | | - this.isActive = true; |
60 | | - this.cb = cb; |
61 | | - return { async: true }; |
62 | | - } else if ( token.type !== 'end' || this.toEnd ) { |
63 | | - // end token |
64 | | - var res = this.transformation ( this.tokens, this.cb, this.manager ); |
65 | | - this.tokens = []; |
| 55 | + var res; |
| 56 | + if ( this.isActive ) { |
| 57 | + // finish processing |
| 58 | + this.tokens.push ( token ); |
| 59 | + this.isActive = false; |
66 | 60 | this.manager.removeTransform( this.rank + this._anyDelta, 'any' ); |
67 | | - this.isActive = false; |
68 | | - // Transformation can be either sync or async, but receives all collected |
69 | | - // tokens instead of a single token. |
70 | | - return res; |
71 | | - // XXX sync version: return tokens |
72 | | - } else if ( token.type === 'end' && ! this.toEnd ) { |
| 61 | + if ( token.type !== 'END' || this.toEnd ) { |
| 62 | + // end token |
| 63 | + res = this.transformation ( this.tokens, this.cb, this.manager ); |
| 64 | + this.tokens = []; |
| 65 | + // Transformation can be either sync or async, but receives all collected |
| 66 | + // tokens instead of a single token. |
| 67 | + return res; |
| 68 | + // XXX sync version: return tokens |
| 69 | + } else { |
| 70 | + // just return collected tokens |
| 71 | + res = this.tokens; |
| 72 | + this.tokens = []; |
| 73 | + return { tokens: res }; |
| 74 | + } |
| 75 | + } else if ( token.type !== 'END' ) { |
| 76 | + this.manager.env.dp( 'starting collection on ', token ); |
| 77 | + // start collection |
| 78 | + this.tokens.push ( token ); |
| 79 | + this.manager.addTransform( this._onAnyToken.bind ( this ), |
| 80 | + this.rank + this._anyDelta, 'any' ); |
73 | 81 | // Did not encounter a matching end token before the end, and are not |
74 | 82 | // supposed to collect to the end. So just return the tokens verbatim. |
75 | | - this.isActive = false; |
76 | | - return { tokens: this.tokens }; |
| 83 | + this.isActive = true; |
| 84 | + return { }; |
| 85 | + } else { |
| 86 | + // pass through end token |
| 87 | + return { token: token }; |
77 | 88 | } |
78 | 89 | }; |
79 | 90 | |