Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.pegParser.js |
— | — | @@ -33,25 +33,36 @@ |
34 | 34 | callback(); |
35 | 35 | } else { |
36 | 36 | 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 |
50 | 56 | }, 'json'); |
51 | 57 | } 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 | + }); |
56 | 67 | } |
57 | 68 | } |
58 | 69 | }; |
Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.js |
— | — | @@ -89,17 +89,8 @@ |
90 | 90 | $('.parseNodeHighlight').removeClass('parseNodeHighlight'); |
91 | 91 | match(this, function(node, other) { |
92 | 92 | $(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) { |
103 | 93 | if (other) { |
| 94 | + $(other).addClass('parseNodeHighlight'); |
104 | 95 | // try to scroll the other into view. how... feasible is this? :DD |
105 | 96 | var visibleStart = b.scrollTop(); |
106 | 97 | var visibleEnd = visibleStart + b.height(); |
— | — | @@ -114,6 +105,12 @@ |
115 | 106 | return false; |
116 | 107 | } |
117 | 108 | }); |
| 109 | + event.preventDefault(); |
| 110 | + return false; |
| 111 | + }).delegate('.parseNode', 'mouseleave', function(event) { |
| 112 | + $('.parseNodeHighlight').removeClass('parseNodeHighlight'); |
| 113 | + event.preventDefault(); |
| 114 | + return false; |
118 | 115 | }); |
119 | 116 | }; |
120 | 117 | makeMagic(left, right, rightMap); |
— | — | @@ -257,9 +254,6 @@ |
258 | 255 | }, |
259 | 256 | setupEditor: function($target) { |
260 | 257 | $target.delegate('.parseNode', 'click', function(event) { |
261 | | - if (context.parserPlayground.useInspector) { |
262 | | - return true; |
263 | | - } |
264 | 258 | var node = $(this).data('parseNode'); |
265 | 259 | if ( node ) { |
266 | 260 | // Ok, not 100% kosher right now but... :D |
Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.fakeParser.js |
— | — | @@ -305,6 +305,10 @@ |
306 | 306 | return str; |
307 | 307 | }; |
308 | 308 | var src; |
| 309 | + if (typeof tree === "string") { |
| 310 | + callback(tree); |
| 311 | + return; |
| 312 | + } |
309 | 313 | switch (tree.type) { |
310 | 314 | case 'page': |
311 | 315 | src = subParseArray(tree.content); |
— | — | @@ -330,7 +334,7 @@ |
331 | 335 | src += ']]'; |
332 | 336 | break; |
333 | 337 | case 'h': |
334 | | - stub = ''; |
| 338 | + var stub = ''; |
335 | 339 | for (var i = 0; i < tree.level; i++) { |
336 | 340 | stub += '='; |
337 | 341 | } |
— | — | @@ -339,7 +343,18 @@ |
340 | 344 | case 'ext': |
341 | 345 | src = '<' + tree.name; |
342 | 346 | 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 | + } |
344 | 359 | } |
345 | 360 | if ('content' in tree) { |
346 | 361 | src += '>'; |
Index: trunk/extensions/ParserPlayground/modules/pegParser.pegjs.txt |
— | — | @@ -222,11 +222,7 @@ |
223 | 223 | |
224 | 224 | ref_start |
225 | 225 | = "<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; |
231 | 227 | } |
232 | 228 | |
233 | 229 | ref_end |
— | — | @@ -241,7 +237,8 @@ |
242 | 238 | |
243 | 239 | ext_param |
244 | 240 | = space* name:ext_param_name "=" val:ext_param_val { |
245 | | - return [name, val]; |
| 241 | + val.name = name; |
| 242 | + return val; |
246 | 243 | } |
247 | 244 | |
248 | 245 | ext_param_name |
— | — | @@ -250,6 +247,6 @@ |
251 | 248 | } |
252 | 249 | |
253 | 250 | 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('') } } |