Further renaming, this time from pegParser to pegTokenizer.

This commit is contained in:
Gabriel Wicke 2011-12-08 10:59:44 +00:00
parent 76bc477038
commit 92fdf99384
4 changed files with 19 additions and 16 deletions

View file

@ -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 = {};

View file

@ -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;
}

View file

@ -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++;