From 92fdf993841676ea98243d39f0180b2846c93039 Mon Sep 17 00:00:00 2001 From: Gabriel Wicke Date: Thu, 8 Dec 2011 10:59:44 +0000 Subject: [PATCH] Further renaming, this time from pegParser to pegTokenizer. --- .../parser/mediawiki.HTML5TreeBuilder.node.js | 7 +++++-- ...rser.peg.js => mediawiki.tokenizer.peg.js} | 20 +++++++++---------- ...arser.pegjs.txt => pegTokenizer.pegjs.txt} | 0 tests/parser/parserTests.js | 8 ++++---- 4 files changed, 19 insertions(+), 16 deletions(-) rename modules/parser/{mediawiki.parser.peg.js => mediawiki.tokenizer.peg.js} (86%) rename modules/parser/{pegParser.pegjs.txt => pegTokenizer.pegjs.txt} (100%) diff --git a/modules/parser/mediawiki.HTML5TreeBuilder.node.js b/modules/parser/mediawiki.HTML5TreeBuilder.node.js index 519eee4214..d8d6617f8a 100644 --- a/modules/parser/mediawiki.HTML5TreeBuilder.node.js +++ b/modules/parser/mediawiki.HTML5TreeBuilder.node.js @@ -1,6 +1,9 @@ +/* Front-end/Wrapper for a particular tree builder, in this case the + * parser/tree builder from the node 'html5' module. Feed it tokens using + * processToken, and it will build you a DOM tree retrievable using .document + * or .body(). */ + var events = require('events'); - - var HTML5 = require('./html5/index'); FauxHTML5 = {}; diff --git a/modules/parser/mediawiki.parser.peg.js b/modules/parser/mediawiki.tokenizer.peg.js similarity index 86% rename from modules/parser/mediawiki.parser.peg.js rename to modules/parser/mediawiki.tokenizer.peg.js index fd7b8cde2c..78f92a5310 100644 --- a/modules/parser/mediawiki.parser.peg.js +++ b/modules/parser/mediawiki.tokenizer.peg.js @@ -9,17 +9,17 @@ * to point at the MW page name containing the parser peg definition; default * is 'MediaWiki:Gadget-ParserPlayground-PegParser.pegjs'. */ -function PegParser(env) { +function PegTokenizer(env) { this.env = env || {}; } -PegParser.src = false; +PegTokenizer.src = false; -PegParser.prototype.parseToTree = function(text, callback) { +PegTokenizer.prototype.tokenize = function(text, callback) { this.initSource(function() { var out, err; try { - var parser = PEG.buildParser(PegParser.src); + var parser = PEG.buildParser(PegTokenizer.src); out = parser.parse(text); } catch (e) { err = e; @@ -34,7 +34,7 @@ PegParser.prototype.parseToTree = function(text, callback) { * @param {object} tree * @param {function(tree, error)} callback */ -PegParser.prototype.expandTree = function(tree, callback) { +PegTokenizer.prototype.expandTree = function(tree, callback) { var self = this; var subParseArray = function(listOfTrees) { var content = []; @@ -89,8 +89,8 @@ PegParser.prototype.expandTree = function(tree, callback) { callback(out); }; -PegParser.prototype.initSource = function(callback) { - if (PegParser.src) { +PegTokenizer.prototype.initSource = function(callback) { + if (PegTokenizer.src) { callback(); } else { if ( typeof parserPlaygroundPegPage !== 'undefined' ) { @@ -106,7 +106,7 @@ PegParser.prototype.initSource = function(callback) { success: function(data, xhr) { $.each(data.query.pages, function(i, page) { if (page.revisions && page.revisions.length) { - PegParser.src = page.revisions[0]['*']; + PegTokenizer.src = page.revisions[0]['*']; } }); callback() @@ -118,7 +118,7 @@ PegParser.prototype.initSource = function(callback) { $.ajax({ url: mw.config.get('wgParserPlaygroundAssetsPath', mw.config.get('wgExtensionAssetsPath')) + '/ParserPlayground/modules/pegParser.pegjs.txt', success: function(data) { - PegParser.src = data; + PegTokenizer.src = data; callback(); }, dataType: 'text', @@ -129,5 +129,5 @@ PegParser.prototype.initSource = function(callback) { }; if (typeof module == "object") { - module.exports.PegParser = PegParser; + module.exports.PegTokenizer = PegTokenizer; } diff --git a/modules/parser/pegParser.pegjs.txt b/modules/parser/pegTokenizer.pegjs.txt similarity index 100% rename from modules/parser/pegParser.pegjs.txt rename to modules/parser/pegTokenizer.pegjs.txt diff --git a/tests/parser/parserTests.js b/tests/parser/parserTests.js index 3270b5f78c..9580e79a1c 100644 --- a/tests/parser/parserTests.js +++ b/tests/parser/parserTests.js @@ -142,7 +142,7 @@ var pj = path.join; var testWhiteList = require('./parserTests-whitelist.js').testWhiteList; -_import(pj('parser', 'mediawiki.parser.peg.js'), ['PegParser']); +_import(pj('parser', 'mediawiki.tokenizer.peg.js'), ['PegTokenizer']); _import(pj('parser', 'mediawiki.parser.environment.js'), ['MWParserEnvironment']); _import(pj('parser', 'ext.cite.taghook.ref.js'), ['MWRefTagHook']); @@ -158,9 +158,9 @@ _require(pj('es', 'serializers', 'es.WikitextSerializer.js')); _require(pj('es', 'serializers', 'es.JsonSerializer.js')); // Preload the grammar file... -PegParser.src = fs.readFileSync(path.join(basePath, 'parser', 'pegParser.pegjs.txt'), 'utf8'); +PegTokenizer.src = fs.readFileSync(path.join(basePath, 'parser', 'pegTokenizer.pegjs.txt'), 'utf8'); -var parser = new PegParser(); +var wikiTokenizer = new PegTokenizer(); var testFileName = '../../../../phase3/tests/parser/parserTests.txt'; // default var testFileName2 = '../../../../tests/parser/parserTests.txt'; // Fallback. Not everyone fetch at phase3 level @@ -378,7 +378,7 @@ function processTest(item) { console.log(item.input + "\n"); } - parser.parseToTree(item.input + "\n", function(tokens, err) { + wikiTokenizer.tokenize(item.input + "\n", function(tokens, err) { if (err) { printTitle(); failParseTests++;