Index: trunk/extensions/VisualEditor/tests/parser/parserTests.js |
— | — | @@ -7,11 +7,13 @@ |
8 | 8 | * |
9 | 9 | * Needs smarter compare, as well as search-y helpers. |
10 | 10 | * |
11 | | - * 2011-07-20 <brion@pobox.com> |
| 11 | + * @author Brion Vibber <brion@pobox.com> |
| 12 | + * @author Gabriel Wicke <gwicke@wikimedia.org> |
| 13 | + * @author Neil Kandalgaonkar <neilk@wikimedia.org> |
12 | 14 | */ |
13 | 15 | |
14 | 16 | (function() { |
15 | | -//"use strict"; |
| 17 | + |
16 | 18 | console.log( "Starting up JS parser tests" ); |
17 | 19 | |
18 | 20 | var fs = require('fs'), |
— | — | @@ -161,10 +163,16 @@ |
162 | 164 | this.cache_file = "parserTests.cache"; |
163 | 165 | |
164 | 166 | // Preload the grammar file... |
165 | | - PegTokenizer.src = fs.readFileSync(path.join(basePath, 'parser', 'pegTokenizer.pegjs.txt'), 'utf8'); |
| 167 | + var peg = fs.readFileSync(path.join(basePath, 'parser', 'pegTokenizer.pegjs.txt'), 'utf8'); |
| 168 | + var parserEnv = {}; |
| 169 | + //var parserEnv = new MWParserEnvironment({ |
| 170 | + // tagHooks: { |
| 171 | + // 'ref': MWRefTagHook, |
| 172 | + // 'references': MWReferencesTagHook |
| 173 | + // } |
| 174 | + //}); |
| 175 | + this.wikiTokenizer = new PegTokenizer(parserEnv, peg); |
166 | 176 | |
167 | | - this.wikiTokenizer = new PegTokenizer(); |
168 | | - |
169 | 177 | this.testFileName = '../../../../phase3/tests/parser/parserTests.txt'; // default |
170 | 178 | this.testFileName2 = '../../../../tests/parser/parserTests.txt'; // Fallback. Not everyone fetch at phase3 level |
171 | 179 | |
— | — | @@ -439,13 +447,7 @@ |
440 | 448 | this.failParseTests++; |
441 | 449 | console.log('PARSE FAIL', res.err); |
442 | 450 | } else { |
443 | | - //var environment = new MWParserEnvironment({ |
444 | | - // tagHooks: { |
445 | | - // 'ref': MWRefTagHook, |
446 | | - // 'references': MWReferencesTagHook |
447 | | - // } |
448 | | - //}); |
449 | | - //var res = es.HtmlSerializer.stringify(tokens,environment); |
| 451 | + //var res = es.HtmlSerializer.stringify(tokens,environment); |
450 | 452 | |
451 | 453 | //Slightly better token output debugging: |
452 | 454 | //console.log( util.inspect( res.tokens, false, null ).yellow); |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js |
— | — | @@ -8,8 +8,9 @@ |
9 | 9 | |
10 | 10 | var PEG = require('pegjs'); |
11 | 11 | |
12 | | -function PegTokenizer(env) { |
| 12 | +function PegTokenizer(env, src) { |
13 | 13 | this.env = env || {}; |
| 14 | + this.src = src; |
14 | 15 | } |
15 | 16 | |
16 | 17 | PegTokenizer.src = false; |
— | — | @@ -17,7 +18,7 @@ |
18 | 19 | PegTokenizer.prototype.tokenize = function( text ) { |
19 | 20 | var out, err; |
20 | 21 | if ( !this.parser ) { |
21 | | - this.parser = PEG.buildParser(PegTokenizer.src); |
| 22 | + this.parser = PEG.buildParser(this.src); |
22 | 23 | } |
23 | 24 | try { |
24 | 25 | out = this.parser.parse(text); |