r91240 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91239‎ | r91240 | r91241 >
Date:00:53, 1 July 2011
Author:brion
Status:deferred
Tags:
Comment:
ParserPlayground: some fixies for round-tripping peg version of refs
Modified paths:
  • /trunk/extensions/ParserPlayground/modules/ext.parserPlayground.fakeParser.js (modified) (history)
  • /trunk/extensions/ParserPlayground/modules/ext.parserPlayground.js (modified) (history)
  • /trunk/extensions/ParserPlayground/modules/ext.parserPlayground.pegParser.js (modified) (history)
  • /trunk/extensions/ParserPlayground/modules/pegParser.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.pegParser.js
@@ -33,25 +33,36 @@
3434 callback();
3535 } else {
3636 if ( typeof parserPlaygroundPegPage !== 'undefined' ) {
37 - $.get(wgScriptPath + '/api' + wgScriptExtension, {
38 - format: 'json',
39 - action: 'query',
40 - prop: 'revisions',
41 - rvprop: 'content',
42 - titles: parserPlaygroundPegPage
43 - }, function(data, xhr) {
44 - $.each(data.query.pages, function(i, page) {
45 - if (page.revisions && page.revisions.length) {
46 - PegParser.src = page.revisions[0]['*'];
47 - }
48 - });
49 - callback();
 37+ $.ajax({
 38+ url: wgScriptPath + '/api' + wgScriptExtension,
 39+ data: {
 40+ format: 'json',
 41+ action: 'query',
 42+ prop: 'revisions',
 43+ rvprop: 'content',
 44+ titles: parserPlaygroundPegPage
 45+ },
 46+ success: function(data, xhr) {
 47+ $.each(data.query.pages, function(i, page) {
 48+ if (page.revisions && page.revisions.length) {
 49+ PegParser.src = page.revisions[0]['*'];
 50+ }
 51+ });
 52+ callback()
 53+ },
 54+ dataType: 'json',
 55+ cache: false
5056 }, 'json');
5157 } else {
52 - $.get(wgExtensionAssetsPath + '/ParserPlayground/modules/pegParser.pegjs.txt', function(data) {
53 - PegParser.src = data;
54 - callback();
55 - }, 'text' );
 58+ $.ajax({
 59+ url: wgExtensionAssetsPath + '/ParserPlayground/modules/pegParser.pegjs.txt',
 60+ success: function(data) {
 61+ PegParser.src = data;
 62+ callback();
 63+ },
 64+ dataType: 'text',
 65+ cache: false
 66+ });
5667 }
5768 }
5869 };
Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.js
@@ -89,17 +89,8 @@
9090 $('.parseNodeHighlight').removeClass('parseNodeHighlight');
9191 match(this, function(node, other) {
9292 $(node).addClass('parseNodeHighlight');
93 - $(other).addClass('parseNodeHighlight');
94 - });
95 - event.preventDefault();
96 - return false;
97 - }).delegate('.parseNode', 'mouseleave', function(event) {
98 - $('.parseNodeHighlight').removeClass('parseNodeHighlight');
99 - event.preventDefault();
100 - return false;
101 - }).delegate('.parseNode', 'click', function(event) {
102 - match(this, function(node, other) {
10393 if (other) {
 94+ $(other).addClass('parseNodeHighlight');
10495 // try to scroll the other into view. how... feasible is this? :DD
10596 var visibleStart = b.scrollTop();
10697 var visibleEnd = visibleStart + b.height();
@@ -114,6 +105,12 @@
115106 return false;
116107 }
117108 });
 109+ event.preventDefault();
 110+ return false;
 111+ }).delegate('.parseNode', 'mouseleave', function(event) {
 112+ $('.parseNodeHighlight').removeClass('parseNodeHighlight');
 113+ event.preventDefault();
 114+ return false;
118115 });
119116 };
120117 makeMagic(left, right, rightMap);
@@ -257,9 +254,6 @@
258255 },
259256 setupEditor: function($target) {
260257 $target.delegate('.parseNode', 'click', function(event) {
261 - if (context.parserPlayground.useInspector) {
262 - return true;
263 - }
264258 var node = $(this).data('parseNode');
265259 if ( node ) {
266260 // Ok, not 100% kosher right now but... :D
Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.fakeParser.js
@@ -305,6 +305,10 @@
306306 return str;
307307 };
308308 var src;
 309+ if (typeof tree === "string") {
 310+ callback(tree);
 311+ return;
 312+ }
309313 switch (tree.type) {
310314 case 'page':
311315 src = subParseArray(tree.content);
@@ -330,7 +334,7 @@
331335 src += ']]';
332336 break;
333337 case 'h':
334 - stub = '';
 338+ var stub = '';
335339 for (var i = 0; i < tree.level; i++) {
336340 stub += '=';
337341 }
@@ -339,7 +343,18 @@
340344 case 'ext':
341345 src = '<' + tree.name;
342346 if (tree.params) {
343 - src += ' ' + tree.params;
 347+ for (var i = 0; i < tree.params.length; i++) {
 348+ var param = tree.params[i];
 349+ src += ' ';
 350+ src += param.name + '=';
 351+ if ('quote' in param) {
 352+ src += param.quote;
 353+ }
 354+ src += param.text;
 355+ if ('quote' in param) {
 356+ src += param.quote;
 357+ }
 358+ }
344359 }
345360 if ('content' in tree) {
346361 src += '>';
Index: trunk/extensions/ParserPlayground/modules/pegParser.pegjs.txt
@@ -222,11 +222,7 @@
223223
224224 ref_start
225225 = "<ref" params:ext_param* space* {
226 - var obj = {};
227 - for (var i = 0; i < params.length; i++) {
228 - obj[params[i][0]] = params[i][1];
229 - }
230 - return obj;
 226+ return params;
231227 }
232228
233229 ref_end
@@ -241,7 +237,8 @@
242238
243239 ext_param
244240 = space* name:ext_param_name "=" val:ext_param_val {
245 - return [name, val];
 241+ val.name = name;
 242+ return val;
246243 }
247244
248245 ext_param_name
@@ -250,6 +247,6 @@
251248 }
252249
253250 ext_param_val
254 - = t:[0-9A-Za-z]+ { return t.join('') }
255 - / "'" t:[^'>]+ "'" { return t.join('') }
256 - / '"' t:[^">]+ '"' { return t.join('') }
 251+ = t:[0-9A-Za-z]+ { return {text: t.join('') } }
 252+ / "'" t:[^'>]+ "'" { return { quote: "'", text: t.join('') } }
 253+ / '"' t:[^">]+ '"' { return { quote: '"', text: t.join('') } }

Status & tagging log