diff --git a/modules/parser/mediawiki.tokenizer.peg.js b/modules/parser/mediawiki.tokenizer.peg.js index 35a42e71bb..b42a2574e4 100644 --- a/modules/parser/mediawiki.tokenizer.peg.js +++ b/modules/parser/mediawiki.tokenizer.peg.js @@ -8,8 +8,9 @@ var PEG = require('pegjs'); -function PegTokenizer(env) { +function PegTokenizer(env, src) { this.env = env || {}; + this.src = src; } PegTokenizer.src = false; @@ -17,7 +18,7 @@ PegTokenizer.src = false; PegTokenizer.prototype.tokenize = function( text ) { var out, err; if ( !this.parser ) { - this.parser = PEG.buildParser(PegTokenizer.src); + this.parser = PEG.buildParser(this.src); } try { out = this.parser.parse(text); diff --git a/tests/parser/parserTests.js b/tests/parser/parserTests.js index a54989331e..ce8e382c15 100644 --- a/tests/parser/parserTests.js +++ b/tests/parser/parserTests.js @@ -7,11 +7,13 @@ * * Needs smarter compare, as well as search-y helpers. * - * 2011-07-20 + * @author Brion Vibber + * @author Gabriel Wicke + * @author Neil Kandalgaonkar */ (function() { -//"use strict"; + console.log( "Starting up JS parser tests" ); var fs = require('fs'), @@ -161,9 +163,15 @@ function ParserTests () { this.cache_file = "parserTests.cache"; // Preload the grammar file... - PegTokenizer.src = fs.readFileSync(path.join(basePath, 'parser', 'pegTokenizer.pegjs.txt'), 'utf8'); - - this.wikiTokenizer = new PegTokenizer(); + var peg = fs.readFileSync(path.join(basePath, 'parser', 'pegTokenizer.pegjs.txt'), 'utf8'); + var parserEnv = {}; + //var parserEnv = new MWParserEnvironment({ + // tagHooks: { + // 'ref': MWRefTagHook, + // 'references': MWReferencesTagHook + // } + //}); + this.wikiTokenizer = new PegTokenizer(parserEnv, peg); this.testFileName = '../../../../phase3/tests/parser/parserTests.txt'; // default this.testFileName2 = '../../../../tests/parser/parserTests.txt'; // Fallback. Not everyone fetch at phase3 level @@ -439,13 +447,7 @@ ParserTests.prototype.processTest = function (item) { this.failParseTests++; console.log('PARSE FAIL', res.err); } else { - //var environment = new MWParserEnvironment({ - // tagHooks: { - // 'ref': MWRefTagHook, - // 'references': MWReferencesTagHook - // } - //}); - //var res = es.HtmlSerializer.stringify(tokens,environment); + //var res = es.HtmlSerializer.stringify(tokens,environment); //Slightly better token output debugging: //console.log( util.inspect( res.tokens, false, null ).yellow);